@@ -31,12 +31,13 @@ const prepareOptions = require("../helpers/prepareOptions");
3131const { remove } = require ( "../helpers/remove" ) ;
3232const supportsObjectHasOwn = require ( "../helpers/supportsObjectHasOwn" ) ;
3333const supportsOptionalChaining = require ( "../helpers/supportsOptionalChaining" ) ;
34+ const testTimeout = require ( "../helpers/testTimeout" ) ;
3435
3536const testRootDirectory = path . join ( __dirname , ".." ) ;
3637const STEP_DELAY = 200 ;
3738const AGGREGATE_TIMEOUT = 50 ;
3839const RETOUCH_DELAY = 1000 ;
39- const RETOUCH_LIMIT = 3 ;
40+ const RETOUCH_LIMIT = 5 ;
4041
4142/**
4243 * @param {string } src src
@@ -325,6 +326,8 @@ const describeCases = (config) => {
325326 // watched files the current step changed which no build has reported yet
326327 /** @type {Set<string> } */
327328 let unseenChanges = new Set ( ) ;
329+ // builds started so far, and how many had started when the step was written
330+ const buildCount = { started : 0 , beforeStep : 0 } ;
328331
329332 const currentWatchStepModule = require ( "../helpers/currentWatchStep" ) ;
330333
@@ -391,7 +394,12 @@ const describeCases = (config) => {
391394 fs . renameSync ( file , away ) ;
392395 fs . renameSync ( away , file ) ;
393396 } else if ( fs . existsSync ( file ) ) {
394- fs . utimesSync ( file , now , now ) ;
397+ // a new mtime alone went unreported on macOS once (#22801), so the
398+ // file is replaced by a copy, which arrives as a fresh file
399+ const copy = `${ file } .retouch` ;
400+ fs . copyFileSync ( file , copy ) ;
401+ fs . utimesSync ( copy , now , now ) ;
402+ fs . renameSync ( copy , file ) ;
395403 } else if ( fs . existsSync ( path . dirname ( file ) ) ) {
396404 // a dropped deletion is re-sent by deleting again; no build
397405 // runs between the two calls, so none sees the file
@@ -418,6 +426,9 @@ const describeCases = (config) => {
418426 ? compiler . compilers
419427 : [ compiler ] ;
420428 for ( const child of compilers ) {
429+ child . hooks . watchRun . tap ( "WatchTestCasesTest" , ( ) => {
430+ buildCount . started ++ ;
431+ } ) ;
421432 child . hooks . finishMake . tap (
422433 { name : "WatchTestCasesTest" , stage : Infinity } ,
423434 assertModuleGraph
@@ -441,6 +452,9 @@ const describeCases = (config) => {
441452 throw new Error ( "No stats reported from Compiler" ) ;
442453 }
443454 if ( waitMode ) return ;
455+ // a late event of the last step can start a build just before this
456+ // step is written; it read the old files, and the new ones start the next
457+ if ( buildCount . started <= buildCount . beforeStep ) return ;
444458 // macOS can report one step's changes over more than the aggregate
445459 // timeout; a build that missed some reuses the stale cached module,
446460 // and the late change starts the build this step's tests wait for
@@ -650,6 +664,7 @@ const describeCases = (config) => {
650664 false ,
651665 changed
652666 ) ;
667+ buildCount . beforeStep = buildCount . started ;
653668 unseenChanges = new Set ( ) ;
654669 if ( ! restartCompiler && watchedCompiler ) {
655670 // only a file the last build watched reports its change
@@ -741,7 +756,7 @@ const describeCases = (config) => {
741756 closeCompiler ( ) . then ( finish ) ;
742757 }
743758 } ,
744- 45000
759+ testTimeout ( 45000 )
745760 ) ;
746761
747762 finish ( ) ;
@@ -755,11 +770,11 @@ const describeCases = (config) => {
755770 }
756771 } ;
757772 timer = setTimeout ( startCompiler , 300 ) ;
758- } , 45000 ) ;
773+ } , testTimeout ( 45000 ) ) ;
759774
760775 for ( const run of runs ) {
761776 const { it : _it , getNumberOfTests } = createLazyTestEnv (
762- 10000 ,
777+ testTimeout ( 10000 ) ,
763778 run . name
764779 ) ;
765780 run . it = _it ;
@@ -787,7 +802,7 @@ const describeCases = (config) => {
787802 it : _it ,
788803 beforeEach : _beforeEach ,
789804 afterEach : _afterEach
790- } = createLazyTestEnv ( 10000 ) ;
805+ } = createLazyTestEnv ( testTimeout ( 10000 ) ) ;
791806 } ) ;
792807 }
793808 } ) ;
0 commit comments