@@ -12,26 +12,34 @@ if (common.isIBMi)
1212
1313common . skipIfInspectorDisabled ( ) ;
1414
15+ let gettingDebuggedPid = false ;
16+
17+ async function getDebuggedPid ( instance , waitForLog = true ) {
18+ gettingDebuggedPid = true ;
19+ const session = await instance . connectInspectorSession ( ) ;
20+ await session . send ( { method : 'Runtime.enable' } ) ;
21+ if ( waitForLog ) {
22+ await session . waitForConsoleOutput ( 'log' , 'safe to debug now' ) ;
23+ }
24+ const { value : innerPid } = ( await session . send ( {
25+ 'method' : 'Runtime.evaluate' , 'params' : { 'expression' : 'process.pid' }
26+ } ) ) . result ;
27+ session . disconnect ( ) ;
28+ gettingDebuggedPid = false ;
29+ return innerPid ;
30+ }
31+
1532function restart ( file ) {
1633 writeFileSync ( file , readFileSync ( file ) ) ;
17- const interval = setInterval ( ( ) => writeFileSync ( file , readFileSync ( file ) ) , 500 ) ;
34+ const interval = setInterval ( ( ) => {
35+ if ( ! gettingDebuggedPid ) {
36+ writeFileSync ( file , readFileSync ( file ) ) ;
37+ }
38+ } , common . platformTimeout ( 500 ) ) ;
1839 return ( ) => clearInterval ( interval ) ;
1940}
2041
2142describe ( 'watch mode - inspect' , ( ) => {
22- async function getDebuggedPid ( instance , waitForLog = true ) {
23- const session = await instance . connectInspectorSession ( ) ;
24- await session . send ( { method : 'Runtime.enable' } ) ;
25- if ( waitForLog ) {
26- await session . waitForConsoleOutput ( 'log' , 'safe to debug now' ) ;
27- }
28- const { value : innerPid } = ( await session . send ( {
29- 'method' : 'Runtime.evaluate' , 'params' : { 'expression' : 'process.pid' }
30- } ) ) . result ;
31- session . disconnect ( ) ;
32- return innerPid ;
33- }
34-
3543 it ( 'should start debugger on inner process' , async ( ) => {
3644 const file = fixtures . path ( 'watch-mode/inspect.js' ) ;
3745 const instance = new NodeInstance ( [ '--inspect=0' , '--watch' ] , undefined , file ) ;
0 commit comments