@@ -41,7 +41,7 @@ function refresh() {
41
41
42
42
const runner = join ( import . meta. dirname , '..' , 'fixtures' , 'test-runner-watch.mjs' ) ;
43
43
44
- async function testWatch ( { fileToUpdate, file, action = 'update' , cwd = tmpdir . path } ) {
44
+ async function testWatch ( { fileToUpdate, file, action = 'update' , cwd = tmpdir . path , fileToCreate } ) {
45
45
const ran1 = util . createDeferredPromise ( ) ;
46
46
const ran2 = util . createDeferredPromise ( ) ;
47
47
const args = [ runner ] ;
@@ -56,7 +56,7 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
56
56
child . stdout . on ( 'data' , ( data ) => {
57
57
stdout += data . toString ( ) ;
58
58
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) ;
60
60
if ( testRuns ?. length >= 1 ) ran1 . resolve ( ) ;
61
61
if ( testRuns ?. length >= 2 ) ran2 . resolve ( ) ;
62
62
} ) ;
@@ -78,10 +78,10 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
78
78
79
79
for ( const run of runs ) {
80
80
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 / ) ;
85
85
}
86
86
} ;
87
87
@@ -101,21 +101,21 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
101
101
assert . strictEqual ( runs . length , 2 ) ;
102
102
103
103
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 / ) ;
108
108
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 / ) ;
109
109
110
110
if ( action === 'rename2' ) {
111
111
assert . match ( secondRun , / M O D U L E _ N O T _ F O U N D / ) ;
112
112
return ;
113
113
}
114
114
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 / ) ;
119
119
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 / ) ;
120
120
} ;
121
121
@@ -144,10 +144,37 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
144
144
}
145
145
} ;
146
146
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
+
147
173
action === 'update' && await testUpdate ( ) ;
148
174
action === 'rename' && await testRename ( ) ;
149
175
action === 'rename2' && await testRename ( ) ;
150
176
action === 'delete' && await testDelete ( ) ;
177
+ action === 'create' && await testCreate ( ) ;
151
178
}
152
179
153
180
describe ( 'test runner watch mode' , ( ) => {
@@ -193,4 +220,8 @@ describe('test runner watch mode', () => {
193
220
action : 'rename2'
194
221
} ) ;
195
222
} ) ;
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
+ } ) ;
196
227
} ) ;
0 commit comments