@@ -30,9 +30,9 @@ function createTmpFile(content = 'console.log("running");', ext = '.js', basenam
3030}
3131
3232async 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 = { }
3434} ) {
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 } ) ;
3636 let completes = 0 ;
3737 let cancelRestarts = ( ) => { } ;
3838 let stderr = '' ;
@@ -88,6 +88,22 @@ async function failWriteSucceed({ file, watchedFile }) {
8888tmpdir . refresh ( ) ;
8989
9090describe ( '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+
91107 it ( 'should watch changes to a file - event loop ended' , async ( ) => {
92108 const file = createTmpFile ( ) ;
93109 const { stderr, stdout } = await runWriteSucceed ( { file, watchedFile : file } ) ;
0 commit comments