@@ -39,7 +39,9 @@ async function runWriteSucceed({
3939 options = { } ,
4040 shouldFail = false
4141} ) {
42- const child = spawn ( execPath , [ watchFlag , '--no-warnings' , ...args ] , { encoding : 'utf8' , stdio : 'pipe' , ...options } ) ;
42+ args . unshift ( '--no-warnings' ) ;
43+ if ( watchFlag !== null ) args . unshift ( watchFlag ) ;
44+ const child = spawn ( execPath , args , { encoding : 'utf8' , stdio : 'pipe' , ...options } ) ;
4345 let completes = 0 ;
4446 let cancelRestarts = ( ) => { } ;
4547 let stderr = '' ;
@@ -531,4 +533,45 @@ console.log(values.random);
531533 `Completed running ${ inspect ( file ) } ` ,
532534 ] ) ;
533535 } ) ;
536+
537+ it ( 'should run when `--watch --inspect`' , async ( ) => {
538+ const file = createTmpFile ( ) ;
539+ const args = [ '--watch' , '--inspect' , file ] ;
540+ const { stdout, stderr } = await runWriteSucceed ( { file, watchedFile : file , watchFlag : null , args } ) ;
541+
542+ assert . match ( stderr , / l i s t e n i n g o n w s : \/ \/ / ) ;
543+ assert . deepStrictEqual ( stdout , [
544+ 'running' ,
545+ `Completed running ${ inspect ( file ) } ` ,
546+ `Restarting ${ inspect ( file ) } ` ,
547+ 'running' ,
548+ `Completed running ${ inspect ( file ) } ` ,
549+ ] ) ;
550+ } ) ;
551+
552+ it ( 'should run when `--watch -r ./foo.js`' , async ( ) => {
553+ const projectDir = tmpdir . resolve ( 'project7' ) ;
554+ mkdirSync ( projectDir ) ;
555+
556+ const dir = path . join ( projectDir , 'watched-dir' ) ;
557+ mkdirSync ( dir ) ;
558+ writeFileSync ( path . join ( projectDir , 'some.js' ) , "console.log('hello')" ) ;
559+
560+ const file = createTmpFile ( "console.log('running');" , '.js' , projectDir ) ;
561+ const args = [ '--watch' , '-r' , './some.js' , file ] ;
562+ const { stdout, stderr } = await runWriteSucceed ( {
563+ file, watchedFile : file , watchFlag : null , args, options : { cwd : projectDir }
564+ } ) ;
565+
566+ assert . strictEqual ( stderr , '' ) ;
567+ assert . deepStrictEqual ( stdout , [
568+ 'hello' ,
569+ 'running' ,
570+ `Completed running ${ inspect ( file ) } ` ,
571+ `Restarting ${ inspect ( file ) } ` ,
572+ 'hello' ,
573+ 'running' ,
574+ `Completed running ${ inspect ( file ) } ` ,
575+ ] ) ;
576+ } ) ;
534577} ) ;
0 commit comments