@@ -7,6 +7,7 @@ import { describe, it } from 'node:test';
7
7
import { spawn } from 'node:child_process' ;
8
8
import { writeFileSync , readFileSync , mkdirSync } from 'node:fs' ;
9
9
import { inspect } from 'node:util' ;
10
+ import { pathToFileURL } from 'node:url' ;
10
11
import { createInterface } from 'node:readline' ;
11
12
12
13
if ( common . isIBMi )
@@ -188,7 +189,7 @@ console.log("don't show me");`);
188
189
it ( 'should watch changes to dependencies - cjs' , async ( ) => {
189
190
const dependency = createTmpFile ( 'module.exports = {};' ) ;
190
191
const file = createTmpFile ( `
191
- const dependency = require(' ${ dependency . replace ( / \\ / g , '/' ) } ' );
192
+ const dependency = require(${ JSON . stringify ( dependency ) } );
192
193
console.log(dependency);
193
194
` ) ;
194
195
const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : dependency } ) ;
@@ -206,7 +207,7 @@ console.log(dependency);
206
207
it ( 'should watch changes to dependencies - esm' , async ( ) => {
207
208
const dependency = createTmpFile ( 'module.exports = {};' ) ;
208
209
const file = createTmpFile ( `
209
- import dependency from 'file:// ${ dependency . replace ( / \\ / g , '/' ) } ' ;
210
+ import dependency from ${ JSON . stringify ( pathToFileURL ( dependency ) ) } ;
210
211
console.log(dependency);
211
212
` , '.mjs' ) ;
212
213
const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : dependency } ) ;
@@ -276,7 +277,7 @@ console.log(values.random);
276
277
277
278
it ( 'should not load --import modules in main process' , async ( ) => {
278
279
const file = createTmpFile ( ) ;
279
- const imported = `file:// ${ createTmpFile ( 'setImmediate(() => process.exit(0));' ) } ` ;
280
+ const imported = pathToFileURL ( createTmpFile ( 'setImmediate(() => process.exit(0));' ) ) ;
280
281
const args = [ '--import' , imported , file ] ;
281
282
const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : file , args } ) ;
282
283
@@ -318,9 +319,9 @@ console.log(values.random);
318
319
it ( 'should watch changes to previously missing ESM dependency' , {
319
320
skip : ! supportsRecursive
320
321
} , async ( ) => {
321
- const dependency = path . join ( tmpdir . path , ` ${ tmpFiles ++ } .mjs`) ;
322
- const relativeDependencyPath = `./ ${ path . basename ( dependency ) } ` ;
323
- const dependant = createTmpFile ( `import ' ${ relativeDependencyPath } ' ` , '.mjs' ) ;
322
+ const relativeDependencyPath = `./ ${ tmpFiles ++ } .mjs`;
323
+ const dependency = path . join ( tmpdir . path , relativeDependencyPath ) ;
324
+ const dependant = createTmpFile ( `import ${ JSON . stringify ( relativeDependencyPath ) } ` , '.mjs' ) ;
324
325
325
326
await failWriteSucceed ( { file : dependant , watchedFile : dependency } ) ;
326
327
} ) ;
0 commit comments