@@ -30,9 +30,9 @@ function createTmpFile(content = 'console.log("running");', ext = '.js', basenam
30
30
}
31
31
32
32
async function runWriteSucceed ( {
33
- file, watchedFile, args = [ file ] , completed = 'Completed running' , restarts = 2
33
+ file, watchedFile, watchFlag = '--watch' , args = [ file ] , completed = 'Completed running' , restarts = 2 , options = { }
34
34
} ) {
35
- const child = spawn ( execPath , [ '--watch' , '--no-warnings' , ...args ] , { encoding : 'utf8' , stdio : 'pipe' } ) ;
35
+ const child = spawn ( execPath , [ watchFlag , '--no-warnings' , ...args ] , { encoding : 'utf8' , stdio : 'pipe' , ... options } ) ;
36
36
let completes = 0 ;
37
37
let cancelRestarts = ( ) => { } ;
38
38
let stderr = '' ;
@@ -88,6 +88,22 @@ async function failWriteSucceed({ file, watchedFile }) {
88
88
tmpdir . refresh ( ) ;
89
89
90
90
describe ( 'watch mode' , { concurrency : true , timeout : 60_000 } , ( ) => {
91
+ it ( 'should watch changes to a file' , async ( ) => {
92
+ const file = createTmpFile ( ) ;
93
+ const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : file , watchFlag : '--watch=true' , options : {
94
+ timeout : 10000
95
+ } } ) ;
96
+
97
+ assert . strictEqual ( stderr , '' ) ;
98
+ assert . deepStrictEqual ( stdout , [
99
+ 'running' ,
100
+ `Completed running ${ inspect ( file ) } ` ,
101
+ `Restarting ${ inspect ( file ) } ` ,
102
+ 'running' ,
103
+ `Completed running ${ inspect ( file ) } ` ,
104
+ ] ) ;
105
+ } ) ;
106
+
91
107
it ( 'should watch changes to a file - event loop ended' , async ( ) => {
92
108
const file = createTmpFile ( ) ;
93
109
const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : file } ) ;
0 commit comments