Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 90a98a6

Browse filesBrowse files
MoLowRafaelGSS
authored andcommitted
test: split watch mode inspector tests to sequential
PR-URL: #44551 Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
1 parent 00185f1 commit 90a98a6
Copy full SHA for 90a98a6

File tree

Expand file treeCollapse file tree

2 files changed

+73
-65
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+73
-65
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-watch-mode.mjs‎

Copy file name to clipboardExpand all lines: test/parallel/test-watch-mode.mjs
-65Lines changed: 0 additions & 65 deletions
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()`');
@@ -236,67 +234,4 @@ describe('watch mode', { concurrency: false, timeout: 60_0000 }, () => {
236234
`Completed running ${inspect(file)}`, `Restarting ${inspect(file)}`, `Completed running ${inspect(file)}`, '',
237235
].join('\n'));
238236
});
239-
240-
describe('inspect', {
241-
skip: Boolean(process.config.variables.coverage || !process.features.inspector),
242-
}, () => {
243-
const silentLogger = { log: () => {}, error: () => {} };
244-
async function getDebuggedPid(instance, waitForLog = true) {
245-
const session = await instance.connectInspectorSession();
246-
await session.send({ method: 'Runtime.enable' });
247-
if (waitForLog) {
248-
await session.waitForConsoleOutput('log', 'safe to debug now');
249-
}
250-
const { value: innerPid } = (await session.send({
251-
'method': 'Runtime.evaluate', 'params': { 'expression': 'process.pid' }
252-
})).result;
253-
session.disconnect();
254-
return innerPid;
255-
}
256-
257-
it('should start debugger on inner process', async () => {
258-
const file = fixtures.path('watch-mode/inspect.js');
259-
const instance = new NodeInstance(['--inspect=0', '--watch'], undefined, file, silentLogger);
260-
let stderr = '';
261-
instance.on('stderr', (data) => { stderr += data; });
262-
263-
const pids = [instance.pid];
264-
pids.push(await getDebuggedPid(instance));
265-
instance.resetPort();
266-
writeFileSync(file, readFileSync(file));
267-
pids.push(await getDebuggedPid(instance));
268-
269-
await instance.kill();
270-
271-
// There should be 3 pids (one parent + 2 restarts).
272-
// Message about Debugger should only appear twice.
273-
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, 2);
274-
assert.strictEqual(new Set(pids).size, 3);
275-
});
276-
277-
it('should prevent attaching debugger with SIGUSR1 to outer process', { skip: common.isWindows }, async () => {
278-
const file = fixtures.path('watch-mode/inspect_with_signal.js');
279-
const instance = new NodeInstance(['--inspect-port=0', '--watch'], undefined, file, silentLogger);
280-
let stderr = '';
281-
instance.on('stderr', (data) => { stderr += data; });
282-
283-
const loggedPid = await new Promise((resolve) => {
284-
instance.on('stdout', (data) => {
285-
const matches = data.match(/pid is (\d+)/);
286-
if (matches) resolve(Number(matches[1]));
287-
});
288-
});
289-
290-
291-
process.kill(instance.pid, 'SIGUSR1');
292-
process.kill(loggedPid, 'SIGUSR1');
293-
const debuggedPid = await getDebuggedPid(instance, false);
294-
295-
await instance.kill();
296-
297-
// Message about Debugger should only appear once in inner process.
298-
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, 1);
299-
assert.strictEqual(loggedPid, debuggedPid);
300-
});
301-
});
302237
});
Collapse file
+73Lines changed: 73 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.