@@ -38,7 +38,7 @@ function refresh() {
3838
3939const runner = join ( import . meta. dirname , '..' , 'fixtures' , 'test-runner-watch.mjs' ) ;
4040
41- async function testWatch ( { fileToUpdate, file, action = 'update' , cwd = tmpdir . path } ) {
41+ async function testWatch ( { fileToUpdate, file, action = 'update' , cwd = tmpdir . path , fileToCreate } ) {
4242 const ran1 = util . createDeferredPromise ( ) ;
4343 const ran2 = util . createDeferredPromise ( ) ;
4444 const args = [ runner ] ;
@@ -123,10 +123,35 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
123123 }
124124 } ;
125125
126+ const testCreate = async ( ) => {
127+ await ran1 . promise ;
128+ const newFilePath = tmpdir . resolve ( fileToCreate ) ;
129+ const interval = setInterval (
130+ ( ) => writeFileSync (
131+ newFilePath ,
132+ 'module.exports = {};'
133+ ) ,
134+ common . platformTimeout ( 1000 )
135+ ) ;
136+ await ran2 . promise ;
137+ runs . push ( currentRun ) ;
138+ clearInterval ( interval ) ;
139+ child . kill ( ) ;
140+ await once ( child , 'exit' ) ;
141+
142+ for ( const run of runs ) {
143+ assert . match ( run , / # t e s t s 1 / ) ;
144+ assert . match ( run , / # p a s s 1 / ) ;
145+ assert . match ( run , / # f a i l 0 / ) ;
146+ assert . match ( run , / # c a n c e l l e d 0 / ) ;
147+ }
148+ } ;
149+
126150 action === 'update' && await testUpdate ( ) ;
127151 action === 'rename' && await testRename ( ) ;
128152 action === 'rename2' && await testRename ( ) ;
129153 action === 'delete' && await testDelete ( ) ;
154+ action === 'create' && await testCreate ( ) ;
130155}
131156
132157describe ( 'test runner watch mode' , ( ) => {
@@ -172,4 +197,8 @@ describe('test runner watch mode', () => {
172197 action : 'rename2'
173198 } ) ;
174199 } ) ;
200+
201+ it ( 'should run new tests when a new file is created in the watched directory' , async ( ) => {
202+ await testWatch ( { action : 'create' , fileToCreate : 'new-test-file.test.js' } ) ;
203+ } ) ;
175204} ) ;
0 commit comments