@@ -7,6 +7,7 @@ import { describe, it } from 'node:test';
77import { spawn } from 'node:child_process' ;
88import { writeFileSync , readFileSync , mkdirSync } from 'node:fs' ;
99import { inspect } from 'node:util' ;
10+ import { pathToFileURL } from 'node:url' ;
1011import { createInterface } from 'node:readline' ;
1112
1213if ( common . isIBMi )
@@ -188,7 +189,7 @@ console.log("don't show me");`);
188189 it ( 'should watch changes to dependencies - cjs' , async ( ) => {
189190 const dependency = createTmpFile ( 'module.exports = {};' ) ;
190191 const file = createTmpFile ( `
191- const dependency = require(' ${ dependency . replace ( / \\ / g , '/' ) } ' );
192+ const dependency = require(${ JSON . stringify ( dependency ) } );
192193console.log(dependency);
193194` ) ;
194195 const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : dependency } ) ;
@@ -206,7 +207,7 @@ console.log(dependency);
206207 it ( 'should watch changes to dependencies - esm' , async ( ) => {
207208 const dependency = createTmpFile ( 'module.exports = {};' ) ;
208209 const file = createTmpFile ( `
209- import dependency from 'file:// ${ dependency . replace ( / \\ / g , '/' ) } ' ;
210+ import dependency from ${ JSON . stringify ( pathToFileURL ( dependency ) ) } ;
210211console.log(dependency);
211212` , '.mjs' ) ;
212213 const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : dependency } ) ;
@@ -276,7 +277,7 @@ console.log(values.random);
276277
277278 it ( 'should not load --import modules in main process' , async ( ) => {
278279 const file = createTmpFile ( ) ;
279- const imported = `file:// ${ createTmpFile ( 'setImmediate(() => process.exit(0));' ) } ` ;
280+ const imported = pathToFileURL ( createTmpFile ( 'setImmediate(() => process.exit(0));' ) ) ;
280281 const args = [ '--import' , imported , file ] ;
281282 const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : file , args } ) ;
282283
@@ -318,9 +319,9 @@ console.log(values.random);
318319 it ( 'should watch changes to previously missing ESM dependency' , {
319320 skip : ! supportsRecursive
320321 } , 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' ) ;
324325
325326 await failWriteSucceed ( { file : dependant , watchedFile : dependency } ) ;
326327 } ) ;
0 commit comments