@@ -19,11 +19,18 @@ jest.unmock('cosmiconfig');
19
19
20
20
jest . setTimeout ( 60 * 1000 ) ;
21
21
22
+ // Can't set the "Connection" header in node < 18.14.1 (undici < 5.15.0): https://github.com/nodejs/undici/pull/1829,
23
+ // However in these versions "Connection" is set to "close" by default in node 18 anyway comparing with later version
24
+ const [ nodeVersionMajor , nodeVersionMinor , nodeVersionPatch ] =
25
+ process . versions . node . split ( '.' ) . map ( Number ) ;
26
+ const canSetConnectionHeader =
27
+ nodeVersionMajor > 18 || nodeVersionMinor > 14 || nodeVersionPatch >= 1 ;
28
+
22
29
// Workaround for https://github.com/nodejs/node/issues/54484:
23
30
// Fetch with connection: close to prevent Node reusing connections across tests
24
31
const fetchAndClose = ( path : string ) =>
25
32
fetch ( path , {
26
- headers : { Connection : 'close' } ,
33
+ headers : canSetConnectionHeader ? { Connection : 'close' } : { } ,
27
34
} ) ;
28
35
29
36
describe ( 'Metro development server serves bundles via HTTP' , ( ) => {
@@ -34,7 +41,10 @@ describe('Metro development server serves bundles via HTTP', () => {
34
41
async function downloadAndExec ( path : string , context = { } ) : mixed {
35
42
const response = await fetchAndClose (
36
43
'http://localhost:' + config . server . port + path ,
37
- ) ;
44
+ ) . catch ( e => {
45
+ console . error ( 'Fetch failed' , e ) ;
46
+ throw new Error ( 'Fetch failed' , { cause : e } ) ;
47
+ } ) ;
38
48
bundlesDownloaded . add ( path ) ;
39
49
40
50
const body = await response . text ( ) ;
0 commit comments