Skip to content

Commit 97f6caf

Browse files
MoLowrichardlau
authored andcommitted
test: split watch mode inspector tests to sequential
PR-URL: #44551 Backport-PR-URL: #44976 Reviewed-By: Kohei Ueno <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Nitzan Uziely <[email protected]>
1 parent 1e0dcd1 commit 97f6caf

File tree

2 files changed

+73
-65
lines changed

2 files changed

+73
-65
lines changed

test/parallel/test-watch-mode.mjs

-65
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { writeFileSync, readFileSync } from 'node:fs';
1010
import { inspect } from 'node:util';
1111
import { once } from 'node:events';
1212
import { setTimeout } from 'node:timers/promises';
13-
import { NodeInstance } from '../common/inspector-helper.js';
14-
1513

1614
if (common.isIBMi)
1715
common.skip('IBMi does not support `fs.watch()`');
@@ -234,67 +232,4 @@ describe('watch mode', { concurrency: false, timeout: 60_0000 }, () => {
234232
`Completed running ${inspect(file)}`, `Restarting ${inspect(file)}`, `Completed running ${inspect(file)}`, '',
235233
].join('\n'));
236234
});
237-
238-
describe('inspect', {
239-
skip: Boolean(process.config.variables.coverage || !process.features.inspector),
240-
}, () => {
241-
const silentLogger = { log: () => {}, error: () => {} };
242-
async function getDebuggedPid(instance, waitForLog = true) {
243-
const session = await instance.connectInspectorSession();
244-
await session.send({ method: 'Runtime.enable' });
245-
if (waitForLog) {
246-
await session.waitForConsoleOutput('log', 'safe to debug now');
247-
}
248-
const { value: innerPid } = (await session.send({
249-
'method': 'Runtime.evaluate', 'params': { 'expression': 'process.pid' }
250-
})).result;
251-
session.disconnect();
252-
return innerPid;
253-
}
254-
255-
it('should start debugger on inner process', async () => {
256-
const file = fixtures.path('watch-mode/inspect.js');
257-
const instance = new NodeInstance(['--inspect=0', '--watch'], undefined, file, silentLogger);
258-
let stderr = '';
259-
instance.on('stderr', (data) => { stderr += data; });
260-
261-
const pids = [instance.pid];
262-
pids.push(await getDebuggedPid(instance));
263-
instance.resetPort();
264-
writeFileSync(file, readFileSync(file));
265-
pids.push(await getDebuggedPid(instance));
266-
267-
await instance.kill();
268-
269-
// There should be 3 pids (one parent + 2 restarts).
270-
// Message about Debugger should only appear twice.
271-
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, 2);
272-
assert.strictEqual(new Set(pids).size, 3);
273-
});
274-
275-
it('should prevent attaching debugger with SIGUSR1 to outer process', { skip: common.isWindows }, async () => {
276-
const file = fixtures.path('watch-mode/inspect_with_signal.js');
277-
const instance = new NodeInstance(['--inspect-port=0', '--watch'], undefined, file, silentLogger);
278-
let stderr = '';
279-
instance.on('stderr', (data) => { stderr += data; });
280-
281-
const loggedPid = await new Promise((resolve) => {
282-
instance.on('stdout', (data) => {
283-
const matches = data.match(/pid is (\d+)/);
284-
if (matches) resolve(Number(matches[1]));
285-
});
286-
});
287-
288-
289-
process.kill(instance.pid, 'SIGUSR1');
290-
process.kill(loggedPid, 'SIGUSR1');
291-
const debuggedPid = await getDebuggedPid(instance, false);
292-
293-
await instance.kill();
294-
295-
// Message about Debugger should only appear once in inner process.
296-
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, 1);
297-
assert.strictEqual(loggedPid, debuggedPid);
298-
});
299-
});
300235
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as common from '../common/index.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
3+
import assert from 'node:assert';
4+
import { describe, it } from 'node:test';
5+
import { writeFileSync, readFileSync } from 'node:fs';
6+
import { NodeInstance } from '../common/inspector-helper.js';
7+
8+
9+
if (common.isIBMi)
10+
common.skip('IBMi does not support `fs.watch()`');
11+
12+
common.skipIfInspectorDisabled();
13+
14+
describe('watch mode - inspect', () => {
15+
const silentLogger = { log: () => {}, error: () => {} };
16+
async function getDebuggedPid(instance, waitForLog = true) {
17+
const session = await instance.connectInspectorSession();
18+
await session.send({ method: 'Runtime.enable' });
19+
if (waitForLog) {
20+
await session.waitForConsoleOutput('log', 'safe to debug now');
21+
}
22+
const { value: innerPid } = (await session.send({
23+
'method': 'Runtime.evaluate', 'params': { 'expression': 'process.pid' }
24+
})).result;
25+
session.disconnect();
26+
return innerPid;
27+
}
28+
29+
it('should start debugger on inner process', async () => {
30+
const file = fixtures.path('watch-mode/inspect.js');
31+
const instance = new NodeInstance(['--inspect=0', '--watch'], undefined, file, silentLogger);
32+
let stderr = '';
33+
instance.on('stderr', (data) => { stderr += data; });
34+
35+
const pids = [instance.pid];
36+
pids.push(await getDebuggedPid(instance));
37+
instance.resetPort();
38+
writeFileSync(file, readFileSync(file));
39+
pids.push(await getDebuggedPid(instance));
40+
41+
await instance.kill();
42+
43+
// There should be 3 pids (one parent + 2 restarts).
44+
// Message about Debugger should only appear twice.
45+
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, 2);
46+
assert.strictEqual(new Set(pids).size, 3);
47+
});
48+
49+
it('should prevent attaching debugger with SIGUSR1 to outer process', { skip: common.isWindows }, async () => {
50+
const file = fixtures.path('watch-mode/inspect_with_signal.js');
51+
const instance = new NodeInstance(['--inspect-port=0', '--watch'], undefined, file, silentLogger);
52+
let stderr = '';
53+
instance.on('stderr', (data) => { stderr += data; });
54+
55+
const loggedPid = await new Promise((resolve) => {
56+
instance.on('stdout', (data) => {
57+
const matches = data.match(/pid is (\d+)/);
58+
if (matches) resolve(Number(matches[1]));
59+
});
60+
});
61+
62+
63+
process.kill(instance.pid, 'SIGUSR1');
64+
process.kill(loggedPid, 'SIGUSR1');
65+
const debuggedPid = await getDebuggedPid(instance, false);
66+
67+
await instance.kill();
68+
69+
// Message about Debugger should only appear once in inner process.
70+
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, 1);
71+
assert.strictEqual(loggedPid, debuggedPid);
72+
});
73+
});

0 commit comments

Comments
 (0)