Skip to report

MSW’s request handlers move into Node

Trace the PR that brought MSW to Node: a new node component intercepts outgoing requests with the same request handlers, through a response utility shared with the browser worker.

mswjs/msw #146 · PR by kettanaito · Merged

mswjs/msw b9dacdbd..0ec75edf

base and head as given

  • Server-side request interception entered the library
  • Server interception now depends on request handlers
  • A shared response-resolution utility now serves browser and server interception
  • Header utilities entered response construction and worker message handling
files changed
36
in a component
13
lines in components
307
components
6
public routes changed
0
schema statements
0
new dependencies
3
excluded by role
23
Based on 12 of 13 eligible changed files

Server-side request interception

Added
Before
did not exist
After
Server requests can be intercepted

Server-side code can intercept outgoing requests with existing request handlers, return mocked responses after configured delays, and restore interception when finished.

In favour

  • In favour: Reuses handler predicates and resolvers across browser and server

Against

  • Against: Server interception supplies fixed defaults for browser-specific request fields

Header handling

Modified
Before
Prior behavior not established
After
Headers use shared utility objects

Mocked responses now carry shared utility header objects, while worker messages serialize headers into lists before recreating browser responses. Header-setting also accepts object values containing arrays.

In favour

  • In favour: Preserves repeated header values across worker message serialization

The model found nothing to weigh against this.

Files changed in 6 components. Dependencies shown: 3 new, 14 unchanged
unchanged · 14new · 31 component added

3 new dependencies between components — Node → Handlers · Node → Utils · Setup Worker → Source

What else could behave differently

6 components · 18 files

These components import changed code, directly or through other files. A traced dependency is a place to review, not a confirmed runtime failure.

Reached 3

ComponentSymbolCited atFilesReached by
Utilssrc/utils/Signature changed 1 of 9 changed symbols reaching itsrc/handlers/requestHandler.ts:16-3243 direct · 1 at two steps
Trace path

Shortest component path from the changed symbol:

  1. Handlers
  2. Utils

Later steps follow file imports; they do not prove this symbol is called.

Sourcesrc/Body changed 1 of 10 changed symbols reaching itsrc/context/fetch.ts:31-4933 direct
Trace path

Shortest component path from the changed symbol:

  1. Context
  2. Source

Later steps follow file imports; they do not prove this symbol is called.

Handlerssrc/handlers/Body changed 1 of 2 changed symbols reaching itsrc/context/fetch.ts:31-4911 direct
Trace path

Shortest component path from the changed symbol:

  1. Context
  2. Handlers

Later steps follow file imports; they do not prove this symbol is called.

Ranked lower 3

ComponentFilesReached by
src/setupWorker/63 direct · 3 at two steps
src/context/22 direct
src/node/22 direct

Statements 3

MockedRequest's signature change reached 4 files in Utils. 31
src/handlers/requestHandler.ts:16-32
fetch's body change reached 3 files in Source. 3
src/context/fetch.ts:31-49
fetch's body change reached 1 file in Handlers. 1
src/context/fetch.ts:31-49

38 reached files belong to no component — tests, docs and config.

Routes, schema, dependencies

WhatObjectWhere
+ dependency@types/node-fetch@^2.5.7declared, and used by no file in any component
+ dependencyheaders-utils@^1.1.9src/context/fetch.ts:1
+ dependencynode-request-interceptor@^0.2.2src/node/setupServer.ts:2
3 statements, with the lines behind them
Declared, and used by no file in any component.
headers-utils ^1.1.9 was added as a dependency.
src/context/fetch.ts:1
node-request-interceptor ^0.2.2 was added as a dependency.
src/node/setupServer.ts:2

Inspect components, files and symbols

Component

UtilsModified
src/utils/

4 files · 174 lines

exports, dependency, 3 dependents

Utils added the getResponse export and removed the getCleanUrl export.

Header handling, modified

SourceModified
src/

3 files · 32 lines

dependency, 4 dependents

Header handling, modified

HandlersModified
src/handlers/

1 file · 8 lines

dependency, 5 dependents

Server-side request interception, added

Setup WorkerModified
src/setupWorker/

1 file · 6 lines

dependency, 3 dependents

Setup Worker added the ResponseWithSerializedHeaders export.

Header handling, modified

ContextModified
src/context/

2 files · 20 lines

dependency, 2 dependents

Header handling, modified

NodeAdded
src/node/

2 files · 67 lines

dependency

Node added the setupServer export.

Server-side request interception, added

File

Handlerssrc/handlers/
src/handlers/requestHandler.ts

+4 −4

Server-side request interception, added

Nodesrc/node/
src/node/setupServer.ts

+66 −0

Server-side request interception, added

Nodesrc/node/
src/node/index.ts

+1 −0

Server-side request interception, added

Utilssrc/utils/
src/utils/handleRequestWith.ts

+25 −50

Header handling, modified

Utilssrc/utils/
src/utils/getResponse.ts

+69 −0

Header handling, modified

Utilssrc/utils/
src/utils/logger.ts

+14 −10

Header handling, modified

Utilssrc/utils/
src/utils/getCleanUrl.ts

+0 −6

Header handling, modified

Sourcesrc/
src/response.ts

+12 −10

Header handling, modified

Sourcesrc/
src/rest.ts

+3 −3

Header handling, modified

Sourcesrc/
src/mockServiceWorker.js

+3 −1

Header handling, modified

Setup Workersrc/setupWorker/
src/setupWorker/glossary.ts

+6 −0

Header handling, modified

Contextsrc/context/
src/context/set.ts

+4 −10

Header handling, modified

Contextsrc/context/
src/context/fetch.ts

+4 −2

Header handling, modified

Function

imports what changeddownstream of it, one mark per step

Diff

Handlerssrc/handlers/
src/handlers/requestHandler.ts

1–1, 17–17, 19–19 and 2 more spans

Server-side request interception, added

Nodesrc/node/
src/node/setupServer.ts

1–66

Server-side request interception, added

Nodesrc/node/
src/node/index.ts

1–1

Server-side request interception, added

Utilssrc/utils/
src/utils/handleRequestWith.ts

1–1, 3–6, 10–11 and 9 more spans

Header handling, modified

Utilssrc/utils/
src/utils/getResponse.ts

1–69

Header handling, modified

Utilssrc/utils/
src/utils/logger.ts

1–1, 3–3, 9–9 and 5 more spans

Header handling, modified

Utilssrc/utils/
src/utils/getCleanUrl.ts

1–6

Header handling, modified

Sourcesrc/
src/response.ts

1–1, 25–33, 36–36 and 1 more span

Header handling, modified

Sourcesrc/
src/rest.ts

2–2, 18–18, 48–48 and 1 more span

Header handling, modified

Sourcesrc/
src/mockServiceWorker.js

184–186

Header handling, modified

Setup Workersrc/setupWorker/
src/setupWorker/glossary.ts

2–3, 25–28

Header handling, modified

Contextsrc/context/
src/context/set.ts

1–1, 13–15, 24–27

Header handling, modified

Contextsrc/context/
src/context/fetch.ts

1–1, 19–19, 22–22 and 1 more span

Header handling, modified

Analysis scope

161 → 6
  1. 161
    files at head
  2. 10
    components
  3. 6
    changed by this change

Where the new files landed

3 new files
New fileBelongs toUsed byCallsServes
src/utils/getResponse.tsimports 1 package this change added
Utilsbase frame
Node
SourceHandlers
src/node/2 new filesimports 2 packages this change added
Nodenew territory
its own component only — 1 of 2 files imported by nothing
HandlersUtils

5 added files carry no component — 4 test, 1 config.

6components changed
0reached, not changed
1components added/removed
3dependencies added between components
0dependencies removed between components
0files moved to another path

36 files changed, 18 claims stated. 6 components reached in total.

naming: “model

narrative: “model

analyzer 0.2.0, config v1.9.0-phase8

Every line above is derived from b9dacdbd..0ec75edf and nothing else.