Skip to content

Commit 1e80295

Browse files
clydinalan-agius4
authored andcommitted
test: remove node-fetch package usage
Native fetch support is now available in Node.js and the `node-fetch` package can now be removed. (cherry picked from commit e588e84)
1 parent 1628c7f commit 1e80295

File tree

25 files changed

+57
-61
lines changed

25 files changed

+57
-61
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
"@types/less": "^3.0.3",
106106
"@types/loader-utils": "^2.0.0",
107107
"@types/node": "^18.13.0",
108-
"@types/node-fetch": "^2.1.6",
109108
"@types/npm-package-arg": "^6.1.0",
110109
"@types/pacote": "^11.1.3",
111110
"@types/picomatch": "^2.3.0",
@@ -171,7 +170,6 @@
171170
"mini-css-extract-plugin": "2.7.6",
172171
"mrmime": "1.0.1",
173172
"ng-packagr": "17.0.0-rc.0",
174-
"node-fetch": "^2.2.0",
175173
"npm": "^8.11.0",
176174
"npm-package-arg": "11.0.1",
177175
"open": "8.4.2",

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ ts_library(
295295
"//packages/angular_devkit/architect/testing",
296296
"//packages/angular_devkit/core",
297297
"//packages/angular_devkit/core/node",
298-
"@npm//@types/node-fetch",
299298
"@npm//rxjs",
300299
],
301300
)
@@ -314,11 +313,10 @@ LARGE_SPECS = {
314313
"shards": 10,
315314
"size": "large",
316315
"extra_deps": [
317-
"@npm//@types/node-fetch",
318-
"@npm//node-fetch",
319316
"@npm//@types/http-proxy",
320317
"@npm//http-proxy",
321318
"@npm//puppeteer",
319+
"@npm//undici",
322320
],
323321
},
324322
"extract-i18n": {},
@@ -374,9 +372,8 @@ LARGE_SPECS = {
374372
"ssr-dev-server": {
375373
"extra_deps": [
376374
"@npm//@types/browser-sync",
377-
"@npm//@types/node-fetch",
378375
"@npm//browser-sync",
379-
"@npm//node-fetch",
376+
"@npm//undici",
380377
"//packages/angular/ssr",
381378
],
382379
},

packages/angular_devkit/build_angular/src/builders/dev-server/specs/index_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import { DevServerBuilderOutput } from '@angular-devkit/build-angular';
1010
import { workspaces } from '@angular-devkit/core';
11-
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
1211
import { createArchitect, host } from '../../../testing/test-utils';
1312

1413
describe('Dev Server Builder index', () => {

packages/angular_devkit/build_angular/src/builders/dev-server/specs/ssl_spec.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import { Architect, BuilderRun } from '@angular-devkit/architect';
1010
import { DevServerBuilderOutput } from '@angular-devkit/build-angular';
1111
import { tags } from '@angular-devkit/core';
12-
import * as https from 'https';
13-
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
12+
import { Agent, getGlobalDispatcher, setGlobalDispatcher } from 'undici';
1413
import { createArchitect, host } from '../../../testing/test-utils';
1514

1615
describe('Dev Server Builder ssl', () => {
@@ -36,10 +35,20 @@ describe('Dev Server Builder ssl', () => {
3635
expect(output.success).toBe(true);
3736
expect(output.baseUrl).toMatch(/^https:\/\/localhost:\d+\//);
3837

39-
const response = await fetch(output.baseUrl, {
40-
agent: new https.Agent({ rejectUnauthorized: false }),
41-
});
42-
expect(await response.text()).toContain('<title>HelloWorldApp</title>');
38+
// The self-signed certificate used by the dev server will cause fetch to fail
39+
// unless reject unauthorized is disabled.
40+
const originalDispatcher = getGlobalDispatcher();
41+
setGlobalDispatcher(
42+
new Agent({
43+
connect: { rejectUnauthorized: false },
44+
}),
45+
);
46+
try {
47+
const response = await fetch(output.baseUrl);
48+
expect(await response.text()).toContain('<title>HelloWorldApp</title>');
49+
} finally {
50+
setGlobalDispatcher(originalDispatcher);
51+
}
4352
});
4453

4554
it('supports key and cert', async () => {
@@ -113,9 +122,19 @@ describe('Dev Server Builder ssl', () => {
113122
expect(output.success).toBe(true);
114123
expect(output.baseUrl).toMatch(/^https:\/\/localhost:\d+\//);
115124

116-
const response = await fetch(output.baseUrl, {
117-
agent: new https.Agent({ rejectUnauthorized: false }),
118-
});
119-
expect(await response.text()).toContain('<title>HelloWorldApp</title>');
125+
// The self-signed certificate used by the dev server will cause fetch to fail
126+
// unless reject unauthorized is disabled.
127+
const originalDispatcher = getGlobalDispatcher();
128+
setGlobalDispatcher(
129+
new Agent({
130+
connect: { rejectUnauthorized: false },
131+
}),
132+
);
133+
try {
134+
const response = await fetch(output.baseUrl);
135+
expect(await response.text()).toContain('<title>HelloWorldApp</title>');
136+
} finally {
137+
setGlobalDispatcher(originalDispatcher);
138+
}
120139
});
121140
});

packages/angular_devkit/build_angular/src/builders/dev-server/specs/works_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import { Architect, BuilderRun } from '@angular-devkit/architect';
1010
import { DevServerBuilderOutput } from '@angular-devkit/build-angular';
1111
import { normalize, virtualFs } from '@angular-devkit/core';
12-
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
1312
import { createArchitect, host } from '../../../testing/test-utils';
1413

1514
describe('Dev Server Builder', () => {

packages/angular_devkit/build_angular/src/builders/dev-server/tests/behavior/build_localize_replaced_watch_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
/* eslint-disable max-len */
10-
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
1110
import { concatMap, count, take, timeout } from 'rxjs';
1211
import { URL } from 'url';
1312
import { serveWebpackBrowser } from '../../index';

packages/angular_devkit/build_angular/src/builders/dev-server/tests/behavior/build_translation_watch_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
/* eslint-disable max-len */
10-
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
1110
import { concatMap, count, take, timeout } from 'rxjs';
1211
import { URL } from 'url';
1312
import { serveWebpackBrowser } from '../../index';

packages/angular_devkit/build_angular/src/builders/dev-server/tests/behavior/serve_service-worker_spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// eslint-disable-next-line import/no-extraneous-dependencies
10-
import fetch from 'node-fetch';
119
import { concatMap, count, take, timeout } from 'rxjs';
1210
import { serveWebpackBrowser } from '../../index';
1311
import { executeOnceAndFetch } from '../execute-fetch';
@@ -177,7 +175,7 @@ describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
177175
concatMap(async ({ result }, index) => {
178176
expect(result?.success).toBeTrue();
179177
const response = await fetch(new URL('ngsw.json', `${result?.baseUrl}`));
180-
const { hashTable } = await response.json();
178+
const { hashTable } = (await response.json()) as { hashTable: object };
181179
const hashTableEntries = Object.keys(hashTable);
182180

183181
switch (index) {

packages/angular_devkit/build_angular/src/builders/dev-server/tests/execute-fetch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import fetch, { RequestInit, Response } from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
109
import { lastValueFrom, mergeMap, take, timeout } from 'rxjs';
1110
import { URL } from 'url';
1211
import {

packages/angular_devkit/build_angular/src/builders/ssr-dev-server/specs/proxy_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Architect } from '@angular-devkit/architect';
1010
// eslint-disable-next-line import/no-extraneous-dependencies
1111
import * as browserSync from 'browser-sync';
1212
import * as http from 'http';
13-
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
1413
import { createArchitect, host } from '../../../testing/test-utils';
1514
import { SSRDevServerBuilderOutput } from '../index';
1615

0 commit comments

Comments
 (0)