@@ -3,6 +3,7 @@ import * as fixtures from '../common/fixtures.mjs';
33import assert from 'node:assert' ;
44import { describe , it } from 'node:test' ;
55import { writeFileSync , readFileSync } from 'node:fs' ;
6+ import { setTimeout } from 'node:timers/promises' ;
67import { NodeInstance } from '../common/inspector-helper.js' ;
78
89
@@ -11,6 +12,12 @@ if (common.isIBMi)
1112
1213common . skipIfInspectorDisabled ( ) ;
1314
15+ function restart ( file ) {
16+ writeFileSync ( file , readFileSync ( file ) ) ;
17+ const interval = setInterval ( ( ) => writeFileSync ( file , readFileSync ( file ) ) , 500 ) ;
18+ return ( ) => clearInterval ( interval ) ;
19+ }
20+
1421describe ( 'watch mode - inspect' , ( ) => {
1522 async function getDebuggedPid ( instance , waitForLog = true ) {
1623 const session = await instance . connectInspectorSession ( ) ;
@@ -29,20 +36,25 @@ describe('watch mode - inspect', () => {
2936 const file = fixtures . path ( 'watch-mode/inspect.js' ) ;
3037 const instance = new NodeInstance ( [ '--inspect=0' , '--watch' ] , undefined , file ) ;
3138 let stderr = '' ;
39+ const stdout = [ ] ;
3240 instance . on ( 'stderr' , ( data ) => { stderr += data ; } ) ;
41+ instance . on ( 'stdout' , ( data ) => { stdout . push ( data ) ; } ) ;
3342
3443 const pids = [ instance . pid ] ;
3544 pids . push ( await getDebuggedPid ( instance ) ) ;
3645 instance . resetPort ( ) ;
37- writeFileSync ( file , readFileSync ( file ) ) ;
46+ const stopRestarting = restart ( file ) ;
3847 pids . push ( await getDebuggedPid ( instance ) ) ;
48+ stopRestarting ( ) ;
3949
50+ await setTimeout ( common . platformTimeout ( 500 ) ) ;
4051 await instance . kill ( ) ;
4152
42- // There should be 3 pids (one parent + 2 restarts).
43- // Message about Debugger should only appear twice.
44- assert . strictEqual ( stderr . match ( / D e b u g g e r l i s t e n i n g o n w s : \/ \/ / g) . length , 2 ) ;
45- assert . strictEqual ( new Set ( pids ) . size , 3 ) ;
53+ // There should be a process per restart and one per parent process.
54+ // Message about Debugger should appear once per restart.
55+ const restarts = stdout . filter ( ( line ) => line === 'safe to debug now' ) . length ;
56+ assert . strictEqual ( stderr . match ( / D e b u g g e r l i s t e n i n g o n w s : \/ \/ / g) . length , restarts ) ;
57+ assert . strictEqual ( new Set ( pids ) . size , restarts + 1 ) ;
4658 } ) ;
4759
4860 it ( 'should prevent attaching debugger with SIGUSR1 to outer process' , { skip : common . isWindows } , async ( ) => {
0 commit comments