@@ -17,7 +17,7 @@ tmpdir.refresh();
1717const  fixtureContent  =  { 
1818  'dependency.js' : 'module.exports = {};' , 
1919  'dependency.mjs' : 'export const a = 1;' , 
20-   'dependent .js' : ` 
20+   'test .js' : ` 
2121const test = require('node:test'); 
2222require('./dependency.js'); 
2323import('./dependency.mjs'); 
@@ -29,12 +29,12 @@ const fixturePaths = Object.keys(fixtureContent)
2929Object . entries ( fixtureContent ) 
3030  . forEach ( ( [ file ,  content ] )  =>  writeFileSync ( fixturePaths [ file ] ,  content ) ) ; 
3131
32- async  function  testWatch ( {  fileToUpdate } )  { 
32+ async  function  testWatch ( {  fileToUpdate,  file  } )  { 
3333  const  ran1  =  util . createDeferredPromise ( ) ; 
3434  const  ran2  =  util . createDeferredPromise ( ) ; 
3535  const  child  =  spawn ( process . execPath , 
36-                       [ '--watch' ,  '--test' ,  '--no-warnings' ,   fixturePaths [ 'dependent.js' ] ] , 
37-                       {  encoding : 'utf8' ,  stdio : 'pipe'  } ) ; 
36+                       [ '--watch' ,  '--test' ,  file  ?  fixturePaths [ file ]  :  undefined ] . filter ( Boolean ) , 
37+                       {  encoding : 'utf8' ,  stdio : 'pipe' ,   cwd :  tmpdir . path  } ) ; 
3838  let  stdout  =  '' ; 
3939
4040  child . stdout . on ( 'data' ,  ( data )  =>  { 
@@ -47,25 +47,26 @@ async function testWatch({ fileToUpdate }) {
4747  await  ran1 . promise ; 
4848  const  content  =  fixtureContent [ fileToUpdate ] ; 
4949  const  path  =  fixturePaths [ fileToUpdate ] ; 
50-   const  interval  =  setInterval ( ( )  =>  { 
51-     console . log ( `Updating ${ path }  ) ; 
52-     writeFileSync ( path ,  content ) ; 
53-   } ,  50 ) ; 
50+   const  interval  =  setInterval ( ( )  =>  writeFileSync ( path ,  content ) ,  50 ) ; 
5451  await  ran2 . promise ; 
5552  clearInterval ( interval ) ; 
5653  child . kill ( ) ; 
5754} 
5855
5956describe ( 'test runner watch mode' ,  ( )  =>  { 
6057  it ( 'should run tests repeatedly' ,  async  ( )  =>  { 
61-     await  testWatch ( {  fileToUpdate : 'dependent .js'  } ) ; 
58+     await  testWatch ( {  file :  'test.js' ,   fileToUpdate : 'test .js'  } ) ; 
6259  } ) ; 
6360
6461  it ( 'should run tests with dependency repeatedly' ,  async  ( )  =>  { 
65-     await  testWatch ( {  fileToUpdate : 'dependency.js'  } ) ; 
62+     await  testWatch ( {  file :  'test.js' ,   fileToUpdate : 'dependency.js'  } ) ; 
6663  } ) ; 
6764
6865  it ( 'should run tests with ESM dependency' ,  async  ( )  =>  { 
69-     await  testWatch ( {  fileToUpdate : 'dependency.mjs'  } ) ; 
66+     await  testWatch ( {  file : 'test.js' ,  fileToUpdate : 'dependency.mjs'  } ) ; 
67+   } ) ; 
68+ 
69+   it ( 'should support running tests without a file' ,  async  ( )  =>  { 
70+     await  testWatch ( {  fileToUpdate : 'test.js'  } ) ; 
7071  } ) ; 
7172} ) ; 
0 commit comments