Skip to content

Commit b88b85c

Browse files
Run tests with all Node frameworks, fix ReadableStream.cancel & remove URL ponyfill (#1929)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent e075474 commit b88b85c

File tree

83 files changed

+1870
-16619
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1870
-16619
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@whatwg-node/fetch": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@whatwg-node/node-fetch@^0.7.5` ↗︎](https://www.npmjs.com/package/@whatwg-node/node-fetch/v/0.7.5) (from `^0.7.1`, in `dependencies`)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@whatwg-node/node-fetch": patch
3+
---
4+
dependencies updates:
5+
- Removed dependency [`@kamilkisiela/fast-url-parser@^1.1.4` ↗︎](https://www.npmjs.com/package/@kamilkisiela/fast-url-parser/v/1.1.4) (from `dependencies`)
6+
- Removed dependency [`fast-querystring@^1.1.1` ↗︎](https://www.npmjs.com/package/fast-querystring/v/1.1.1) (from `dependencies`)

.changeset/warm-plums-grin.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
'@whatwg-node/node-fetch': patch
3+
---
4+
5+
- Remove URL ponyfill implementation based on `fast-url-parser` and `fast-querystring`, because Node now uses Ada URL parser which is fast enough.
6+
7+
- Fix `ReadableStream[Symbol.asyncIterator]`
8+
9+
`ReadableStream` uses `Readable` so it uses `Symbol.asyncIterator` method of `Readable` but the returned iterator's `.return` method doesn't handle cancellation correctly. So we need to call `readable.destroy(optionalError)` manually to cancel the stream.
10+
11+
This allows `ReadableStream` to use implementations relying on `AsyncIterable.cancel` to handle cancellation like `Readable.from`
12+
13+
Previously the following was not handling cancellation;
14+
15+
```ts
16+
const res = new ReadableStream({
17+
start(controller) {
18+
controller.enqueue('Hello');
19+
controller.enqueue('World');
20+
},
21+
cancel(reason) {
22+
console.log('cancelled', reason);
23+
}
24+
});
25+
26+
const readable = Readable.from(res);
27+
28+
readable.destroy(new Error('MY REASON'));
29+
30+
// Should log 'cancelled MY REASON'
31+
```

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"website",
6666
"scripts",
6767
"e2e",
68-
"benchmarks"
68+
"benchmarks",
69+
"deno-jest.ts"
6970
],
7071
"globals": {
7172
"BigInt": true

.github/workflows/deployment-e2e.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
plan: ['aws-lambda', 'azure-function', 'cloudflare-workers', 'cloudflare-modules', 'deno']
12+
plan: ['aws-lambda', 'azure-function', 'cloudflare-workers', 'cloudflare-modules']
1313
# TODO: Add vercel
1414
name: e2e / ${{ matrix.plan }}
1515

@@ -27,12 +27,6 @@ jobs:
2727
- name: Install Required Libraries
2828
run: sudo apt update && sudo apt install -y libcurl4-openssl-dev libssl-dev
2929

30-
- name: Use Deno
31-
if: matrix.plan == 'deno'
32-
uses: denoland/setup-deno@v2
33-
with:
34-
deno-version: vx.x.x
35-
3630
- name: Cache Node Modules
3731
uses: actions/cache@v4
3832
id: node-modules-cache-deployment-e2e

.github/workflows/tests.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
NODE_OPTIONS: --max-old-space-size=4096
11+
NODE_NO_WARNINGS: 1
1112
CI: true
1213

1314
jobs:
@@ -97,15 +98,13 @@ jobs:
9798
command: yarn test:leaks --ci
9899

99100
unit-bun:
100-
name: unit / bun ${{matrix.node-version}}
101+
name: unit / bun
101102
runs-on: ubuntu-latest
102103
services:
103104
httpbin:
104105
image: kennethreitz/httpbin
105106
ports:
106107
- 8888:80
107-
strategy:
108-
fail-fast: false
109108
steps:
110109
- name: Checkout Master
111110
uses: actions/checkout@v4
@@ -115,16 +114,33 @@ jobs:
115114
uses: the-guild-org/shared-config/setup@main
116115
with:
117116
nodeVersion: 22
118-
- name: Cache Jest
119-
uses: actions/cache@v4
120-
with:
121-
path: .cache/jest
122-
key: ${{ runner.os }}-${{matrix.node-version}}-jest-${{ hashFiles('yarn.lock') }}
123-
restore-keys: |
124-
${{ runner.os }}-${{matrix.node-version}}-jest-
125117
- name: Test
126118
run: yarn test:bun --ci
127119

120+
unit-deno:
121+
name: unit / deno
122+
runs-on: ubuntu-latest
123+
services:
124+
httpbin:
125+
image: kennethreitz/httpbin
126+
ports:
127+
- 8888:80
128+
steps:
129+
- name: Checkout Master
130+
uses: actions/checkout@v4
131+
- name: Install Required Libraries
132+
run: sudo apt update && sudo apt install -y libcurl4-openssl-dev libssl-dev
133+
- name: Setup env
134+
uses: the-guild-org/shared-config/setup@main
135+
with:
136+
nodeVersion: 22
137+
- name: Test
138+
uses: nick-fields/retry@v3
139+
with:
140+
timeout_minutes: 10
141+
max_attempts: 5
142+
command: yarn test:deno
143+
128144
esm:
129145
name: esm
130146
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ junit.xml
7676
package-lock.json
7777

7878
eslint_report.json
79+
80+
deno.lock

.yarnrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore-engines true

benchmarks/node-fetch/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createServer } from 'http';
1+
import { createServer } from 'node:http';
22
import { isScenario, scenarios } from './scenarios';
33

44
const port = 50001;

benchmarks/server/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Blob as BufferBlob } from 'buffer';
2-
import { createServer, type RequestListener } from 'http';
1+
import { Blob as BufferBlob } from 'node:buffer';
2+
import { createServer, type RequestListener } from 'node:http';
33
import * as undici from 'undici';
44
import { createServerAdapter, Response } from '@whatwg-node/server';
55

deno-jest.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { fn } from 'jsr:@std/expect';
2+
3+
export {
4+
describe,
5+
it,
6+
test,
7+
beforeEach,
8+
afterEach,
9+
beforeAll,
10+
afterAll,
11+
} from 'jsr:@std/testing/bdd';
12+
export { expect } from 'jsr:@std/expect';
13+
14+
export const jest = {
15+
fn,
16+
spyOn(target: any, method: string) {
17+
Object.defineProperty(target, method, {
18+
value: fn(target[method]),
19+
writable: true,
20+
});
21+
},
22+
};

deno.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"imports": {
3+
"@jest/globals": "./deno-jest.ts",
4+
"@whatwg-node/cookie-store": "./packages/cookie-store/src/index.ts",
5+
"@whatwg-node/disposablestack": "./packages/disposablestack/src/index.ts",
6+
"@whatwg-node/fetch": "./packages/fetch/dist/esm-ponyfill.js",
7+
"@whatwg-node/events": "./packages/events/src/index.ts",
8+
"fetchache": "./packages/fetchache/src/index.ts",
9+
"@whatwg-node/node-fetch": "./packages/node-fetch/src/index.ts",
10+
"@whatwg-node/server": "./packages/server/src/index.ts",
11+
"@whatwg-node/server-plugin-cookies": "./packages/server-plugin-cookies/src/index.ts"
12+
}
13+
}

e2e/aws-lambda/scripts/createAwsLambdaDeployment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'path';
1+
import { join } from 'node:path';
22
import {
33
assertDeployedEndpoint,
44
DeploymentConfiguration,

e2e/aws-lambda/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Buffer } from 'node:buffer';
12
import { APIGatewayEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
23
import { createTestServerAdapter } from '@e2e/shared-server';
34
import { URL } from '@whatwg-node/fetch';

e2e/azure-function/scripts/createAzureFunctionDeployment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'path';
1+
import { join } from 'node:path';
22
import {
33
assertDeployedEndpoint,
44
DeploymentConfiguration,

e2e/cloudflare-workers/scripts/createCfDeployment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'path';
1+
import { join } from 'node:path';
22
import {
33
assertDeployedEndpoint,
44
DeploymentConfiguration,

e2e/deno/e2e.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)