-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace node-fetch
with native fetch
in tests and docs
#1327
Conversation
This pull request was exported from Phabricator. Differential Revision: D61336391 |
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'}}); ``` However, since we only use `node-fetch` in this test it seems like a good chance to remove it completely and use the native `fetch` provided by node (stable since Node.js v21, but works well in older node versions for the purpose of testing). The native fetch also defaults to `keepAlive: true` (https://github.com/nodejs/undici?tab=readme-ov-file#pipelining) which I manually tweaked to be false. Differential Revision: D61336391
This pull request was exported from Phabricator. Differential Revision: D61336391 |
dcbc9ef
to
c1af98d
Compare
Summary: 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'}}); ``` Differential Revision: D61336391
c1af98d
to
f266d20
Compare
This pull request was exported from Phabricator. Differential Revision: D61336391 |
1 similar comment
This pull request was exported from Phabricator. Differential Revision: D61336391 |
f266d20
to
806f87b
Compare
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'}}); ``` Differential Revision: D61336391
Summary: 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'}}); ``` Differential Revision: D61336391
806f87b
to
a74db64
Compare
This pull request was exported from Phabricator. Differential Revision: D61336391 |
Interesting, feels like a Node bug to me... const {createServer} = require('node:http');
const port = 8080;
const url = 'http://localhost:' + port
async function main() {
const server1 = createServer((req, res) => res.end());
await new Promise(r => server1.listen(port, r));
await fetch(url);
await new Promise(r => setTimeout(r, 0));
await new Promise(r => server1.close(r));
const server2 = createServer((req, res) => res.end());
await new Promise(r => server2.listen(port, r));
await fetch(url); // Throws
await new Promise(r => server2.close(r));
}
main();
|
Opened nodejs/undici#3492 |
This pull request was exported from Phabricator. Differential Revision: D61336391 |
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'}}); ``` Reviewed By: robhogan Differential Revision: D61336391
a74db64
to
8e0e043
Compare
This pull request was exported from Phabricator. Differential Revision: D61336391 |
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'}}); ``` Reviewed By: robhogan Differential Revision: D61336391
8e0e043
to
1454218
Compare
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 Reviewed By: robhogan Differential Revision: D61336391
This pull request was exported from Phabricator. Differential Revision: D61336391 |
1454218
to
fcdefe8
Compare
This pull request has been merged in 60de111. |
node-fetch
with native fetch
in tests and docs
Summary:
Updating
node-fetch
to the latest version caused tests inpackages/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: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.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: nodejs/undici#3492
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.
Differential Revision: D61336391