Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit e3a489f

Browse files
joshgavJan Krems
authored and
Jan Krems
committed
test: custom port
1 parent 7b31acf commit e3a489f

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

lib/_inspect.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const [ InspectClient, createRepl ] =
4242

4343
const debuglog = util.debuglog('inspect');
4444

45-
const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)-port=(\d+)$/;
45+
const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)(?:-port|-brk)?=(\d{1,5})$/;
4646
function getDefaultPort() {
4747
for (const arg of process.execArgv) {
4848
const match = arg.match(DEBUG_PORT_PATTERN);
@@ -56,8 +56,7 @@ function getDefaultPort() {
5656
function runScript(script, scriptArgs, inspectPort, childPrint) {
5757
return new Promise((resolve) => {
5858
const args = [
59-
'--inspect',
60-
`--debug-brk=${inspectPort}`,
59+
`--inspect-brk=${inspectPort}`,
6160
].concat([script], scriptArgs);
6261
const child = spawn(process.execPath, args);
6362
child.stdout.setEncoding('utf8');
@@ -68,7 +67,7 @@ function runScript(script, scriptArgs, inspectPort, childPrint) {
6867
let output = '';
6968
function waitForListenHint(text) {
7069
output += text;
71-
if (/chrome-devtools:\/\//.test(output)) {
70+
if (/^Debugger listening on/.test(output)) {
7271
child.stderr.removeListener('data', waitForListenHint);
7372
resolve(child);
7473
}
@@ -295,6 +294,7 @@ function parseArgv([target, ...args]) {
295294

296295
const hostMatch = target.match(/^([^:]+):(\d+)$/);
297296
const portMatch = target.match(/^--port=(\d+)$/);
297+
298298
if (hostMatch) {
299299
// Connecting to remote debugger
300300
// `node-inspect localhost:9229`
@@ -303,16 +303,15 @@ function parseArgv([target, ...args]) {
303303
isRemote = true;
304304
script = null;
305305
} else if (portMatch) {
306-
// Start debugger on custom port
307-
// `node debug --port=8058 app.js`
306+
// start debugee on custom port
307+
// `node inspect --port=9230 script.js`
308308
port = parseInt(portMatch[1], 10);
309309
script = args[0];
310310
scriptArgs = args.slice(1);
311311
}
312312

313313
return {
314-
host, port,
315-
isRemote, script, scriptArgs,
314+
host, port, isRemote, script, scriptArgs,
316315
};
317316
}
318317

test/cli/launch.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ const { test } = require('tap');
55

66
const startCLI = require('./start-cli');
77

8+
test('custom port', (t) => {
9+
const CUSTOM_PORT = '9230';
10+
const script = Path.join('examples', 'three-lines.js');
11+
12+
const cli = startCLI([`--port=${CUSTOM_PORT}`, script]);
13+
14+
return cli.waitForInitialBreak()
15+
.then(() => cli.waitForPrompt())
16+
.then(() => {
17+
t.match(cli.output, 'debug>', 'prints a prompt');
18+
t.match(
19+
cli.output,
20+
new RegExp(`< Debugger listening on [^\n]*${CUSTOM_PORT}`),
21+
'forwards child output');
22+
})
23+
.then(() => cli.quit())
24+
.then((code) => {
25+
t.equal(code, 0, 'exits with success');
26+
});
27+
});
28+
829
test('examples/three-lines.js', (t) => {
930
const script = Path.join('examples', 'three-lines.js');
1031
const cli = startCLI([script]);
@@ -13,6 +34,10 @@ test('examples/three-lines.js', (t) => {
1334
.then(() => cli.waitForPrompt())
1435
.then(() => {
1536
t.match(cli.output, 'debug>', 'prints a prompt');
37+
t.match(
38+
cli.output,
39+
new RegExp(`< Debugger listening on [^\n]*9229`),
40+
'forwards child output');
1641
})
1742
.then(() => cli.command('["hello", "world"].join(" ")'))
1843
.then(() => {

test/cli/start-cli.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function startCLI(args) {
102102
return this.waitFor(/break (?:on start )?in/i, timeout)
103103
.then(() => {
104104
if (/Break on start/.test(this.output)) {
105-
return this.command('n')
105+
return this.command('next', false)
106106
.then(() => this.waitFor(/break in/, timeout));
107107
}
108108
});
@@ -127,8 +127,10 @@ function startCLI(args) {
127127
.map((match) => +match[1]);
128128
},
129129

130-
command(input) {
131-
this.flushOutput();
130+
command(input, flush = true) {
131+
if (flush) {
132+
this.flushOutput();
133+
}
132134
child.stdin.write(input);
133135
child.stdin.write('\n');
134136
return this.waitForPrompt();

0 commit comments

Comments
 (0)