File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -503,7 +503,10 @@ function watchFiles(testFiles, opts) {
503
503
return ; // Avoid rerunning files when file deleted
504
504
}
505
505
}
506
-
506
+ // Reset the root start time to recalculate the duration
507
+ // of the run
508
+ opts . root . clearExecutionTime ( ) ;
509
+ // Restart test files
507
510
if ( opts . isolation === 'none' ) {
508
511
PromisePrototypeThen ( restartTestFile ( kIsolatedProcessName ) , undefined , ( error ) => {
509
512
triggerUncaughtException ( error , true /* fromPromise */ ) ;
Original file line number Diff line number Diff line change @@ -1341,6 +1341,11 @@ class Test extends AsyncResource {
1341
1341
this . parent . reportStarted ( ) ;
1342
1342
this . reporter . start ( this . nesting , this . loc , this . name ) ;
1343
1343
}
1344
+
1345
+ clearExecutionTime ( ) {
1346
+ this . startTime = hrtime ( ) ;
1347
+ this . endTime = null ;
1348
+ }
1344
1349
}
1345
1350
1346
1351
class TestHook extends Test {
Original file line number Diff line number Diff line change @@ -189,6 +189,8 @@ async function testWatch(
189
189
action === 'rename2' && await testRename ( ) ;
190
190
action === 'delete' && await testDelete ( ) ;
191
191
action === 'create' && await testCreate ( ) ;
192
+
193
+ return runs ;
192
194
}
193
195
194
196
describe ( 'test runner watch mode' , ( ) => {
@@ -241,6 +243,20 @@ describe('test runner watch mode', () => {
241
243
await testWatch ( { action : 'create' , fileToCreate : 'new-test-file.test.js' } ) ;
242
244
} ) ;
243
245
246
+ // This test is flaky by its nature as it relies on the timing of 2 different runs
247
+ // considering the number of digits in the duration_ms is 9
248
+ // the chances of having the same duration_ms are very low
249
+ // but not impossible
250
+ // In case of costant failures, consider increasing the number of tests
251
+ it ( 'should recalculate the run duration on a watch restart' , async ( ) => {
252
+ const testRuns = await testWatch ( { file : 'test.js' , fileToUpdate : 'test.js' } ) ;
253
+ const durations = testRuns . map ( ( run ) => {
254
+ const runDuration = run . match ( / # d u r a t i o n _ m s \s ( [ \d . ] + ) / ) ;
255
+ return runDuration ;
256
+ } ) ;
257
+ assert . notDeepStrictEqual ( durations [ 0 ] [ 1 ] , durations [ 1 ] [ 1 ] ) ;
258
+ } ) ;
259
+
244
260
describe ( 'test runner watch mode with different cwd' , ( ) => {
245
261
it (
246
262
'should execute run using a different cwd for the runner than the process cwd' ,
You can’t perform that action at this time.
0 commit comments