Skip to content
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

fix native fetch error in server-test on node 18 #1341

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/metro/src/integration_tests/__tests__/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ jest.unmock('cosmiconfig');

jest.setTimeout(60 * 1000);

// Can't set the "Connection" header in node < 18.14.1 (undici < 5.15.0): https://github.com/nodejs/undici/pull/1829,
// However in these versions "Connection" is set to "close" by default in node 18 anyway comparing with later version
const [nodeVersionMajor, nodeVersionMinor, nodeVersionPatch] =
process.versions.node.split('.').map(Number);
const canSetConnectionHeader =
nodeVersionMajor > 18 ||
(nodeVersionMajor === 18 && nodeVersionMinor > 14) ||
(nodeVersionMajor === 18 && nodeVersionMinor === 14 && nodeVersionPatch >= 1);

// Workaround for https://github.com/nodejs/node/issues/54484:
// Fetch with connection: close to prevent Node reusing connections across tests
const fetchAndClose = (path: string) =>
fetch(path, {
headers: {Connection: 'close'},
headers: canSetConnectionHeader ? {Connection: 'close'} : {},
});

describe('Metro development server serves bundles via HTTP', () => {
Expand Down
Loading