Skip to content

Commit

Permalink
feat!: adopt the global Fetch API (#1436)
Browse files Browse the repository at this point in the history
Co-authored-by: Frederik Rabøl <frederik-rm@hotmail.com>
Co-authored-by: Christoph Fricke <christoph@frickeonline.de>
Co-authored-by: Piotr <hello@piotr.cz>
Co-authored-by: Kristján Oddsson <koddsson@github.com>
Co-authored-by: thepassle <pascalschilp@gmail.com>
Co-authored-by: Kevin Østerkilde <kevin@oesterkilde.dk>
Co-authored-by: Laryssa Rocha <laryssa.vrocha@gmail.com>
Co-authored-by: Matthew Costabile <mattcosta7@github.com>
  • Loading branch information
9 people committed Oct 23, 2023
1 parent 61c220c commit 1033f65
Show file tree
Hide file tree
Showing 440 changed files with 8,971 additions and 7,709 deletions.
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', '5.1', '5.2']
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.7', '4.8', '4.9', '5.0', '5.1', '5.2']
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
42 changes: 20 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,18 @@ 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 { http, HttpResponse } from 'msw'
import { setupWorker } from 'msw/browser'

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,
},
]),
)
http.get('/books', () => {
return HttpResponse.json([
{
id: 'ea42ffcb-e729-4dd5-bfac-7a5b645cb1da',
title: 'The Lord of the Rings',
publishedAt: -486867600,
},
])
}),
)

Expand Down Expand Up @@ -217,24 +216,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 { http, 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,
},
]),
)
http.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

0 comments on commit 1033f65

Please sign in to comment.