Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/content/docs/integrations/msw.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ This guide assumes you are already familiar with [MSW](https://mswjs.io/). If yo
npm install @orpc/experimental-msw@beta
```

:::info
Both MSW v2 and v3 are supported.
:::

## Setup

Create MSW utils from a [router contract](/docs/contract/router) or an implemented [router](/docs/router) (convert [lazy routers](/docs/router#lazy-router) with [`unlazyRouter`](/docs/contract/router#router-to-contract) first). The `handler` option creates the fetch handler that serves each mock. Configure it like your production handler, so serialization, validation, and error envelopes behave exactly like your real server.
Expand Down Expand Up @@ -91,7 +95,7 @@ export const Loading: Story = {

## Passthrough

The `.passthrough` method creates an MSW request handler that performs matching requests against the real server as-is, useful to exempt specific procedures from mocking, for example while [onUnhandledRequest](https://mswjs.io/docs/api/setup-server/listen#onunhandledrequest) treats everything else as an error:
The `.passthrough` method creates an MSW request handler that performs matching requests against the real server as-is, useful to exempt specific procedures from mocking, for example while [onUnhandledFrame](https://mswjs.io/docs/api/setup-server/listen) (`onUnhandledRequest` in MSW v2) treats everything else as an error:

```ts
const handlers = [
Expand Down
3 changes: 2 additions & 1 deletion packages/msw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
},
"devDependencies": {
"@orpc/openapi": "workspace:*",
"msw": "^2.15.0",
"msw": "^3.0.2",
Comment thread
dinwwwh marked this conversation as resolved.
"msw-v2": "npm:msw@^2.15.0",
"zod": "^4.6.5"
}
}
2 changes: 1 addition & 1 deletion packages/msw/src/http-procedure-utils.openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const contract = {

const server = setupServer()

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
beforeAll(() => server.listen({ onUnhandledFrame: 'error' }))
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

Expand Down
2 changes: 1 addition & 1 deletion packages/msw/src/http-procedure-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const contract = {

const server = setupServer()

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
beforeAll(() => server.listen({ onUnhandledFrame: 'error' }))
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

Expand Down
2 changes: 1 addition & 1 deletion packages/msw/src/http-router-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('with an implemented router', () => {

const server = setupServer()

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
beforeAll(() => server.listen({ onUnhandledFrame: 'error' }))
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

Expand Down
88 changes: 86 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,29 @@ export default defineConfig(({ mode }) => ({
globals: true,
setupFiles: ['./vitest.javascript.ts'],
include: ['**/*.test.ts'],
exclude: [...defaultExclude, '**/.claude/**', './packages/bun/**', './packages/cloudflare/**'],
exclude: [
...defaultExclude,
'**/.claude/**',
'./packages/bun/**',
'./packages/cloudflare/**',
// MSW v3 requires Node.js 22+, older versions only run the MSW v2 project below
...(Number.parseInt(process.versions.node) < 22 ? ['./packages/msw/**'] : []),
],
benchmark: {
exclude: ['**/**'],
},
},
},
{
// also test @orpc/experimental-msw against MSW v2
resolve: {
alias: { msw: 'msw-v2' },
},
test: {
name: 'msw-v2',
globals: true,
setupFiles: ['./vitest.javascript.ts'],
include: ['./packages/msw/**/*.test.ts'],
benchmark: {
exclude: ['**/**'],
},
Expand Down
Loading