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) {
503503 return ; // Avoid rerunning files when file deleted
504504 }
505505 }
506-
506+ // Reset the root start time to recalculate the duration
507+ // of the run
508+ opts . root . clearExecutionTime ( ) ;
509+ // Restart test files
507510 if ( opts . isolation === 'none' ) {
508511 PromisePrototypeThen ( restartTestFile ( kIsolatedProcessName ) , undefined , ( error ) => {
509512 triggerUncaughtException ( error , true /* fromPromise */ ) ;
Original file line number Diff line number Diff line change @@ -1341,6 +1341,11 @@ class Test extends AsyncResource {
13411341 this . parent . reportStarted ( ) ;
13421342 this . reporter . start ( this . nesting , this . loc , this . name ) ;
13431343 }
1344+
1345+ clearExecutionTime ( ) {
1346+ this . startTime = hrtime ( ) ;
1347+ this . endTime = null ;
1348+ }
13441349}
13451350
13461351class TestHook extends Test {
Original file line number Diff line number Diff line change @@ -189,6 +189,8 @@ async function testWatch(
189189 action === 'rename2' && await testRename ( ) ;
190190 action === 'delete' && await testDelete ( ) ;
191191 action === 'create' && await testCreate ( ) ;
192+
193+ return runs ;
192194}
193195
194196describe ( 'test runner watch mode' , ( ) => {
@@ -241,6 +243,20 @@ describe('test runner watch mode', () => {
241243 await testWatch ( { action : 'create' , fileToCreate : 'new-test-file.test.js' } ) ;
242244 } ) ;
243245
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+
244260 describe ( 'test runner watch mode with different cwd' , ( ) => {
245261 it (
246262 '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