Skip to content

Commit 60de111

Browse files
vzaidmanfacebook-github-bot
authored andcommitted
updated node-fetch (#1327)
Summary: Pull Request resolved: #1327 Updating `node-fetch` to the latest version caused tests in `packages/metro/src/integration_tests/__tests__/server-test.js` to fail. Running each test case inside the file failed individually, but there seems to have been a race condition between the tests causing subsequent tests to fail with the following error: ``` FetchError: request to http://localhost:10028/import-export/index.bundle?platform=ios&dev=true&minify=false failed, reason: socket hang up ``` It happens because the "connection: close" header is removed in the latest version of `node-fetch`: node-fetch/node-fetch#1765 and can be fixed by adding this header manually to fetches. ``` fetch('path', {headers: {'Connection': 'close'}}); ``` This diff introduces a workaround where we add that header, however `fetch` is expected to work even without it when the following bug is fixed: https://github.com/nodejs/node/issues/54484 Also, since `node-fetch` was only used in this one test, it was actually a good opportunity to remove it from the project's dependencies altogether. Reviewed By: robhogan Differential Revision: D61336391 fbshipit-source-id: 898c9745dbbc1e622699ff36b4112a95c3c68656
1 parent c6e5686 commit 60de111

File tree

5 files changed

+17
-38
lines changed

5 files changed

+17
-38
lines changed

packages/metro/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"metro-transform-plugins": "0.80.10",
4949
"metro-transform-worker": "0.80.10",
5050
"mime-types": "^2.1.27",
51-
"node-fetch": "^2.2.0",
5251
"nullthrows": "^1.1.1",
5352
"serialize-error": "^2.1.0",
5453
"source-map": "^0.5.6",

packages/metro/src/integration_tests/__tests__/server-test.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@
1313
const Metro = require('../../..');
1414
const execBundle = require('../execBundle');
1515
const fs = require('fs');
16-
const fetch = require('node-fetch');
1716
const path = require('path');
1817

1918
jest.unmock('cosmiconfig');
2019

2120
jest.setTimeout(60 * 1000);
2221

22+
// Workaround for https://github.com/nodejs/node/issues/54484:
23+
// Fetch with connection: close to prevent Node reusing connections across tests
24+
const fetchAndClose = (path: string) =>
25+
fetch(path, {
26+
headers: {Connection: 'close'},
27+
});
28+
2329
describe('Metro development server serves bundles via HTTP', () => {
2430
let config;
2531
let httpServer;
2632
const bundlesDownloaded = new Set();
2733

2834
async function downloadAndExec(path: string, context = {}): mixed {
29-
const response = await fetch(
35+
const response = await fetchAndClose(
3036
'http://localhost:' + config.server.port + path,
3137
);
3238
bundlesDownloaded.add(path);
@@ -111,14 +117,14 @@ describe('Metro development server serves bundles via HTTP', () => {
111117
});
112118

113119
test('responds with 404 when the bundle cannot be resolved', async () => {
114-
const response = await fetch(
120+
const response = await fetchAndClose(
115121
'http://localhost:' + config.server.port + '/doesnotexist.bundle',
116122
);
117123
expect(response.status).toBe(404);
118124
});
119125

120126
test('responds with 500 when an import inside the bundle cannot be resolved', async () => {
121-
const response = await fetch(
127+
const response = await fetchAndClose(
122128
'http://localhost:' +
123129
config.server.port +
124130
'/build-errors/inline-requires-cannot-resolve-import.bundle',
@@ -128,7 +134,7 @@ describe('Metro development server serves bundles via HTTP', () => {
128134

129135
describe('dedicated endpoints for serving source files', () => {
130136
test('under /[metro-project]/', async () => {
131-
const response = await fetch(
137+
const response = await fetchAndClose(
132138
'http://localhost:' +
133139
config.server.port +
134140
'/[metro-project]/TestBundle.js',
@@ -143,7 +149,7 @@ describe('Metro development server serves bundles via HTTP', () => {
143149
});
144150

145151
test('under /[metro-watchFolders]/', async () => {
146-
const response = await fetch(
152+
const response = await fetchAndClose(
147153
'http://localhost:' +
148154
config.server.port +
149155
'/[metro-watchFolders]/1/metro/src/integration_tests/basic_bundle/TestBundle.js',
@@ -158,7 +164,7 @@ describe('Metro development server serves bundles via HTTP', () => {
158164
});
159165

160166
test('under /[metro-project]/', async () => {
161-
const response = await fetch(
167+
const response = await fetchAndClose(
162168
'http://localhost:' +
163169
config.server.port +
164170
'/[metro-project]/TestBundle.js',
@@ -173,7 +179,7 @@ describe('Metro development server serves bundles via HTTP', () => {
173179
});
174180

175181
test('no access to files without source extensions', async () => {
176-
const response = await fetch(
182+
const response = await fetchAndClose(
177183
'http://localhost:' +
178184
config.server.port +
179185
'/[metro-project]/not_a_source_file.xyz',
@@ -188,7 +194,7 @@ describe('Metro development server serves bundles via HTTP', () => {
188194
});
189195

190196
test('no access to source files excluded from the file map', async () => {
191-
const response = await fetch(
197+
const response = await fetchAndClose(
192198
'http://localhost:' +
193199
config.server.port +
194200
'/[metro-project]/excluded_from_file_map.js',
@@ -203,7 +209,7 @@ describe('Metro development server serves bundles via HTTP', () => {
203209
});
204210

205211
test('requested with aggressive URL encoding /%5Bmetro-project%5D', async () => {
206-
const response = await fetch(
212+
const response = await fetchAndClose(
207213
'http://localhost:' +
208214
config.server.port +
209215
'/%5Bmetro-project%5D/Foo%2Ejs',

website/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"@sideway/formula": "^3.0.1",
3131
"got": "^11.8.5",
3232
"http-cache-semantics": "^4.1.1",
33-
"node-fetch": "^2.0.0",
3433
"terser": "^5.14.2",
3534
"trim": "^0.0.3"
3635
}

website/yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -7727,7 +7727,7 @@ node-emoji@^1.10.0:
77277727
dependencies:
77287728
lodash.toarray "^4.4.0"
77297729

7730-
[email protected], node-fetch@^2.0.0:
7730+
77317731
version "2.6.7"
77327732
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
77337733
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==

yarn.lock

-25
Original file line numberDiff line numberDiff line change
@@ -4930,13 +4930,6 @@ node-dir@^0.1.17:
49304930
dependencies:
49314931
minimatch "^3.0.2"
49324932

4933-
node-fetch@^2.2.0:
4934-
version "2.6.7"
4935-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
4936-
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
4937-
dependencies:
4938-
whatwg-url "^5.0.0"
4939-
49404933
node-int64@^0.4.0:
49414934
version "0.4.0"
49424935
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
@@ -5959,11 +5952,6 @@ to-regex-range@^5.0.1:
59595952
dependencies:
59605953
is-number "^7.0.0"
59615954

5962-
tr46@~0.0.3:
5963-
version "0.0.3"
5964-
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
5965-
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
5966-
59675955
ts-api-utils@^1.0.1:
59685956
version "1.0.3"
59695957
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.3.tgz#f12c1c781d04427313dbac808f453f050e54a331"
@@ -6142,19 +6130,6 @@ walker@^1.0.8:
61426130
dependencies:
61436131
makeerror "1.0.12"
61446132

6145-
webidl-conversions@^3.0.0:
6146-
version "3.0.1"
6147-
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
6148-
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
6149-
6150-
whatwg-url@^5.0.0:
6151-
version "5.0.0"
6152-
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
6153-
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
6154-
dependencies:
6155-
tr46 "~0.0.3"
6156-
webidl-conversions "^3.0.0"
6157-
61586133
which-boxed-primitive@^1.0.2:
61596134
version "1.0.2"
61606135
resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"

0 commit comments

Comments
 (0)