test: support inspecting WPTs in child processes · nodejs/node@1e455a4 · GitHub
Skip to content

Commit 1e455a4

Browse files
panvaaduh95
authored andcommitted
test: support inspecting WPTs in child processes
Add WPT_INSPECT to launch one generated main-thread test with --inspect-brk on an available port. Forward debugger stderr so an inspector client can attach while the child is paused. Require an exact generated test path and reject worker variants, whose test code runs in a nested Worker. Cover backend precedence, selector errors, inspector attachment, and clean shutdown. Refs: #51854 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #65510 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1f7cab5 commit 1e455a4

4 files changed

Lines changed: 162 additions & 3 deletions

File tree

‎test/common/wpt.js‎

Lines changed: 32 additions & 2 deletions

‎test/parallel/test-common-wpt-backends.js‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const { spawnSync } = require('child_process');
1313
const { backends, WPTRunner } = require('../common/wpt');
1414

1515
const queueProbe = process.env.NODE_TEST_WPT_QUEUE_PROBE === '1';
16+
const backendProbe = process.env.NODE_TEST_WPT_BACKEND_PROBE;
1617

1718
const harnessPath = fixtures.path('wpt', 'resources', 'testharness.js');
1819
const specPath = fixtures.path('wpt-backends-spec.js');
@@ -156,7 +157,74 @@ function checkQueuedSpecsKeepRunnerAlive() {
156157
assert.strictEqual(status, 0, `Queued WPT probe failed:\n${stdout}${stderr}`);
157158
}
158159

160+
function runDefaultBackendProbe() {
161+
const runner = new WPTRunner('compression');
162+
assert.strictEqual(runner.runSpec, backends[backendProbe]);
163+
}
164+
165+
function checkBackendSelection() {
166+
const env = { ...process.env };
167+
delete env.WPT_BACKEND;
168+
delete env.WPT_INSPECT;
169+
170+
for (const [name, expected, args, overrides] of [
171+
['default', 'thread', [__filename]],
172+
['environment override', 'process', [__filename], { WPT_BACKEND: 'process' }],
173+
['inspect override', 'process', [__filename], {
174+
WPT_BACKEND: 'thread',
175+
WPT_INSPECT: '1',
176+
}],
177+
]) {
178+
const result = spawnSync(process.execPath, args, {
179+
env: {
180+
...env,
181+
...overrides,
182+
NODE_TEST_WPT_BACKEND_PROBE: expected,
183+
},
184+
encoding: 'utf8',
185+
timeout: common.platformTimeout(10_000),
186+
});
187+
const { error, status, stdout, stderr } = result;
188+
assert.ifError(error);
189+
assert.strictEqual(
190+
status,
191+
0,
192+
`${name} WPT backend probe failed:\n${stdout}${stderr}`,
193+
);
194+
}
195+
}
196+
197+
function checkInspectSelection() {
198+
const driver = path.join(__dirname, '../wpt/test-compression.js');
199+
const env = { ...process.env, WPT_INSPECT: '1' };
200+
delete env.WPT_BACKEND;
201+
202+
const runFailure = common.mustCall((args, expected) => {
203+
const result = spawnSync(process.execPath, [driver, ...args], {
204+
env,
205+
encoding: 'utf8',
206+
timeout: common.platformTimeout(10_000),
207+
});
208+
const { error, status, stdout, stderr } = result;
209+
assert.ifError(error);
210+
assert.strictEqual(status, 1, `WPT inspect probe passed:\n${stdout}${stderr}`);
211+
assert.match(stderr, expected);
212+
}, 3);
213+
214+
runFailure([], /WPT_INSPECT requires a WPT test path/);
215+
runFailure(
216+
['compression-bad-chunks.any.js'],
217+
/WPT_INSPECT requires exactly one generated WPT test path; .* matched 2:\r?\ncompression\/compression-bad-chunks\.any\.html\r?\ncompression\/compression-bad-chunks\.any\.worker\.html/,
218+
);
219+
runFailure(
220+
['compression/compression-bad-chunks.any.worker.html'],
221+
/WPT_INSPECT does not support worker tests: compression\/compression-bad-chunks\.any\.worker\.html/,
222+
);
223+
}
224+
159225
async function main() {
226+
checkBackendSelection();
227+
checkInspectSelection();
160228
checkQueuedSpecsKeepRunnerAlive();
161229

162230
const completed = await compare(false);
@@ -197,7 +265,9 @@ async function main() {
197265
assert.deepStrictEqual(workerResults, windowResults);
198266
}
199267

200-
if (queueProbe) {
268+
if (backendProbe) {
269+
runDefaultBackendProbe();
270+
} else if (queueProbe) {
201271
runQueueProbe();
202272
} else {
203273
main().then(common.mustCall());
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
common.skipIfInspectorDisabled();
5+
6+
const assert = require('assert');
7+
const path = require('path');
8+
const { NodeInstance } = require('../common/inspector-helper');
9+
10+
const driver = path.join(__dirname, '../wpt/test-compression.js');
11+
12+
async function main() {
13+
const parent = new NodeInstance([], `
14+
delete process.env.WPT_BACKEND;
15+
process.env.WPT_INSPECT = '1';
16+
process.argv[2] = 'compression/compression-bad-chunks.any.html';
17+
require(${JSON.stringify(driver)});
18+
`, '', {
19+
log() {},
20+
error() {},
21+
});
22+
const stderr = [];
23+
parent.on('stderr', (line) => stderr.push(line));
24+
25+
const session = await parent.connectInspectorSession();
26+
await session.send([
27+
{ method: 'Runtime.enable' },
28+
{ method: 'Debugger.enable' },
29+
{ method: 'Runtime.runIfWaitingForDebugger' },
30+
]);
31+
await session.waitForNotification('Debugger.paused');
32+
await session.send({ method: 'Debugger.resume' });
33+
await session.disconnect();
34+
35+
const { exitCode, signal } = await parent.expectShutdown();
36+
assert.strictEqual(signal, null);
37+
assert.strictEqual(exitCode, 0);
38+
assert.strictEqual(
39+
stderr.filter((line) => line.startsWith('Debugger listening on ')).length,
40+
1,
41+
);
42+
}
43+
44+
main().then(common.mustCall());

‎test/wpt/README.md‎

Lines changed: 15 additions & 0 deletions

0 commit comments

Comments
 (0)