Skip to content

Commit

Permalink
feat: release mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
thepassle committed Nov 8, 2023
1 parent dcf3f8c commit 3b0040a
Show file tree
Hide file tree
Showing 7 changed files with 5,706 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-games-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/mocks': major
---

Initial release
5,703 changes: 5,676 additions & 27 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/dev-server-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"dependencies": {
"@mdn/browser-compat-data": "^4.0.0",
"@web/dev-server-core": "^0.7.0",
"parse5": "^6.0.1",
"esbuild": "^0.19.5",
"parse5": "^6.0.1",
"ua-parser-js": "^1.0.33"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/mocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"scripts": {
"start": "wds --config demo/wc/web-dev-server.config.mjs",
"test:browser": "node ../test-runner/dist/bin.js test-browser/*.test.js --config test-browser/web-test-runner.config.js",
"types": "wireit"
},
"files": [
Expand All @@ -65,7 +66,7 @@
"@web/storybook-prebuilt": "^0.1.37",
"@web/storybook-utils": "^1.0.0",
"lit": "^2.7.5 || ^3.0.0",
"msw": "0.0.0-fetch.rc-23"
"msw": "^2.0.0"
},
"devDependencies": {
"@web/dev-server": "^0.4.0",
Expand Down
15 changes: 15 additions & 0 deletions packages/mocks/test-browser/mocks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { http } from '../http.js';
import { expect } from '@esm-bundle/chai';
import { registerMockRoutes } from '../browser.js';

it('mocks a request', async () => {
registerMockRoutes(http.get('/api/foo', () => Response.json({ foo: 'foo' })));
const { foo } = await fetch('/api/foo').then(r => r.json());
expect(foo).to.equal('foo');
});

it('overrides a previous handler', async () => {
registerMockRoutes(http.get('/api/foo', () => Response.json({ foo: 'bar' })));
const { foo } = await fetch('/api/foo').then(r => r.json());
expect(foo).to.equal('bar');
});
6 changes: 6 additions & 0 deletions packages/mocks/test-browser/web-test-runner.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { mockPlugin } from '../wds-plugin.js';

export default {
nodeResolve: true,
plugins: [mockPlugin()],
};
2 changes: 1 addition & 1 deletion packages/mocks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"rootDir": "."
},
"include": ["**/*.js", "**/*.ts"],
"exclude": ["dist-types"]
"exclude": ["dist-types", "test-browser"]
}

0 comments on commit 3b0040a

Please sign in to comment.