2017-05-27 11:31:00 +00:00
|
|
|
'use strict';
|
2017-05-31 05:23:40 +00:00
|
|
|
const { mustCall, skipIfInspectorDisabled } = require('../common');
|
2017-06-03 02:30:25 +00:00
|
|
|
|
2017-05-31 05:23:40 +00:00
|
|
|
skipIfInspectorDisabled();
|
2017-06-03 02:30:25 +00:00
|
|
|
|
2017-05-27 11:31:00 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const { spawn } = require('child_process');
|
|
|
|
|
2017-06-06 18:21:22 +00:00
|
|
|
function test(arg, port = '') {
|
2017-05-27 11:31:00 +00:00
|
|
|
const args = [arg, '-p', 'process.debugPort'];
|
|
|
|
const proc = spawn(process.execPath, args);
|
|
|
|
proc.stdout.setEncoding('utf8');
|
|
|
|
proc.stderr.setEncoding('utf8');
|
|
|
|
let stdout = '';
|
|
|
|
let stderr = '';
|
|
|
|
proc.stdout.on('data', (data) => stdout += data);
|
|
|
|
proc.stderr.on('data', (data) => stderr += data);
|
2018-01-23 13:07:18 +00:00
|
|
|
proc.stdout.on('close', (hadErr) => assert(!hadErr));
|
|
|
|
proc.stderr.on('close', (hadErr) => assert(!hadErr));
|
2017-05-27 11:31:00 +00:00
|
|
|
proc.stderr.on('data', () => {
|
|
|
|
if (!stderr.includes('\n')) return;
|
2021-08-29 08:14:22 +00:00
|
|
|
assert.match(stderr, /Debugger listening on (.+)/);
|
2017-05-27 11:31:00 +00:00
|
|
|
port = new URL(RegExp.$1).port;
|
|
|
|
assert(+port > 0);
|
|
|
|
});
|
|
|
|
if (/inspect-brk/.test(arg)) {
|
|
|
|
proc.stderr.on('data', () => {
|
|
|
|
if (stderr.includes('\n') && !proc.killed) proc.kill();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
let onclose = () => {
|
|
|
|
onclose = () => assert.strictEqual(port, stdout.trim());
|
|
|
|
};
|
|
|
|
proc.stdout.on('close', mustCall(() => onclose()));
|
|
|
|
proc.stderr.on('close', mustCall(() => onclose()));
|
2017-11-02 10:56:27 +00:00
|
|
|
proc.on('exit', mustCall((exitCode, signal) => assert.strictEqual(
|
|
|
|
exitCode,
|
|
|
|
0,
|
|
|
|
`exitCode: ${exitCode}, signal: ${signal}`)));
|
2017-05-27 11:31:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test('--inspect=0');
|
|
|
|
test('--inspect=127.0.0.1:0');
|
|
|
|
test('--inspect=localhost:0');
|
|
|
|
|
|
|
|
test('--inspect-brk=0');
|
|
|
|
test('--inspect-brk=127.0.0.1:0');
|
|
|
|
test('--inspect-brk=localhost:0');
|
2017-06-06 18:21:22 +00:00
|
|
|
|
|
|
|
// In these cases, the inspector doesn't listen, so an ephemeral port is not
|
|
|
|
// allocated and the expected value of `process.debugPort` is `0`.
|
|
|
|
test('--inspect-port=0', '0');
|
|
|
|
test('--inspect-port=127.0.0.1:0', '0');
|
|
|
|
test('--inspect-port=localhost:0', '0');
|