@@ -3,6 +3,7 @@ import * as fixtures from '../common/fixtures.mjs';
3
3
import assert from 'node:assert' ;
4
4
import { describe , it } from 'node:test' ;
5
5
import { writeFileSync , readFileSync } from 'node:fs' ;
6
+ import { setTimeout } from 'node:timers/promises' ;
6
7
import { NodeInstance } from '../common/inspector-helper.js' ;
7
8
8
9
@@ -11,6 +12,12 @@ if (common.isIBMi)
11
12
12
13
common . skipIfInspectorDisabled ( ) ;
13
14
15
+ function restart ( file ) {
16
+ writeFileSync ( file , readFileSync ( file ) ) ;
17
+ const interval = setInterval ( ( ) => writeFileSync ( file , readFileSync ( file ) ) , 500 ) ;
18
+ return ( ) => clearInterval ( interval ) ;
19
+ }
20
+
14
21
describe ( 'watch mode - inspect' , ( ) => {
15
22
async function getDebuggedPid ( instance , waitForLog = true ) {
16
23
const session = await instance . connectInspectorSession ( ) ;
@@ -29,20 +36,25 @@ describe('watch mode - inspect', () => {
29
36
const file = fixtures . path ( 'watch-mode/inspect.js' ) ;
30
37
const instance = new NodeInstance ( [ '--inspect=0' , '--watch' ] , undefined , file ) ;
31
38
let stderr = '' ;
39
+ const stdout = [ ] ;
32
40
instance . on ( 'stderr' , ( data ) => { stderr += data ; } ) ;
41
+ instance . on ( 'stdout' , ( data ) => { stdout . push ( data ) ; } ) ;
33
42
34
43
const pids = [ instance . pid ] ;
35
44
pids . push ( await getDebuggedPid ( instance ) ) ;
36
45
instance . resetPort ( ) ;
37
- writeFileSync ( file , readFileSync ( file ) ) ;
46
+ const stopRestarting = restart ( file ) ;
38
47
pids . push ( await getDebuggedPid ( instance ) ) ;
48
+ stopRestarting ( ) ;
39
49
50
+ await setTimeout ( common . platformTimeout ( 500 ) ) ;
40
51
await instance . kill ( ) ;
41
52
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 ) ;
46
58
} ) ;
47
59
48
60
it ( 'should prevent attaching debugger with SIGUSR1 to outer process' , { skip : common . isWindows } , async ( ) => {
0 commit comments