@@ -18,7 +18,7 @@ tmpdir.refresh();
1818const fixtureContent = {
1919 'dependency.js' : 'module.exports = {};' ,
2020 'dependency.mjs' : 'export const a = 1;' ,
21- 'dependent .js' : `
21+ 'test .js' : `
2222const test = require('node:test');
2323require('./dependency.js');
2424import('./dependency.mjs');
@@ -30,12 +30,12 @@ const fixturePaths = Object.keys(fixtureContent)
3030Object . entries ( fixtureContent )
3131 . forEach ( ( [ file , content ] ) => writeFileSync ( fixturePaths [ file ] , content ) ) ;
3232
33- async function testWatch ( { fileToUpdate } ) {
33+ async function testWatch ( { fileToUpdate, file } ) {
3434 const ran1 = util . createDeferredPromise ( ) ;
3535 const ran2 = util . createDeferredPromise ( ) ;
3636 const child = spawn ( process . execPath ,
37- [ '--watch' , '--test' , '--no-warnings' , fixturePaths [ 'dependent.js' ] ] ,
38- { encoding : 'utf8' , stdio : 'pipe' } ) ;
37+ [ '--watch' , '--test' , file ? fixturePaths [ file ] : undefined ] . filter ( Boolean ) ,
38+ { encoding : 'utf8' , stdio : 'pipe' , cwd : tmpdir . path } ) ;
3939 let stdout = '' ;
4040
4141 child . stdout . on ( 'data' , ( data ) => {
@@ -48,25 +48,26 @@ async function testWatch({ fileToUpdate }) {
4848 await ran1 . promise ;
4949 const content = fixtureContent [ fileToUpdate ] ;
5050 const path = fixturePaths [ fileToUpdate ] ;
51- const interval = setInterval ( ( ) => {
52- console . log ( `Updating ${ path } ` ) ;
53- writeFileSync ( path , content ) ;
54- } , 50 ) ;
51+ const interval = setInterval ( ( ) => writeFileSync ( path , content ) , common . platformTimeout ( 1000 ) ) ;
5552 await ran2 . promise ;
5653 clearInterval ( interval ) ;
5754 child . kill ( ) ;
5855}
5956
6057describe ( 'test runner watch mode' , ( ) => {
6158 it ( 'should run tests repeatedly' , async ( ) => {
62- await testWatch ( { fileToUpdate : 'dependent .js' } ) ;
59+ await testWatch ( { file : 'test.js' , fileToUpdate : 'test .js' } ) ;
6360 } ) ;
6461
6562 it ( 'should run tests with dependency repeatedly' , async ( ) => {
66- await testWatch ( { fileToUpdate : 'dependency.js' } ) ;
63+ await testWatch ( { file : 'test.js' , fileToUpdate : 'dependency.js' } ) ;
6764 } ) ;
6865
6966 it ( 'should run tests with ESM dependency' , async ( ) => {
70- await testWatch ( { fileToUpdate : 'dependency.mjs' } ) ;
67+ await testWatch ( { file : 'test.js' , fileToUpdate : 'dependency.mjs' } ) ;
68+ } ) ;
69+
70+ it ( 'should support running tests without a file' , async ( ) => {
71+ await testWatch ( { fileToUpdate : 'test.js' } ) ;
7172 } ) ;
7273} ) ;
0 commit comments