You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mocks.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
1
MSW Auto-Mocker
2
2
3
-
- Handlers: `src/mocks/handlers.ts` combines custom and auto-generated.
4
-
-Custom: add overrides in `src/mocks/customHandlers/index.ts`.
5
-
- Auto-gen: `src/mocks/mocker.ts` reads `swagger.json` and creates fixtures in`src/mocks/fixtures` on first run.
3
+
- Handlers: `src/mocks/handlers.ts` combines non-schema mocks and auto-generated mocks.
4
+
-Non-schema mocks: add hand-written handlers in `src/mocks/customHandlers/index.ts`. These run before auto-generated handlers so they can replace or extend behavior when needed.
5
+
- Auto-generated: `src/mocks/mocker.ts` reads `swagger.json` and creates fixtures under`src/mocks/fixtures` on first run.
6
6
- Validation: Loaded fixtures are validated with Ajv; errors log to console.
7
7
8
8
Usage
9
-
- Vitest: already wired via`src/mocks/test.setup.ts`. Run `pnpm test`.
10
-
- Browser dev (optional): import and call `startWorker()` from `src/mocks/browser.ts` in your app's dev entry.
11
-
- Standalone server (dev): run `pnpm mock:server`to start an HTTP mock server on`http://localhost:9090` (configurable via`MOCK_PORT`). Point your app's API base URL or a Next.js rewrite to this server to consume mock data without a real backend.
9
+
- Vitest: tests initialize MSW in`src/mocks/test.setup.ts`. Run `pnpm test`.
10
+
- Browser (optional): call `startWorker()` from `src/mocks/browser.ts` in your development entry point to mock requests in the browser.
11
+
- Standalone server (dev): `pnpm mock:server`starts an HTTP mock server at`http://localhost:9090` (configurable with`MOCK_PORT`). Point API requests or Next.js rewrites to this origin to develop without a live backend.
12
12
13
13
Regeneration
14
-
- Delete a fixture file or run with `AUTO_MOCKER_FORCE=1`to re-generate.
14
+
- Delete a fixture file to re-generate it on next request.
15
15
16
16
Failure behavior (always strict)
17
17
- If a schema is missing or faker fails, the handler responds 500 and does not write a placeholder.
0 commit comments