Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
293 commits
Select commit Hold shift + click to select a range
de0bd2f
fix(RequestHandler): set ResponseBodyType as undefined by default
kettanaito Oct 19, 2022
a27f6b7
test(cookies-inheritance): use a response body union type
kettanaito Oct 19, 2022
e005153
fix(bypass): support request generic to satisfy various polyfills
kettanaito Oct 21, 2022
03e6658
Merge branch 'main' into feat/standard-api
kettanaito Oct 21, 2022
f3894cf
chore: update to @mswjs/interceptors@0.18.0
kettanaito Nov 7, 2022
0157d82
chore: use @swc/jest vs ts-jest
kettanaito Nov 8, 2022
9b50319
fix(bypass): return [url, init] tuple for polyfill compatibility
kettanaito Nov 8, 2022
895e8e6
Merge branch 'main' into feat/standard-api
kettanaito Nov 14, 2022
10e3691
chore: fix failing bypass test
kettanaito Nov 14, 2022
8874812
chore: fix worker context event listener compatibility
kettanaito Nov 14, 2022
6861097
fix: typescript <= 4.4 compatibility
kettanaito Nov 14, 2022
b14380b
docs: improve migration guide
kettanaito Nov 15, 2022
b320fe5
test: fix response-patching test
kettanaito Nov 15, 2022
2684382
fix(bypass): forward request body
kettanaito Nov 15, 2022
085d52b
test: fix failing tests
kettanaito Nov 15, 2022
4edf17f
Merge branch 'main' into feat/standard-api
kettanaito Nov 15, 2022
77ca45a
Merge branch 'main' into feat/standard-api
kettanaito Nov 15, 2022
d84b2d0
chore: v0.0.0-fetch.rc-1
kettanaito Nov 15, 2022
b48b42e
Merge branch 'main' into feat/standard-api
kettanaito Nov 16, 2022
09218f3
docs(migrating): remove duplicate handler in set-cookies
kettanaito Nov 16, 2022
84978a0
docs: use HeadersInit for multi-value cookies
kettanaito Nov 17, 2022
3875d9b
chore(HttpResponse): remove commented code
kettanaito Nov 17, 2022
80ed635
docs: fix typo in migration guide (#1469)
Xayer Nov 18, 2022
cb2766d
Merge branch 'main' into feat/standard-api
kettanaito Nov 24, 2022
041ff3e
chore: v0.0.0-fetch.rc-2
kettanaito Nov 24, 2022
2f8bf27
fix(HttpResponse): accept interfaces as json response-data type (#1481)
christoph-fricke Nov 28, 2022
4bea835
docs(migrating): fix example for response composition (#1483)
christoph-fricke Dec 2, 2022
3a001af
docs(migrating): fix description for "ctx.errors" migration (#1487)
christoph-fricke Dec 2, 2022
7788593
Merge branch 'main' into feat/standard-api
kettanaito Dec 6, 2022
ffc51db
Merge branch 'main' into feat/standard-api
kettanaito Dec 7, 2022
9ba34e1
chore(release): v0.0.0-fetch.rc-3
kettanaito Dec 7, 2022
9607880
Merge branch 'main' into feat/standard-api
kettanaito Jan 11, 2023
6b87f2b
fix(decorateResponseInit): use global "Headers" if available
kettanaito Jan 11, 2023
d1e82e7
Merge branch 'main' into feat/standard-api
kettanaito Jan 14, 2023
cff6452
fix: update to @mswjs/interceptors@0.19.3
kettanaito Jan 14, 2023
021a080
Merge branch 'main' into feat/standard-api
kettanaito Jan 27, 2023
1bfd751
fix(worker): remove bypassing of server-sent events (#1551)
piotr-cz Feb 21, 2023
9a2446b
feat: drop support for node < 18
kettanaito Feb 27, 2023
b614531
Merge branch 'main' into feat/standard-api
kettanaito Feb 27, 2023
0fd5019
chore: fix unit tests
kettanaito Feb 27, 2023
d0a27ef
test(xhr): rewrite to fetch api
kettanaito Feb 27, 2023
7062869
chore: fix node tests
kettanaito Mar 1, 2023
603b24a
chore: use node 18 on ci
kettanaito Mar 3, 2023
e39b8fe
chore: move interceptors back to regular dependencies
kettanaito Mar 3, 2023
7acbf21
test: fix rest-api body mocks test
kettanaito Mar 3, 2023
fc38370
chore: fix browser tests
kettanaito Mar 3, 2023
69d2c65
chore(xhr): fix onload being called twice in tests
kettanaito Mar 4, 2023
5e92590
chore(release): v0.0.0-fetch.rc-4
kettanaito Mar 4, 2023
2273782
chore(release): v0.0.0-fetch.rc-5
kettanaito Mar 4, 2023
22cb9a1
feat: distribute library as cjs and esm
kettanaito Mar 7, 2023
c0c7f2a
fix: set "main" to node, use explicit "browser" field
kettanaito Mar 7, 2023
e4dce71
chore(release): 0.0.0-fetch.rc-6
kettanaito Mar 7, 2023
694bec9
test(on): clone response before reading it
kettanaito Mar 7, 2023
0f08330
chore: use node v18.14.2 internally
kettanaito Mar 7, 2023
a9cd280
test: unskip form-data node test
kettanaito Mar 7, 2023
e2c6d5a
Merge branch 'main' into feat/standard-api
kettanaito Mar 21, 2023
a369914
fix: update "strict-event-emitter" to 0.5.0
kettanaito Mar 21, 2023
37617c8
chore(release): v0.0.0-fetch.rc-7
kettanaito Mar 21, 2023
c347a9e
Merge branch 'main' into feat/standard-api
kettanaito Mar 23, 2023
2d57879
Merge branch 'main' into feat/standard-api
kettanaito Mar 24, 2023
bedcb2c
chore(release): v0.0.0-fetch.rc-8
kettanaito Mar 24, 2023
c4367a5
fix: migrate to "@open-draft/until@2"
kettanaito Mar 30, 2023
c5d6600
chore: update to "@mswjs/interceptors@0.22.10"
kettanaito Mar 30, 2023
472a358
chore: update to "page-with@0.6.1"
kettanaito Mar 30, 2023
14cf7d7
Merge branch 'main' into feat/standard-api
kettanaito Apr 6, 2023
7c6c9d9
feat: split the library into "core", "browser" and "node" (#1584)
kettanaito Apr 11, 2023
651e1a8
feat: export browser integration from "msw/browser" (#1591)
kettanaito Apr 11, 2023
206682f
docs: mention "msw/browser" change in migration guidelines
kettanaito Apr 11, 2023
f5637d1
chore(release): v0.0.0-fetch.rc-9
kettanaito Apr 11, 2023
34ae9da
fix: include "browser" in "files"
kettanaito Apr 12, 2023
e7153d9
chore(release): 0.0.0-fetch.rc-10
kettanaito Apr 12, 2023
76bac29
docs: add missing quote to migration guidelines (#1592)
Apr 12, 2023
6af4b3c
fix: ditch "debug" in favor of "@open-draft/logger"
kettanaito Apr 13, 2023
f4b4b4f
fix: use "statuses" plain object, list as dependency
kettanaito Apr 13, 2023
f656f0c
fix: bump to interceptors 0.22.12
kettanaito Apr 14, 2023
b8376e4
chore: explain "customConditions" in jest (jsdom)
kettanaito Apr 14, 2023
a4dadc9
chore: force exit node tests
kettanaito Apr 14, 2023
b816698
chore(release): v0.0.0-fetch.rc-11
kettanaito Apr 14, 2023
2331179
chore: add automated modules tests
kettanaito Apr 17, 2023
e48f435
chore: add runtime esm node test
kettanaito Apr 17, 2023
99402f6
fix: drop "chalk"
kettanaito Apr 17, 2023
1f81582
fix: use default import for cjs "statuses"
kettanaito Apr 17, 2023
0074b52
test: add runtime esm node.js tests
kettanaito Apr 17, 2023
a3b5c09
test: fix printHandlers location tests
kettanaito Apr 17, 2023
4c21110
chore: add browser module tests
kettanaito Apr 17, 2023
0fd26dc
chore: use "@web/dev-server" for browser esm tests
kettanaito Apr 18, 2023
4f3e05b
chore: update in-house dependencies for esm compat
kettanaito Apr 18, 2023
8ae5a4f
chore: use correct cjs deps imports
kettanaito Apr 18, 2023
f1749a6
chore: fix typescript package import in ts tests
kettanaito Apr 18, 2023
c7139df
fix(cookie): use manually bundled esm version
kettanaito Apr 20, 2023
9b27a12
chore: temporarily fix "process.env" for "graphql"
kettanaito Apr 25, 2023
7ff17ae
feat(HttpResponse): make initializable class
kettanaito Apr 28, 2023
0f35fd2
fix: esm fixes
thepassle Apr 29, 2023
100a43f
fix: annotate "@bundled-es-modules/statuses"
kettanaito Apr 29, 2023
94ec2ca
Merge branch 'main' into feat/standard-api
kettanaito Apr 29, 2023
36a0dcc
fix: cjs build of js-levenshtein
kettanaito Apr 29, 2023
229c967
chore(release): v0.0.0-fetch.rc-12
kettanaito Apr 29, 2023
cb565c9
fix: add "chalk@4" back to dependencies
kettanaito May 2, 2023
e20814e
chore(release): v0.0.0-fetch.rc-13
kettanaito May 2, 2023
b631430
Merge branch 'main' into feat/standard-api
kettanaito May 2, 2023
50c4c9c
fix: stream response chunks as they come in Node.js (#1606)
kettanaito May 3, 2023
8a527e9
fix: prevent "abort" listener memory leak in RequestHandler (#1608)
kettanaito May 7, 2023
b159c28
chore(release): v0.0.0-fetch.rc-14
kettanaito May 8, 2023
ed9275a
test: add response FormData browser test
kettanaito May 9, 2023
f663eeb
test: add Blob response browser test
kettanaito May 9, 2023
9c73b7d
test: add Blob json to request browser tests
kettanaito May 9, 2023
ccc576d
Merge branch 'main' into feat/standard-api
kettanaito May 12, 2023
2a287bc
feat: add "useRemoteHandlers" sync layer
kettanaito May 12, 2023
a20d446
fix: defer server connection to the first handler
kettanaito May 13, 2023
e9cc153
chore: use request/response serialize/deserialize utils
kettanaito May 13, 2023
7587800
chore: reuse req/res serialization for logging
kettanaito May 13, 2023
68727eb
chore: annotate sync server events map
kettanaito May 13, 2023
a2efc29
fix: bypass internal socket requests using "x-msw-request-type" header
kettanaito May 13, 2023
df07102
chore: use a single SYNC_SERVER_URL variable
kettanaito May 13, 2023
ceb507a
chore: use node polyfills for node tests in jest
kettanaito May 13, 2023
8bff5a0
feat: add "setupRemoteServer" API
kettanaito May 16, 2023
cedba0a
fix: await the server connection promise correctly
kettanaito May 17, 2023
598b1b7
fix: provide explicit exports from "setupRemoteServer"
kettanaito May 17, 2023
612a5ba
feat: support custom "MSW_INTERNAL_WEBSOCKET_PORT" env variable
kettanaito May 26, 2023
0f5c443
test(setupRemoteServer): add basic "use" test
kettanaito May 26, 2023
d27fc23
chore: move client creation to "setupRemoteServer"
kettanaito May 28, 2023
6e0c634
fix: format errors
kettanaito May 28, 2023
0bd22bb
feat(setupRemoteServer): support life-cycle events
kettanaito Jun 6, 2023
589eac6
Merge branch 'main' into feat/standard-api
kettanaito Jun 8, 2023
883d21f
Merge branch 'feat/standard-api' into feat/ws-sync-handlers
kettanaito Jun 8, 2023
b25655c
fix: normalize response status and status text when logging
kettanaito Jun 9, 2023
17f72e8
Merge branch 'main' into feat/standard-api
kettanaito Jun 9, 2023
f78d69e
Merge branch 'feat/standard-api' into feat/ws-sync-handlers
kettanaito Jun 13, 2023
a7caf12
test: add "Response.error" integration test
kettanaito Jun 29, 2023
82e3812
feat: do not set "x-powered-by" mocked response header
kettanaito Jun 29, 2023
8ca0287
chore: upgrade to @mswjs/interceptors@0.23.0
kettanaito Jun 29, 2023
1f06019
fix: rely on "isMockedResponse" to emit response events in node
kettanaito Jun 29, 2023
90f3989
feat: handle Response.error special use-case
kettanaito Jun 30, 2023
cff199d
test(response-patching): rely on custom "x-source" response header
kettanaito Jun 30, 2023
510f8b8
fix: upgrade to graphql@16.7.0, remove "process" workaround
kettanaito Jun 30, 2023
59c3e52
chore(release): v0.0.0-fetch.rc-15
kettanaito Jun 30, 2023
789327a
Merge branch 'main' into feat/standard-api
kettanaito Jul 20, 2023
47fd803
feat: make life-cycle event listeners have object argument
kettanaito Jul 20, 2023
61f6f3b
feat: remove the ".printHandlers()" method
kettanaito Jul 20, 2023
c371f03
feat: deprecate "rest" in favor of "http" (#1673)
kettanaito Jul 31, 2023
8943e1d
docs(passthrough): improve jsdoc description
kettanaito Jul 31, 2023
15db686
fix: remove unused utils modules
kettanaito Jul 31, 2023
90b854a
chore(release): v0.0.0-fetch.rc-16
kettanaito Aug 6, 2023
6adc652
Merge branch 'main' into feat/standard-api
kettanaito Aug 18, 2023
6239a0f
Merge branch 'main' into feat/standard-api
kettanaito Aug 18, 2023
bb02e57
test(graphql): add test on anonymous operation warning (#1693)
kettanaito Aug 18, 2023
5f3dd2a
Merge branch 'main' into feat/standard-api
kettanaito Aug 25, 2023
3b8f57e
fix(graphql): clone request before parsing (#1714)
kettanaito Aug 25, 2023
3fb29e5
chore(release): v0.0.0-fetch.rc-17
kettanaito Aug 25, 2023
223c17a
Merge branch 'main' into feat/standard-api
kettanaito Sep 2, 2023
a2b61ba
docs: add multipart-data common issue to migrating
kettanaito Sep 2, 2023
5034e48
Merge branch 'main' into feat/standard-api
kettanaito Sep 7, 2023
4ba43a5
chore: upgrade "headers-polyfill" to 3.2.3
kettanaito Sep 7, 2023
0898517
chore(release): v0.0.0-fetch.rc-18
kettanaito Sep 7, 2023
c5d03b0
Merge branch 'feat/standard-api' into feat/ws-sync-handlers
kettanaito Sep 7, 2023
b2b634c
fix: remove "NetworkError" in favor of "HttpResponse.error" (#1730)
kettanaito Sep 7, 2023
faa71c4
chore(release): v0.0.0-fetch.rc-19
kettanaito Sep 8, 2023
3eca8c7
fix(graphql): support request handler options (#1739)
kettanaito Sep 16, 2023
91989df
feat(worker): move exception handling from the worker (#1734)
kettanaito Sep 16, 2023
f1ff76a
Merge branch 'feat/standard-api' into feat/ws-sync-handlers
kettanaito Sep 16, 2023
0e8d362
chore: merge "main" into "feat/ws-sync-handlers"
kettanaito Oct 26, 2023
b8e9560
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Oct 30, 2023
2325fd5
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Nov 16, 2023
b3c4eda
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Jan 7, 2024
1b85677
chore: minor adjustments
kettanaito Jan 7, 2024
c9d23c9
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Jan 8, 2024
d9cc36c
chore(wip): continue
kettanaito Jan 13, 2024
e89afa5
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Feb 20, 2024
d23dd25
fix(wip): fix broken "use()" runtime handlers
kettanaito Feb 20, 2024
e79f5b2
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Sep 4, 2024
81969e3
fix: client sync server handshake
kettanaito Sep 5, 2024
46decd1
fix(RemoteRequestHandler): await response on `parse` phase
kettanaito Sep 5, 2024
661113d
test: add response type tests
kettanaito Sep 5, 2024
cb50d9a
fix: use default remote port number
kettanaito Sep 5, 2024
38b0e27
docs: add jsdoc to listen options
kettanaito Sep 5, 2024
6e2ee96
feat: add `remote.boundary()`
kettanaito Nov 29, 2024
dbb3cd6
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Nov 29, 2024
49357ed
chore(wip): debugging
kettanaito Dec 1, 2024
a6c6f6f
fix: fix ws passthrough, adjust remote tests
kettanaito Dec 4, 2024
0b2e2c0
test(wip): add `remote.boundary` tests
kettanaito Dec 4, 2024
0e48062
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Dec 5, 2024
2eba1ad
feat: support boundary and `contextId`
kettanaito Dec 5, 2024
11c466b
chore: adjust tests to headers changes
kettanaito Dec 5, 2024
7ad582c
chore(wip): wip
kettanaito Dec 10, 2024
fa8a197
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Dec 12, 2024
57ab678
fix(setupServer): skip forwarding internal websocket events
kettanaito Dec 12, 2024
c069b25
fix(RemoteRequestHandler): handle socket disconnects
kettanaito Dec 12, 2024
c2d5c13
fix(serializeUtils): preserve empty request/response bodies
kettanaito Dec 12, 2024
657d7b1
chore: last days of websocket server
kettanaito Dec 13, 2024
5264ec4
feat: use http for remote request handling
kettanaito Dec 13, 2024
e6fac6d
chore: remove `console.log` to fix linting
kettanaito Dec 18, 2024
9d04f0a
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Dec 18, 2024
cfc120c
fix: use consistent `localhost` for remote server
kettanaito Dec 18, 2024
310a2c0
feat: use random internal server port
kettanaito Dec 18, 2024
28875f9
chore: rewrite `RemoteClient` to `node:http`
kettanaito Jan 4, 2025
69a26dc
feat: forward life-cycle events over http
kettanaito Jan 6, 2025
f6cb07c
test: pass correct ArrayBuffer
kettanaito Jan 8, 2025
c21f0bd
test: move the life-cycle event forwarding test
kettanaito Jan 8, 2025
3826cad
fix(setupServer): print a dev utils error on failed remote connection
kettanaito Jan 8, 2025
d7d09fb
chore: hopefully, improve node and core ts configs
kettanaito Jan 8, 2025
ac6da8b
test(setupServer): add test for not emitting life cycle events on int…
kettanaito Jan 8, 2025
b5ea6fc
fix: support `onUnhandledRequest`
kettanaito Jan 8, 2025
a70b518
chore: move `RemoteClient` to core
kettanaito Jan 8, 2025
0d03db2
test: add `onUnhandledRequest` default behavior test
kettanaito Jan 9, 2025
b22d00c
fix(node): export `ListenOptions`
kettanaito Jan 9, 2025
b0b0381
test: add warn/error/bypass `onUnhandledRequest` tests
kettanaito Jan 9, 2025
61c8fe7
test: add custom callback `onUnhandledRequest` test
kettanaito Jan 9, 2025
bc0e0a7
chore: move `spyOnLifeCycleEvents` to node utils
kettanaito Jan 9, 2025
3c76156
fix: set "duplex" to "half" when handling requests
kettanaito Jan 10, 2025
80db9b8
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Jul 6, 2025
2b9efe4
fix(setupRemoteServer): use `getResponse()` to get mocked responses
kettanaito Jul 6, 2025
f41676c
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Aug 26, 2025
89dfa99
chore: adjust test setup to esm
kettanaito Aug 26, 2025
3224e0b
feat(wip): implement network handling protocol
kettanaito Aug 30, 2025
946df21
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Oct 3, 2025
7b9b434
docs: add cpri design document
kettanaito Oct 3, 2025
3097d9e
feat(wip): network rpc
kettanaito Oct 6, 2025
376b296
feat(wip): network sources
kettanaito Oct 8, 2025
9ac4e23
chore: basic `setupWorker` using `defineNetwork`
kettanaito Oct 8, 2025
89a8cf9
chore: annotate ambiguous `responseBody`
kettanaito Oct 8, 2025
6969709
fix: events, unhandled frames, service worker polish
kettanaito Oct 9, 2025
85c0c5a
fix: logging, unhandled lookup errors
kettanaito Oct 9, 2025
9e2d2e0
fix: map `onUnhandledFrame` to `onUnhandledRequest`
kettanaito Oct 9, 2025
2e87412
fix: `InterceptorSource`, fallback source for `setupWorker`
kettanaito Oct 9, 2025
b5c26c5
feat: websocket source, fallback source
kettanaito Oct 9, 2025
4de76dc
docs: add websocket logging comment
kettanaito Oct 9, 2025
d427536
chore: split network frame handling
kettanaito Oct 9, 2025
dabc438
feat(wip): migrate `setupServer` to the new architecture
kettanaito Oct 9, 2025
f973c69
fix: continue with setup-server, remote
kettanaito Oct 10, 2025
d9d07df
fix: await pushed frames
kettanaito Oct 10, 2025
217eaa9
fix: delete request passthrough `accept` header
kettanaito Oct 11, 2025
8401b85
fix: throw handler exceptions as-is to preserve 500 responses
kettanaito Oct 11, 2025
1ceaf4e
fix: correct order of merging `initialHandlers` and latest `handlers`
kettanaito Oct 11, 2025
ad8cf81
fix: life-cycle events for `setupServer`
kettanaito Oct 11, 2025
881c973
fix: free internal frame map on `.disable()`
kettanaito Oct 11, 2025
18faa73
fix: add `frame` listener earlier
kettanaito Oct 11, 2025
055ad91
fix: support legacy `onUnhandledRequest`
kettanaito Oct 11, 2025
d09d8cb
fix: correctly handle errors from `onUnhandledRequest` vs handler exc…
kettanaito Oct 11, 2025
d22e69d
fix: use `warn` as the default unhandled strategy in `setupServer`
kettanaito Oct 11, 2025
209b65c
fix: add handler input validation to handlers controller
kettanaito Oct 11, 2025
837f141
fix: add unhandled websocket connection handling
kettanaito Oct 11, 2025
dc56c2a
fix: skip logs for `setupServer`
kettanaito Oct 11, 2025
1ac66f0
fix: add websocket logging
kettanaito Oct 11, 2025
c5a58da
fix: support erroring unhandled websocket connections
kettanaito Oct 11, 2025
edb653e
chore: polish
kettanaito Oct 13, 2025
1515bba
chore: move browser sources under `./browser/sources`
kettanaito Oct 13, 2025
3d61036
feat(wip): implement `RemoteInterceptor`
kettanaito Oct 13, 2025
a435350
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Oct 19, 2025
eb4f080
Merge branch 'main' into feat/ws-sync-handlers
kettanaito Nov 7, 2025
541cc21
chore: polish
kettanaito Nov 7, 2025
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
63 changes: 63 additions & 0 deletions decisions/cross-process-request-interception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Cross-Process Request Interception (CPRI)

## Goal

Allow the user to intercept the network from one process while handling it in another. The primary use case for this is to affect the server-side application requests while within the test process:

```ts
// app.js
import { setupServer } from 'msw/node'

// Establish the sender
const server = setupServer({
remote: { enable: true },
})
server.listen()
```

```ts
// test/homepage.test.ts
// Establish a receiver.
const server = setupRemoteServer()

test('...', async () => {
server.use(
http.get('https://example.com/resource', () => {
return HttpResponse.text('hello world')
}),
)
})
```

## Sender and receiver

The remote interception consists of two parts:

- The sender that intercepts the traffic in a remote process and sends it to the receiver to potentially handle;
- The receiver that resolves any received requests against the defined request handlers.

> I chose to emphasize the receiver part with `setupRemoteServer()` to highlight that this "server" is not going to intercept the traffic in this process, unlike `setupServer()`.

## Protocol

For such an interception to be possible, we are designing a network serialization protocol to transfer requests and responses between processes. Spiritually, this isn't much different from the serialization we already perform between the client and worker threads in `setupWorker`.

I propose we use WebSocket as the underlying transport for this protocol. This will support HTTP requests while give us a proper protocol to serialize and handle WebSocket requests as well, since those will be event-based by design (something that won't be possible to properly describe with HTTP). WebSocket does pose a slight challenge as we would have to handle request body streams properly (can we use `WebSocketStream` for that?).

> I am open to considering other protocols, too. We might benefit even more from a custom RPC, like the one in [Cap'n Web](https://github.com/cloudflare/capnweb). May be worth looking into it for inspiration.

## `RemoteRequestHandler`

We use a new kind of request handler called `RemoteRequestHandler` on the _sender_ part to stall the request resolution until the receiver decides on how to handle the outgoing request. If the receiver does not handle the request, the sender proceeds with using its own request handlers for request resolution.

> `RemoteRequestHandler` is not the best mechanism for this. While it works with the current layout of MSW, the sender process is de-facto a _source_ of network. I like the concept of [network sources](https://github.com/mswjs/msw/discussions/2488) but it's a large refactor that we should not include in the remote interception right now. What we should do, is design the current approach so it's ready for network sources as much as possible.

## Pending tasks

- [ ] **Outline the network serialization protocol**. How to represent requests/responses? Their body streams? (see prior work at `src/core/nhp`). How to handle binary data transferred via WebSocket? The protocol should be able to serialize and deserialize all of that.
- [ ] (Potentially) replace the current serialization logic in `setupWorker` with the designed protocol to stay consistent.
- [ ] Tackle common use case problems:
- [ ] What if the app needs the test to serve homepage (see [this](https://github.com/mswjs/msw/pull/1617#issuecomment-2331258739))? That creates a catch 22 since testing frameworks often wait for the app to respond so they know the app is ready for tests. If the app's response depends on the test now, they both will get stuck indefinitely.
- [ ] Fix the [life-cycle events order](https://github.com/mswjs/msw/pull/1617#issuecomment-2580999914).
- [ ] Ensure the WebSocket transport is secure (see [this](https://github.com/mswjs/msw/pull/1617#pullrequestreview-2937795837)).
- [ ] Add more tests for HTTP and WebSocket CPRI.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,12 @@
"sideEffects": false,
"dependencies": {
"@inquirer/confirm": "^5.0.0",
"@msgpack/msgpack": "^3.1.2",
"@mswjs/interceptors": "^0.40.0",
"@open-draft/deferred-promise": "^2.2.0",
"@types/statuses": "^2.0.4",
"@types/ws": "^8.18.1",
"engine.io-client": "^6.6.3",
"cookie": "^1.0.2",
"graphql": "^16.8.1",
"headers-polyfill": "^4.0.2",
Expand All @@ -249,11 +252,14 @@
"path-to-regexp": "^6.3.0",
"picocolors": "^1.1.1",
"rettime": "^0.7.0",
"socket.io": "^4.8.1",
"socket.io-client": "^4.8.1",
"statuses": "^2.0.2",
"strict-event-emitter": "^0.5.1",
"tough-cookie": "^6.0.0",
"type-fest": "^4.26.1",
"until-async": "^3.0.2",
"ws": "^8.18.3",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
Loading
Loading