MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-inspector-port-zero.js:9–41  ·  view source on GitHub ↗
(arg, port = '')

Source from the content-addressed store, hash-verified

7const { spawn } = require('child_process');
8
9function test(arg, port = '') {
10 const args = [arg, '-p', 'process.debugPort'];
11 const proc = spawn(process.execPath, args);
12 proc.stdout.setEncoding('utf8');
13 proc.stderr.setEncoding('utf8');
14 let stdout = '';
15 let stderr = '';
16 proc.stdout.on('data', (data) => stdout += data);
17 proc.stderr.on('data', (data) => stderr += data);
18 proc.stdout.on('close', mustCall((hadErr) => assert(!hadErr)));
19 proc.stderr.on('close', mustCall((hadErr) => assert(!hadErr)));
20 proc.stderr.on('data', mustCallAtLeast(() => {
21 if (!stderr.includes('\n')) return;
22 assert.match(stderr, /Debugger listening on (.+)/);
23 port = new URL(RegExp.$1).port;
24 assert(+port > 0);
25 }, 0));
26 if (/inspect-brk/.test(arg)) {
27 proc.stderr.on('data', () => {
28 if (stderr.includes('\n') && !proc.killed) proc.kill();
29 });
30 } else {
31 let onclose = mustCall(() => {
32 onclose = mustCall(() => assert.strictEqual(port, stdout.trim()));
33 });
34 proc.stdout.on('close', () => onclose());
35 proc.stderr.on('close', () => onclose());
36 proc.on('exit', mustCall((exitCode, signal) => assert.strictEqual(
37 exitCode,
38 0,
39 `exitCode: ${exitCode}, signal: ${signal}`)));
40 }
41}
42
43test('--inspect=0');
44test('--inspect=127.0.0.1:0');

Callers 1

Calls 11

mustCallAtLeastFunction · 0.85
includesMethod · 0.80
killMethod · 0.80
spawnFunction · 0.70
mustCallFunction · 0.70
oncloseFunction · 0.70
matchMethod · 0.65
assertFunction · 0.50
setEncodingMethod · 0.45
onMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…