@@ -41,7 +41,7 @@ function refresh() {
4141
4242const runner = join ( import . meta. dirname , '..' , 'fixtures' , 'test-runner-watch.mjs' ) ;
4343
44- async function testWatch ( { fileToUpdate, file, action = 'update' , cwd = tmpdir . path } ) {
44+ async function testWatch ( { fileToUpdate, file, action = 'update' , cwd = tmpdir . path , fileToCreate } ) {
4545 const ran1 = util . createDeferredPromise ( ) ;
4646 const ran2 = util . createDeferredPromise ( ) ;
4747 const args = [ runner ] ;
@@ -56,7 +56,7 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
5656 child . stdout . on ( 'data' , ( data ) => {
5757 stdout += data . toString ( ) ;
5858 currentRun += data . toString ( ) ;
59- const testRuns = stdout . match ( / # d u r a t i o n _ m s \s \d + / g) ;
59+ const testRuns = stdout . match ( / d u r a t i o n _ m s \s \d + / g) ;
6060 if ( testRuns ?. length >= 1 ) ran1 . resolve ( ) ;
6161 if ( testRuns ?. length >= 2 ) ran2 . resolve ( ) ;
6262 } ) ;
@@ -78,10 +78,10 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
7878
7979 for ( const run of runs ) {
8080 assert . doesNotMatch ( run , / r u n \( \) i s b e i n g c a l l e d r e c u r s i v e l y / ) ;
81- assert . match ( run , / # t e s t s 1 / ) ;
82- assert . match ( run , / # p a s s 1 / ) ;
83- assert . match ( run , / # f a i l 0 / ) ;
84- assert . match ( run , / # c a n c e l l e d 0 / ) ;
81+ assert . match ( run , / t e s t s 1 / ) ;
82+ assert . match ( run , / p a s s 1 / ) ;
83+ assert . match ( run , / f a i l 0 / ) ;
84+ assert . match ( run , / c a n c e l l e d 0 / ) ;
8585 }
8686 } ;
8787
@@ -101,21 +101,21 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
101101 assert . strictEqual ( runs . length , 2 ) ;
102102
103103 const [ firstRun , secondRun ] = runs ;
104- assert . match ( firstRun , / # t e s t s 1 / ) ;
105- assert . match ( firstRun , / # p a s s 1 / ) ;
106- assert . match ( firstRun , / # f a i l 0 / ) ;
107- assert . match ( firstRun , / # c a n c e l l e d 0 / ) ;
104+ assert . match ( firstRun , / t e s t s 1 / ) ;
105+ assert . match ( firstRun , / p a s s 1 / ) ;
106+ assert . match ( firstRun , / f a i l 0 / ) ;
107+ assert . match ( firstRun , / c a n c e l l e d 0 / ) ;
108108 assert . doesNotMatch ( firstRun , / r u n \( \) i s b e i n g c a l l e d r e c u r s i v e l y / ) ;
109109
110110 if ( action === 'rename2' ) {
111111 assert . match ( secondRun , / M O D U L E _ N O T _ F O U N D / ) ;
112112 return ;
113113 }
114114
115- assert . match ( secondRun , / # t e s t s 1 / ) ;
116- assert . match ( secondRun , / # p a s s 1 / ) ;
117- assert . match ( secondRun , / # f a i l 0 / ) ;
118- assert . match ( secondRun , / # c a n c e l l e d 0 / ) ;
115+ assert . match ( secondRun , / t e s t s 1 / ) ;
116+ assert . match ( secondRun , / p a s s 1 / ) ;
117+ assert . match ( secondRun , / f a i l 0 / ) ;
118+ assert . match ( secondRun , / c a n c e l l e d 0 / ) ;
119119 assert . doesNotMatch ( secondRun , / r u n \( \) i s b e i n g c a l l e d r e c u r s i v e l y / ) ;
120120 } ;
121121
@@ -144,10 +144,37 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
144144 }
145145 } ;
146146
147+ const testCreate = async ( ) => {
148+ await ran1 . promise ;
149+ runs . push ( currentRun ) ;
150+ currentRun = '' ;
151+ const newFilePath = tmpdir . resolve ( fileToCreate ) ;
152+ const interval = setInterval (
153+ ( ) => writeFileSync (
154+ newFilePath ,
155+ 'module.exports = {};'
156+ ) ,
157+ common . platformTimeout ( 1000 )
158+ ) ;
159+ await ran2 . promise ;
160+ runs . push ( currentRun ) ;
161+ clearInterval ( interval ) ;
162+ child . kill ( ) ;
163+ await once ( child , 'exit' ) ;
164+
165+ for ( const run of runs ) {
166+ assert . match ( run , / t e s t s 1 / ) ;
167+ assert . match ( run , / p a s s 1 / ) ;
168+ assert . match ( run , / f a i l 0 / ) ;
169+ assert . match ( run , / c a n c e l l e d 0 / ) ;
170+ }
171+ } ;
172+
147173 action === 'update' && await testUpdate ( ) ;
148174 action === 'rename' && await testRename ( ) ;
149175 action === 'rename2' && await testRename ( ) ;
150176 action === 'delete' && await testDelete ( ) ;
177+ action === 'create' && await testCreate ( ) ;
151178}
152179
153180describe ( 'test runner watch mode' , ( ) => {
@@ -193,4 +220,8 @@ describe('test runner watch mode', () => {
193220 action : 'rename2'
194221 } ) ;
195222 } ) ;
223+
224+ it ( 'should run new tests when a new file is created in the watched directory' , async ( ) => {
225+ await testWatch ( { action : 'create' , fileToCreate : 'new-test-file.test.js' } ) ;
226+ } ) ;
196227} ) ;
0 commit comments