Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: adopt the global Fetch API #1436

Merged
merged 211 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 141 commits
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
ded1309
feat: wip new api
kettanaito Oct 7, 2022
6a21d47
feat: add "HttpResponse"
kettanaito Oct 8, 2022
90dd65e
feat: support "HttpResponse.arrayBuffer()"
kettanaito Oct 8, 2022
49369e6
fix(HttpResponse): forward cookies in the browser only
kettanaito Oct 8, 2022
3b947c7
docs: update readme
kettanaito Oct 8, 2022
b909e48
fix(pruneGetRequestBody): support HEAD requests
kettanaito Oct 9, 2022
f9840b7
chore: polyfill Request in jest tests
kettanaito Oct 9, 2022
b87724d
feat: support "bypass" utility
kettanaito Oct 9, 2022
3315cd4
chore: update "headers-polyfill" to 3.1.2
kettanaito Oct 9, 2022
aef1db1
test(headers-multiple): separate headers by comma
kettanaito Oct 9, 2022
b44a993
feat: support new api for graphql
kettanaito Oct 9, 2022
71753c3
chore: migrate "msw-api" tests
kettanaito Oct 10, 2022
a5a91dc
feat: add "delay()"
kettanaito Oct 10, 2022
0ee92d8
feat: migrate to new interceptors
kettanaito Oct 14, 2022
7fcadf2
fix(RequestHandler): clone response in generator
kettanaito Oct 14, 2022
d64713a
chore: migrate to fetch api in node
kettanaito Oct 14, 2022
fd89534
feat: export universal fetch classes
kettanaito Oct 14, 2022
5166b5e
fix(bypass): use compatible Request type
kettanaito Oct 15, 2022
11fa7c6
feat: support one-time request handlers
kettanaito Oct 15, 2022
adab915
feat: add "passthrough", fix tests
kettanaito Oct 15, 2022
dde933b
feat: support multi-value response cookies
kettanaito Oct 16, 2022
13bb61f
chore: add "File" polyfill for node
kettanaito Oct 16, 2022
ca158f3
feat: add "HttpResponse.formData()"
kettanaito Oct 16, 2022
e494683
test: fix request FormData body test
kettanaito Oct 16, 2022
41ffaa0
chore: remove unused code
kettanaito Oct 17, 2022
547eecb
docs: add the migration guide
kettanaito Oct 17, 2022
e8fca8b
feat: support response body type generic
kettanaito Oct 17, 2022
6771bb3
fix(HttpResponse): accept "string" as input to ".json()"
kettanaito Oct 17, 2022
a4adce0
feat: support strict request body type
kettanaito Oct 17, 2022
490d2b8
test: add path params types tests
kettanaito Oct 17, 2022
62a7289
feat(graphql): support strict response body type
kettanaito Oct 17, 2022
7a56a7d
feat: support mock ReadableStream responses
kettanaito Oct 18, 2022
f3ee2f4
feat: handle request body as ArrayBuffer
kettanaito Oct 18, 2022
896ae0e
test: fix graphql typings tests
kettanaito Oct 18, 2022
f78175f
test: remove "set" typings tests
kettanaito Oct 18, 2022
b84fd6b
chore: remove unused "compose"
kettanaito Oct 18, 2022
533f44c
chore(NetworkError): add jsdoc
kettanaito Oct 18, 2022
b562f1f
fix(GraphQLHandler): annotate "errors" as partial
kettanaito Oct 18, 2022
6fd2eb8
chore(HttpResponse): remove unnecessary "defineReadOnly"
kettanaito Oct 18, 2022
6f07723
chore: move "HttpResponse" to the root
kettanaito Oct 18, 2022
d61a5db
test: add unit tests for HttpResponse
kettanaito Oct 18, 2022
801b5ae
chore: move fetch polyfills to root
kettanaito Oct 18, 2022
24a59e5
fix: correct types
kettanaito Oct 19, 2022
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)
koddsson 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
589eac6
Merge branch 'main' into feat/standard-api
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
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
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
84c7354
Merge branch 'main' into feat/standard-api
kettanaito Sep 16, 2023
0763557
chore: upgrade to "headers-polyfill" v4 (#1741)
kettanaito Sep 16, 2023
8f2b94d
feat: set minimal supported typescript version to 4.7 (#1742)
kettanaito Sep 16, 2023
cbb25fb
fix(bypass): make bypass synchronous (#1745)
kettanaito Sep 20, 2023
581450f
chore(release): v0.0.0-fetch.rc-20
kettanaito Sep 20, 2023
2405bbc
chore: update MIGRATING.md (#1737)
Kosai106 Sep 21, 2023
8855956
Merge branch 'main' into feat/standard-api
kettanaito Sep 28, 2023
0a8100c
Merge branch 'main' into feat/standard-api
kettanaito Oct 4, 2023
96caf8a
docs: update jsdoc links
kettanaito Oct 4, 2023
2bcc39c
docs: use "intercept" instead of "capture"
kettanaito Oct 4, 2023
e1e4bb3
docs: add v2 announcement to readme (#1759)
kettanaito Oct 4, 2023
eca6a9e
feat(RequestHandler): make class method arguments an object (#1761)
kettanaito Oct 6, 2023
078e541
fix(worker): replace `Math.random()` with `crypto.randomUUID()` (#1762)
laryro Oct 10, 2023
17d5f3a
fix(setupServer): set max listeners on the "request.signal" (#1765)
kettanaito Oct 10, 2023
89be69f
chore(release): v0.0.0-fetch.rc-21
kettanaito Oct 10, 2023
b04c168
chore: re-add inquirer (#1766)
mattcosta7 Oct 12, 2023
595d6f3
chore(release): v0.0.0-fetch.rc-22
kettanaito Oct 12, 2023
b028c66
test(browser): add ReadableStream response body test (#1770)
kettanaito Oct 15, 2023
6405bea
fix: transfer response buffer on safari (#1771)
kettanaito Oct 15, 2023
f207368
chore(release): v0.0.0-fetch.rc-23
kettanaito Oct 17, 2023
f5f31fa
fix: check "setMaxListeners" in react native (#1773)
kettanaito Oct 18, 2023
cb0a5cd
fix(setupServer): suppress "ERR_INVALID_ARG_TYPE" (AbortSignal) error…
christoph-fricke Oct 20, 2023
1f55572
chore(release): v0.0.0-fetch.rc-24
kettanaito Oct 20, 2023
7d6d82d
fix(core): export the "RequestHandlerOptions" type (#1774)
christoph-fricke Oct 20, 2023
22666b9
chore: revert rc version
kettanaito Oct 23, 2023
5c49daf
Merge branch 'main' into feat/standard-api
kettanaito Oct 23, 2023
144b548
docs: update discord link
kettanaito Oct 23, 2023
cbba4b5
docs: update docs links
kettanaito Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
44 changes: 3 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- uses: pnpm/action-setup@v2
with:
version: 7.12

- name: Install dependencies
run: pnpm install --frozen-lockfile
run: pnpm install

- name: Unit tests
run: pnpm test:unit
Expand All @@ -46,41 +46,3 @@ jobs:
with:
name: playwright-report
path: test/browser/test-results

# Checks the library's compatibility with different
# TypeScript versions to discover type regressions.
typescript:
runs-on: macos-latest
# Skip TypeScript compatibility check on "main".
# A merged pull request implies passing "typescript" job.
if: github.ref != 'refs/heads/main'
strategy:
fail-fast: false
matrix:
ts: ['4.4', '4.5', '4.6', '4.7', '4.8', '4.9', '5.0']
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- uses: pnpm/action-setup@v2
with:
version: 7.12

- name: Install dependencies
run: pnpm install

- name: Install TypeScript ${{ matrix.ts }}
run: pnpm add typescript@${{ matrix.ts }}

- name: Build
run: pnpm build

- name: Typings tests
run: |
pnpm tsc --version
pnpm test:ts
78 changes: 78 additions & 0 deletions .github/workflows/compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: compat

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
# Validate the package.json exports and emitted CJS/ESM bundles.
exports:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
version: 7.12

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Validate package.json exports
run: pnpm check:exports

- name: Test modules (Node.js)
run: pnpm test:modules:node

- name: Test modules (browser)
run: pnpm test:modules:browser

# Checks the library's compatibility with different
# TypeScript versions to discover type regressions.
typescript:
runs-on: macos-latest
# Skip TypeScript compatibility check on "main".
# A merged pull request implies passing "typescript" job.
if: github.ref != 'refs/heads/main'
strategy:
fail-fast: false
matrix:
ts: ['4.4', '4.5', '4.6', '4.7', '4.8', '4.9', '5.0']
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
with:
version: 7.12

- name: Install dependencies
run: pnpm install

- name: Install TypeScript ${{ matrix.ts }}
run: pnpm add typescript@${{ matrix.ts }}

- name: Build
run: pnpm build

- name: Typings tests
run: |
pnpm tsc --version
pnpm test:ts
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
always-auth: true
registry-url: https://registry.npmjs.org

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.14.0
v18.14.2
41 changes: 19 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,17 @@ Let's write an example integration test that asserts the interception of a GET r

```js
// test/browser/example.mocks.ts
import { rest, setupWorker } from 'msw'
import { rest, setupWorker, HttpResponse } from 'msw'

const worker = setupWorker(
rest.get('/books', (req, res, ctx) => {
return res(
ctx.json([
{
id: 'ea42ffcb-e729-4dd5-bfac-7a5b645cb1da',
title: 'The Lord of the Rings',
publishedAt: -486867600,
},
]),
)
rest.get('/books', () => {
return HttpResponse.json([
{
id: 'ea42ffcb-e729-4dd5-bfac-7a5b645cb1da',
title: 'The Lord of the Rings',
publishedAt: -486867600,
},
])
}),
)

Expand Down Expand Up @@ -216,24 +214,23 @@ Let's replicate the same `GET /books` integration test in Node.js.
```ts
// test/node/example.test.ts
import fetch from 'node-fetch'
import { rest } from 'msw'
import { rest, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'

const server = setupServer(
rest.get('/books', (req, res, ctx) => {
return res(
ctx.json([
{
id: 'ea42ffcb-e729-4dd5-bfac-7a5b645cb1da',
title: 'The Lord of the Rings',
publishedAt: -486867600,
},
]),
)
rest.get('/books', () => {
return HttpResponse.json([
{
id: 'ea42ffcb-e729-4dd5-bfac-7a5b645cb1da',
title: 'The Lord of the Rings',
publishedAt: -486867600,
},
])
}),
)

beforeAll(() => server.listen())

afterAll(() => server.close())

test('returns a mocked response', async () => {
Expand Down