@@ -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 : {
@@ -418,6 +419,7 @@ function runTestFile(path, filesWatcher, opts) {
418419 filesWatcher . runningSubtests . delete ( path ) ;
419420 if ( filesWatcher . runningSubtests . size === 0 ) {
420421 opts . root . reporter [ kEmitMessage ] ( 'test:watch:drained' ) ;
422+ queueMicrotask ( ( ) => opts . root . postRun ( ) ) ;
421423 }
422424 }
423425
@@ -445,6 +447,7 @@ function watchFiles(testFiles, opts) {
445447 const runningSubtests = new SafeMap ( ) ;
446448 const watcher = new FilesWatcher ( { __proto__ : null , debounce : 200 , mode : 'filter' , signal : opts . signal } ) ;
447449 const filesWatcher = { __proto__ : null , watcher, runningProcesses, runningSubtests } ;
450+ opts . root . harness . watching = true ;
448451
449452 watcher . on ( 'changed' , ( { owners } ) => {
450453 watcher . unfilterFilesOwnedBy ( owners ) ;
@@ -471,7 +474,10 @@ function watchFiles(testFiles, opts) {
471474 kResistStopPropagation ??= require ( 'internal/event_target' ) . kResistStopPropagation ;
472475 opts . signal . addEventListener (
473476 'abort' ,
474- ( ) => opts . root . postRun ( ) ,
477+ ( ) => {
478+ opts . root . harness . watching = false ;
479+ opts . root . postRun ( ) ;
480+ } ,
475481 { __proto__ : null , once : true , [ kResistStopPropagation ] : true } ,
476482 ) ;
477483 }
0 commit comments