@@ -5,17 +5,17 @@ import path from 'node:path';
55import { execPath } from 'node:process' ;
66import { describe , it } from 'node:test' ;
77import { spawn } from 'node:child_process' ;
8- import { writeFileSync , readFileSync } from 'node:fs' ;
8+ import { appendFileSync , mkdirSync , writeFileSync } from 'node:fs' ;
99import { inspect } from 'node:util' ;
1010import { pathToFileURL } from 'node:url' ;
1111import { createInterface } from 'node:readline' ;
1212
1313if ( common . isIBMi )
1414 common . skip ( 'IBMi does not support `fs.watch()`' ) ;
1515
16- function restart ( file , content = readFileSync ( file ) ) {
17- writeFileSync ( file , content ) ;
18- const timer = setInterval ( ( ) => writeFileSync ( file , content ) , common . platformTimeout ( 250 ) ) ;
16+ function restart ( file ) {
17+ appendFileSync ( file , '\n' ) ;
18+ const timer = setInterval ( ( ) => appendFileSync ( file , '\n' ) , common . platformTimeout ( 250 ) ) ;
1919 return ( ) => clearInterval ( timer ) ;
2020}
2121
@@ -26,6 +26,12 @@ function createTmpFile(content = 'console.log(\'running\');', ext = '.js', basen
2626 return file ;
2727}
2828
29+ function createTmpDir ( ) {
30+ const dir = path . join ( tmpdir . path , `${ tmpFiles ++ } ` ) ;
31+ mkdirSync ( dir ) ;
32+ return dir ;
33+ }
34+
2935async function runWriteSucceed ( {
3036 file,
3137 watchedFile,
@@ -78,10 +84,10 @@ async function runWriteSucceed({
7884}
7985
8086tmpdir . refresh ( ) ;
81- const dir = tmpdir . path ;
8287
8388describe ( 'watch mode' , { concurrency : ! process . env . TEST_PARALLEL , timeout : 60_000 } , ( ) => {
8489 it ( 'should watch changes to worker - cjs' , async ( ) => {
90+ const dir = createTmpDir ( ) ;
8591 const worker = path . join ( dir , 'worker.js' ) ;
8692
8793 writeFileSync ( worker , `
@@ -109,6 +115,7 @@ const w = new Worker(${JSON.stringify(worker)});
109115 } ) ;
110116
111117 it ( 'should watch changes to worker dependencies - cjs' , async ( ) => {
118+ const dir = createTmpDir ( ) ;
112119 const dep = path . join ( dir , 'dep.js' ) ;
113120 const worker = path . join ( dir , 'worker.js' ) ;
114121
@@ -142,6 +149,7 @@ const w = new Worker(${JSON.stringify(worker)});
142149 } ) ;
143150
144151 it ( 'should watch changes to nested worker dependencies - cjs' , async ( ) => {
152+ const dir = createTmpDir ( ) ;
145153 const subDep = path . join ( dir , 'sub-dep.js' ) ;
146154 const dep = path . join ( dir , 'dep.js' ) ;
147155 const worker = path . join ( dir , 'worker.js' ) ;
@@ -181,6 +189,7 @@ const w = new Worker(${JSON.stringify(worker)});
181189 } ) ;
182190
183191 it ( 'should watch changes to worker - esm' , async ( ) => {
192+ const dir = createTmpDir ( ) ;
184193 const worker = path . join ( dir , 'worker.mjs' ) ;
185194
186195 writeFileSync ( worker , `
@@ -208,6 +217,7 @@ new Worker(new URL(${JSON.stringify(pathToFileURL(worker))}));
208217 } ) ;
209218
210219 it ( 'should watch changes to worker dependencies - esm' , async ( ) => {
220+ const dir = createTmpDir ( ) ;
211221 const dep = path . join ( dir , 'dep.mjs' ) ;
212222 const worker = path . join ( dir , 'worker.mjs' ) ;
213223
@@ -241,6 +251,7 @@ new Worker(new URL(${JSON.stringify(pathToFileURL(worker))}));
241251 } ) ;
242252
243253 it ( 'should watch changes to nested worker dependencies - esm' , async ( ) => {
254+ const dir = createTmpDir ( ) ;
244255 const subDep = path . join ( dir , 'sub-dep.mjs' ) ;
245256 const dep = path . join ( dir , 'dep.mjs' ) ;
246257 const worker = path . join ( dir , 'worker.mjs' ) ;
0 commit comments