@@ -94,4 +94,31 @@ describe('watch mode - watch flags', { concurrency: !process.env.TEST_PARALLEL,
9494 `Completed running ${ inspect ( file ) } . Waiting for file changes before restarting...` ,
9595 ] ) ;
9696 } ) ;
97+
98+ it ( 'exposes watch flags through process.execArgv inside the watched script' , async ( ) => {
99+ const projectDir = tmpdir . resolve ( 'project-watch-exec-argv' ) ;
100+ mkdirSync ( projectDir ) ;
101+
102+ const file = createTmpFile ( `
103+ console.log(JSON.stringify(process.execArgv));
104+ ` , '.js' , projectDir ) ;
105+ const watchPath = path . join ( projectDir , 'template.html' ) ;
106+ writeFileSync ( watchPath , '' ) ;
107+
108+ async function assertExecArgv ( args , expected ) {
109+ const { stdout, stderr } = await runNode ( {
110+ args, options : { cwd : projectDir }
111+ } ) ;
112+
113+ assert . strictEqual ( stderr , '' ) ;
114+
115+ const execArgvLine = stdout [ 0 ] ;
116+ assert . deepStrictEqual ( JSON . parse ( execArgvLine ) , expected ) ;
117+ assert . match ( stdout . at ( - 1 ) , / ^ C o m p l e t e d r u n n i n g / ) ;
118+ }
119+
120+ await assertExecArgv ( [ '--watch' , file ] , [ '--watch' ] ) ;
121+ await assertExecArgv ( [ '--watch-path=template.html' , file ] , [ '--watch-path=template.html' ] ) ;
122+ await assertExecArgv ( [ '--watch-path' , 'template.html' , file ] , [ '--watch-path' , 'template.html' ] ) ;
123+ } ) ;
97124} ) ;
0 commit comments