@@ -36,6 +36,7 @@ const { createInterface } = require('readline');
3636const { deserializeError } = require ( 'internal/error_serdes' ) ;
3737const { Buffer } = require ( 'buffer' ) ;
3838const { FilesWatcher } = require ( 'internal/watch_mode/files_watcher' ) ;
39+ const { queueMicrotask } = require ( 'internal/process/task_queues' ) ;
3940const console = require ( 'internal/console/global' ) ;
4041const {
4142 codes : {
@@ -378,6 +379,7 @@ function runTestFile(path, filesWatcher, opts) {
378379 filesWatcher . runningSubtests . delete ( path ) ;
379380 if ( filesWatcher . runningSubtests . size === 0 ) {
380381 opts . root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
382+ queueMicrotask ( ( ) => opts . root . postRun ( ) ) ;
381383 }
382384 }
383385
@@ -405,6 +407,7 @@ function watchFiles(testFiles, opts) {
405407 const runningSubtests = new SafeMap ( ) ;
406408 const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal : opts . signal } ) ;
407409 const filesWatcher = { __proto__ : null , watcher, runningProcesses, runningSubtests } ;
410+ opts . root . harness . watching = true ;
408411
409412 watcher . on ( 'changed' , ( { owners } ) => {
410413 watcher . unfilterFilesOwnedBy ( owners ) ;
@@ -431,7 +434,10 @@ function watchFiles(testFiles, opts) {
431434 kResistStopPropagation ??= require ( 'internal/event_target' ) . kResistStopPropagation ;
432435 opts . signal . addEventListener (
433436 'abort' ,
434- ( ) => opts . root . postRun ( ) ,
437+ ( ) => {
438+ opts . root . harness . watching = false ;
439+ opts . root . postRun ( ) ;
440+ } ,
435441 { __proto__ : null , once : true , [ kResistStopPropagation ] : true } ,
436442 ) ;
437443 }
0 commit comments