@@ -35,6 +35,7 @@ const { createInterface } = require('readline');
3535const { deserializeError } = require ( 'internal/error_serdes' ) ;
3636const { Buffer } = require ( 'buffer' ) ;
3737const { FilesWatcher } = require ( 'internal/watch_mode/files_watcher' ) ;
38+ const { queueMicrotask } = require ( 'internal/process/task_queues' ) ;
3839const console = require ( 'internal/console/global' ) ;
3940const {
4041 codes : {
@@ -421,6 +422,7 @@ function runTestFile(path, filesWatcher, opts) {
421422 filesWatcher . runningSubtests . delete ( path ) ;
422423 if ( filesWatcher . runningSubtests . size === 0 ) {
423424 opts . root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
425+ queueMicrotask ( ( ) => opts . root . postRun ( ) ) ;
424426 }
425427 }
426428
@@ -448,6 +450,7 @@ function watchFiles(testFiles, opts) {
448450 const runningSubtests = new SafeMap ( ) ;
449451 const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal : opts . signal } ) ;
450452 const filesWatcher = { __proto__ : null , watcher, runningProcesses, runningSubtests } ;
453+ opts . root . harness . watching = true ;
451454
452455 watcher . on ( 'changed' , ( { owners } ) => {
453456 watcher . unfilterFilesOwnedBy ( owners ) ;
@@ -474,7 +477,10 @@ function watchFiles(testFiles, opts) {
474477 kResistStopPropagation ??= require ( 'internal/event_target' ) . kResistStopPropagation ;
475478 opts . signal . addEventListener (
476479 'abort' ,
477- ( ) => opts . root . postRun ( ) ,
480+ ( ) => {
481+ opts . root . harness . watching = false ;
482+ opts . root . postRun ( ) ;
483+ } ,
478484 { __proto__ : null , once : true , [ kResistStopPropagation ] : true } ,
479485 ) ;
480486 }
0 commit comments