@@ -67,6 +67,26 @@ describe("--watch", function () {
6767 } ) ;
6868 } ) ;
6969
70+ it ( "keeps watching when the last test file is removed" , function ( ) {
71+ const testFile = path . join ( tempDir , "test/a.js" ) ;
72+ copyFixture ( DEFAULT_FIXTURE , testFile ) ;
73+
74+ return runMochaWatchJSONAsync (
75+ [ "test/**/*.js" , "--watch-files" , "test/**/*.js" ] ,
76+ { cwd : tempDir , expectedRuns : 3 } ,
77+ async ( _mochaProcess , { waitForRuns } ) => {
78+ fs . rmSync ( testFile , { force : true } ) ;
79+ await waitForRuns ( 2 ) ;
80+ copyFixture ( "passing.fixture.cjs" , path . join ( tempDir , "test/b.js" ) ) ;
81+ } ,
82+ ) . then ( ( results ) => {
83+ expect ( results , "to have length" , 3 ) ;
84+ expect ( results [ 0 ] . passes , "to have length" , 1 ) ;
85+ expect ( results [ 1 ] . passes , "to have length" , 0 ) ;
86+ expect ( results [ 2 ] . passes , "to have length" , 2 ) ;
87+ } ) ;
88+ } ) ;
89+
7090 describe ( "when in parallel mode" , function ( ) {
7191 it ( "reruns test when watched test file is touched" , function ( ) {
7292 const testFile = path . join ( tempDir , "test.js" ) ;
@@ -78,6 +98,26 @@ describe("--watch", function () {
7898 expect ( results , "to have length" , 2 ) ;
7999 } ) ;
80100 } ) ;
101+
102+ it ( "keeps watching when the last test file is removed" , function ( ) {
103+ const testFile = path . join ( tempDir , "test/a.js" ) ;
104+ copyFixture ( DEFAULT_FIXTURE , testFile ) ;
105+
106+ return runMochaWatchJSONAsync (
107+ [ "--parallel" , "test/**/*.js" , "--watch-files" , "test/**/*.js" ] ,
108+ { cwd : tempDir , expectedRuns : 3 } ,
109+ async ( _mochaProcess , { waitForRuns } ) => {
110+ fs . rmSync ( testFile , { force : true } ) ;
111+ await waitForRuns ( 2 ) ;
112+ copyFixture ( "passing.fixture.cjs" , path . join ( tempDir , "test/b.js" ) ) ;
113+ } ,
114+ ) . then ( ( results ) => {
115+ expect ( results , "to have length" , 3 ) ;
116+ expect ( results [ 0 ] . passes , "to have length" , 1 ) ;
117+ expect ( results [ 1 ] . passes , "to have length" , 0 ) ;
118+ expect ( results [ 2 ] . passes , "to have length" , 2 ) ;
119+ } ) ;
120+ } ) ;
81121 } ) ;
82122
83123 it ( "reruns test when file matching --watch-files changes" , function ( ) {
0 commit comments