Skip to content

Commit 9ae3d2a

Browse files
committed
1 parent 16a84d5 commit 9ae3d2a

File tree

12 files changed

+40
-179
lines changed

12 files changed

+40
-179
lines changed

.github/workflows/node.js.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jobs:
2929
- run: npm run tsc:examples
3030
- run: npm run start:examples
3131
- run: npm run test:undici
32-
- run: npm run test:node-fetch
3332
- run: npm run test:e2e
3433
- run: npm run test:coverage:whatwg-fetch
3534
- run: npm run test:coverage:examples

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) wrapper.
1414
- No dependencies
1515
- Supports Node.js & web browsers
1616
- Comes with test utilities
17-
- Fully tested (against [node-fetch](https://github.com/node-fetch/node-fetch), [whatwg-fetch](https://github.com/github/fetch) & [undici](https://github.com/nodejs/undici))
17+
- Fully tested (against [Undici](https://github.com/nodejs/undici) & [whatwg-fetch](https://github.com/github/fetch))
1818
- Written in TypeScript
1919

2020
## Why?
@@ -94,7 +94,7 @@ Or copy-paste [Http.ts](src/Http.ts) into your source code.
9494

9595
- Nothing is needed if Node.js >= 18.0
9696
- Use [`--experimental-fetch`](https://nodejs.org/docs/latest-v16.x/api/cli.html#--experimental-fetch) if Node.js >= 16.15 < 18.0
97-
- [node-fetch](https://github.com/node-fetch/node-fetch) if Node.js < 16.15
97+
- ⚠️ [node-fetch](https://github.com/node-fetch/node-fetch) is not supported with @tkrotoff/fetch >= 0.17 due to [`Request` class limitations](https://github.com/node-fetch/node-fetch/blob/v3.3.1/README.md#class-request)
9898

9999
Check [examples/node](examples/node)
100100

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const { defaults } = require('jest-config');
55

66
// [How to set transformIgnorePatterns to fix "Jest encountered an unexpected token"](https://github.com/nrwl/nx/issues/812)
7-
const esModules = ['node-fetch', 'data-uri-to-buffer', 'fetch-blob', 'formdata-polyfill'];
7+
const esModules = [];
88

99
/** @type {import('jest').Config} */
1010
const config = {

jest.setup.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@ console.assert = assert;
77
/* eslint-disable global-require, @typescript-eslint/no-var-requires */
88
const fetchPolyfill = process.env.FETCH;
99
switch (fetchPolyfill) {
10-
case 'whatwg-fetch': {
11-
const whatwgFetch = require('whatwg-fetch');
12-
globalThis.fetch = whatwgFetch.fetch;
13-
globalThis.Request = whatwgFetch.Request;
14-
globalThis.Response = whatwgFetch.Response;
15-
globalThis.Headers = whatwgFetch.Headers;
16-
break;
17-
}
18-
case 'node-fetch': {
19-
const nodeFetch = require('node-fetch');
20-
globalThis.fetch = nodeFetch.default;
21-
globalThis.Request = nodeFetch.Request;
22-
globalThis.Response = nodeFetch.Response;
23-
globalThis.Headers = nodeFetch.Headers;
24-
break;
25-
}
2610
case 'undici': {
2711
const undici = require('undici');
2812
globalThis.fetch = undici.fetch;
@@ -31,6 +15,14 @@ switch (fetchPolyfill) {
3115
globalThis.Headers = undici.Headers;
3216
break;
3317
}
18+
case 'whatwg-fetch': {
19+
const whatwgFetch = require('whatwg-fetch');
20+
globalThis.fetch = whatwgFetch.fetch;
21+
globalThis.Request = whatwgFetch.Request;
22+
globalThis.Response = whatwgFetch.Response;
23+
globalThis.Headers = whatwgFetch.Headers;
24+
break;
25+
}
3426
default: {
3527
assert(false, `Invalid fetch polyfill: '${fetchPolyfill}'`);
3628
}

package-lock.json

Lines changed: 0 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"test:coverage": "npm run test:coverage:undici",
3838
"test:undici": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=undici jest --verbose",
3939
"test:coverage:undici": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=undici jest --coverage",
40-
"test:node-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=node-fetch jest --verbose",
4140
"test:whatwg-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=whatwg-fetch jest --env=jsdom --verbose",
4241
"test:coverage:whatwg-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=whatwg-fetch jest --env=jsdom --coverage",
4342
"test:e2e": "playwright test",
@@ -84,7 +83,6 @@
8483
"husky": "^8.0.3",
8584
"jest": "^29.5.0",
8685
"jest-environment-jsdom": "^29.5.0",
87-
"node-fetch": "^3.3.1",
8886
"playwright": "^1.34.3",
8987
"prettier": "^2.8.8",
9088
"rollup": "^3.23.0",

src/Http.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -565,18 +565,14 @@ describe('body methods', () => {
565565
// https://github.com/whatwg/fetch/issues/1147
566566
let bodyAlreadyUsedError = '';
567567
switch (process.env.FETCH) {
568-
case 'node-fetch': {
569-
bodyAlreadyUsedError = 'body used already for: ';
568+
case 'undici': {
569+
bodyAlreadyUsedError = 'Body is unusable';
570570
break;
571571
}
572572
case 'whatwg-fetch': {
573573
bodyAlreadyUsedError = 'Already read';
574574
break;
575575
}
576-
case 'undici': {
577-
bodyAlreadyUsedError = 'Body is unusable';
578-
break;
579-
}
580576
default: {
581577
assert(false, `Unknown FETCH env '${process.env.FETCH}'`);
582578
}
@@ -634,18 +630,14 @@ test('cannot connect', async () => {
634630

635631
let requestFailedError = '';
636632
switch (process.env.FETCH) {
637-
case 'node-fetch': {
638-
requestFailedError = `request to ${url} failed, reason: connect ECONNREFUSED 127.0.0.1:80`;
633+
case 'undici': {
634+
requestFailedError = 'fetch failed';
639635
break;
640636
}
641637
case 'whatwg-fetch': {
642638
requestFailedError = 'Network request failed';
643639
break;
644640
}
645-
case 'undici': {
646-
requestFailedError = 'fetch failed';
647-
break;
648-
}
649641
default: {
650642
assert(false, `Unknown FETCH env '${process.env.FETCH}'`);
651643
}
@@ -659,7 +651,7 @@ test('cannot connect', async () => {
659651
} catch (e) {
660652
assert(e instanceof Error);
661653
/* eslint-disable jest/no-conditional-expect */
662-
expect(e.name).toEqual(process.env.FETCH === 'node-fetch' ? 'FetchError' : 'TypeError');
654+
expect(e.name).toEqual('TypeError');
663655
expect(e.message).toEqual(requestFailedError);
664656
/* eslint-enable jest/no-conditional-expect */
665657
}

src/HttpError.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test('HttpError with statusText (HTTP/1.1)', async () => {
4040

4141
test('HttpError without statusText because of HTTP/2', async () => {
4242
// ["HTTP/2 doesn't have reason phrases anymore"](https://stackoverflow.com/q/41632077)
43-
// Unfortunately HTTP/2 does not work with whatwg-fetch/jsdom and node-fetch so we cannot test using HTTP/2
43+
// Unfortunately HTTP/2 does not work with whatwg-fetch/jsdom so we cannot test using HTTP/2
4444
// Let's emulate an empty statusText instead
4545

4646
const body = {

0 commit comments

Comments
 (0)