aboutsummaryrefslogtreecommitdiff
path: root/deps/node-inspect/test/cli
diff options
context:
space:
mode:
Diffstat (limited to 'deps/node-inspect/test/cli')
-rw-r--r--deps/node-inspect/test/cli/backtrace.test.js2
-rw-r--r--deps/node-inspect/test/cli/break.test.js6
-rw-r--r--deps/node-inspect/test/cli/exceptions.test.js11
-rw-r--r--deps/node-inspect/test/cli/exec.test.js4
-rw-r--r--deps/node-inspect/test/cli/help.test.js2
-rw-r--r--deps/node-inspect/test/cli/launch.test.js34
-rw-r--r--deps/node-inspect/test/cli/low-level.test.js11
-rw-r--r--deps/node-inspect/test/cli/pid.test.js52
-rw-r--r--deps/node-inspect/test/cli/preserve-breaks.test.js5
-rw-r--r--deps/node-inspect/test/cli/profile.test.js2
-rw-r--r--deps/node-inspect/test/cli/scripts.test.js8
-rw-r--r--deps/node-inspect/test/cli/start-cli.js30
-rw-r--r--deps/node-inspect/test/cli/use-strict.test.js2
-rw-r--r--deps/node-inspect/test/cli/watchers.test.js2
14 files changed, 137 insertions, 34 deletions
diff --git a/deps/node-inspect/test/cli/backtrace.test.js b/deps/node-inspect/test/cli/backtrace.test.js
index 9cd8a82a33..127ea56bf8 100644
--- a/deps/node-inspect/test/cli/backtrace.test.js
+++ b/deps/node-inspect/test/cli/backtrace.test.js
@@ -14,7 +14,7 @@ test('display and navigate backtrace', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.stepCommand('c'))
.then(() => cli.command('bt'))
diff --git a/deps/node-inspect/test/cli/break.test.js b/deps/node-inspect/test/cli/break.test.js
index 1c662d63fc..59b12cde38 100644
--- a/deps/node-inspect/test/cli/break.test.js
+++ b/deps/node-inspect/test/cli/break.test.js
@@ -14,7 +14,7 @@ test('stepping through breakpoints', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
@@ -132,7 +132,7 @@ test('sb before loading file', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('sb("other.js", 3)'))
.then(() => {
@@ -161,7 +161,7 @@ test('clearBreakpoint', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('sb("break.js", 3)'))
.then(() => cli.command('sb("break.js", 9)'))
diff --git a/deps/node-inspect/test/cli/exceptions.test.js b/deps/node-inspect/test/cli/exceptions.test.js
index b66c09fc50..18b7f1855e 100644
--- a/deps/node-inspect/test/cli/exceptions.test.js
+++ b/deps/node-inspect/test/cli/exceptions.test.js
@@ -14,17 +14,19 @@ test('break on (uncaught) exceptions', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
// making sure it will die by default:
.then(() => cli.command('c'))
- .then(() => cli.waitFor(/disconnect/))
+ // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore
+ .then(() => cli.waitFor(/disconnect|FATAL ERROR/))
// Next run: With `breakOnException` it pauses in both places
.then(() => cli.stepCommand('r'))
+ .then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
@@ -41,6 +43,7 @@ test('break on (uncaught) exceptions', (t) => {
// Next run: With `breakOnUncaught` it only pauses on the 2nd exception
.then(() => cli.command('breakOnUncaught'))
.then(() => cli.stepCommand('r')) // also, the setting survives the restart
+ .then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
@@ -52,11 +55,13 @@ test('break on (uncaught) exceptions', (t) => {
// Next run: Back to the initial state! It should die again.
.then(() => cli.command('breakOnNone'))
.then(() => cli.stepCommand('r'))
+ .then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
.then(() => cli.command('c'))
- .then(() => cli.waitFor(/disconnect/))
+ // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore
+ .then(() => cli.waitFor(/disconnect|FATAL ERROR/))
.then(() => cli.quit())
.then(null, onFatal);
diff --git a/deps/node-inspect/test/cli/exec.test.js b/deps/node-inspect/test/cli/exec.test.js
index 5c647134d7..acfd6e34ab 100644
--- a/deps/node-inspect/test/cli/exec.test.js
+++ b/deps/node-inspect/test/cli/exec.test.js
@@ -11,7 +11,7 @@ test('examples/alive.js', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('exec [typeof heartbeat, typeof process.exit]'))
.then(() => {
@@ -60,7 +60,7 @@ test('exec .scope', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.stepCommand('c'))
.then(() => cli.command('exec .scope'))
diff --git a/deps/node-inspect/test/cli/help.test.js b/deps/node-inspect/test/cli/help.test.js
index 11a9358834..9f0c081bde 100644
--- a/deps/node-inspect/test/cli/help.test.js
+++ b/deps/node-inspect/test/cli/help.test.js
@@ -11,7 +11,7 @@ test('examples/empty.js', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('help'))
.then(() => {
diff --git a/deps/node-inspect/test/cli/launch.test.js b/deps/node-inspect/test/cli/launch.test.js
index 99c6ce0aa2..f7efc6eb3f 100644
--- a/deps/node-inspect/test/cli/launch.test.js
+++ b/deps/node-inspect/test/cli/launch.test.js
@@ -5,17 +5,38 @@ const { test } = require('tap');
const startCLI = require('./start-cli');
-test('examples/empty.js', (t) => {
- const script = Path.join('examples', 'empty.js');
+test('custom port', (t) => {
+ const CUSTOM_PORT = '9230';
+ const script = Path.join('examples', 'three-lines.js');
+
+ const cli = startCLI([`--port=${CUSTOM_PORT}`, script]);
+
+ return cli.waitForInitialBreak()
+ .then(() => cli.waitForPrompt())
+ .then(() => {
+ t.match(cli.output, 'debug>', 'prints a prompt');
+ t.match(
+ cli.output,
+ new RegExp(`< Debugger listening on [^\n]*${CUSTOM_PORT}`),
+ 'forwards child output');
+ })
+ .then(() => cli.quit())
+ .then((code) => {
+ t.equal(code, 0, 'exits with success');
+ });
+});
+
+test('examples/three-lines.js', (t) => {
+ const script = Path.join('examples', 'three-lines.js');
const cli = startCLI([script]);
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(cli.output, 'debug>', 'prints a prompt');
t.match(
cli.output,
- '< Debugger listening on port 9229',
+ /< Debugger listening on [^\n]*9229/,
'forwards child output');
})
.then(() => cli.command('["hello", "world"].join(" ")'))
@@ -45,7 +66,7 @@ test('run after quit / restart', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.stepCommand('n'))
.then(() => {
@@ -72,6 +93,7 @@ test('run after quit / restart', (t) => {
t.match(cli.output, 'Use `run` to start the app again');
})
.then(() => cli.stepCommand('run'))
+ .then(() => cli.waitForInitialBreak())
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
@@ -87,6 +109,7 @@ test('run after quit / restart', (t) => {
'steps to the 2nd line');
})
.then(() => cli.stepCommand('restart'))
+ .then(() => cli.waitForInitialBreak())
.then(() => {
t.match(
cli.output,
@@ -100,6 +123,7 @@ test('run after quit / restart', (t) => {
t.match(cli.output, 'Use `run` to start the app again');
})
.then(() => cli.stepCommand('run'))
+ .then(() => cli.waitForInitialBreak())
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
diff --git a/deps/node-inspect/test/cli/low-level.test.js b/deps/node-inspect/test/cli/low-level.test.js
index b6301b2f23..77e3fc2bcf 100644
--- a/deps/node-inspect/test/cli/low-level.test.js
+++ b/deps/node-inspect/test/cli/low-level.test.js
@@ -4,15 +4,15 @@ const { test } = require('tap');
const startCLI = require('./start-cli');
test('Debugger agent direct access', (t) => {
- const cli = startCLI(['examples/empty.js']);
- const scriptPattern = /^\* (\d+): examples(?:\/|\\)empty.js/;
+ const cli = startCLI(['examples/three-lines.js']);
+ const scriptPattern = /^\* (\d+): examples(?:\/|\\)three-lines.js/;
function onFatal(error) {
cli.quit();
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('scripts'))
.then(() => {
@@ -24,7 +24,10 @@ test('Debugger agent direct access', (t) => {
.then(() => {
t.match(
cli.output,
- /scriptSource: '\(function \([^)]+\) \{ \\n}\);'/);
+ /scriptSource: '\(function \(/);
+ t.match(
+ cli.output,
+ /let x = 1;/);
})
.then(() => cli.quit())
.then(null, onFatal);
diff --git a/deps/node-inspect/test/cli/pid.test.js b/deps/node-inspect/test/cli/pid.test.js
new file mode 100644
index 0000000000..15d7fdeaa5
--- /dev/null
+++ b/deps/node-inspect/test/cli/pid.test.js
@@ -0,0 +1,52 @@
+'use strict';
+const { spawn } = require('child_process');
+const Path = require('path');
+
+const { test } = require('tap');
+
+const startCLI = require('./start-cli');
+
+function launchTarget(...args) {
+ const childProc = spawn(process.execPath, args);
+ return Promise.resolve(childProc);
+}
+
+// process.debugPort is our proxy for "the version of node used to run this
+// test suite doesn't support SIGUSR1 for enabling --inspect for a process".
+const defaultsToOldProtocol = process.debugPort === 5858;
+
+test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => {
+ const script = Path.join('examples', 'alive.js');
+ let cli = null;
+ let target = null;
+
+ function cleanup(error) {
+ if (cli) {
+ cli.quit();
+ cli = null;
+ }
+ if (target) {
+ target.kill();
+ target = null;
+ }
+ if (error) throw error;
+ }
+
+ return launchTarget(script)
+ .then((childProc) => {
+ target = childProc;
+ cli = startCLI(['-p', `${target.pid}`]);
+ return cli.waitForPrompt();
+ })
+ .then(() => cli.command('sb("alive.js", 3)'))
+ .then(() => cli.waitFor(/break/))
+ .then(() => cli.waitForPrompt())
+ .then(() => {
+ t.match(
+ cli.output,
+ '> 3 ++x;',
+ 'marks the 3rd line');
+ })
+ .then(() => cleanup())
+ .then(null, cleanup);
+});
diff --git a/deps/node-inspect/test/cli/preserve-breaks.test.js b/deps/node-inspect/test/cli/preserve-breaks.test.js
index 8de8227343..94f61408d9 100644
--- a/deps/node-inspect/test/cli/preserve-breaks.test.js
+++ b/deps/node-inspect/test/cli/preserve-breaks.test.js
@@ -14,7 +14,7 @@ test('run after quit / restart', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('breakpoints'))
.then(() => {
@@ -33,8 +33,7 @@ test('run after quit / restart', (t) => {
t.match(cli.output, `break in ${script}:3`);
})
.then(() => cli.command('restart'))
- .then(() => cli.waitFor([/break in examples/, /breakpoints restored/]))
- .then(() => cli.waitForPrompt())
+ .then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
diff --git a/deps/node-inspect/test/cli/profile.test.js b/deps/node-inspect/test/cli/profile.test.js
index 3ef1896200..0f900c5a2b 100644
--- a/deps/node-inspect/test/cli/profile.test.js
+++ b/deps/node-inspect/test/cli/profile.test.js
@@ -15,7 +15,7 @@ test('profiles', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('exec console.profile()'))
.then(() => {
diff --git a/deps/node-inspect/test/cli/scripts.test.js b/deps/node-inspect/test/cli/scripts.test.js
index cd26411790..1546b8045b 100644
--- a/deps/node-inspect/test/cli/scripts.test.js
+++ b/deps/node-inspect/test/cli/scripts.test.js
@@ -6,7 +6,7 @@ const { test } = require('tap');
const startCLI = require('./start-cli');
test('list scripts', (t) => {
- const script = Path.join('examples', 'empty.js');
+ const script = Path.join('examples', 'three-lines.js');
const cli = startCLI([script]);
function onFatal(error) {
@@ -14,13 +14,13 @@ test('list scripts', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('scripts'))
.then(() => {
t.match(
cli.output,
- /^\* \d+: examples(?:\/|\\)empty\.js/,
+ /^\* \d+: examples(?:\/|\\)three-lines\.js/,
'lists the user script');
t.notMatch(
cli.output,
@@ -31,7 +31,7 @@ test('list scripts', (t) => {
.then(() => {
t.match(
cli.output,
- /\* \d+: examples(?:\/|\\)empty\.js/,
+ /\* \d+: examples(?:\/|\\)three-lines\.js/,
'lists the user script');
t.match(
cli.output,
diff --git a/deps/node-inspect/test/cli/start-cli.js b/deps/node-inspect/test/cli/start-cli.js
index 267aac57f4..ae904308e0 100644
--- a/deps/node-inspect/test/cli/start-cli.js
+++ b/deps/node-inspect/test/cli/start-cli.js
@@ -1,11 +1,21 @@
'use strict';
const spawn = require('child_process').spawn;
+// This allows us to keep the helper inside of `test/` without tap warning
+// about "pending" test files.
+const tap = require('tap');
+tap.test('startCLI', (t) => t.end());
+
const CLI =
process.env.USE_EMBEDDED_NODE_INSPECT === '1' ?
'inspect' :
require.resolve('../../cli.js');
+const BREAK_MESSAGE = new RegExp('(?:' + [
+ 'assert', 'break', 'break on start', 'debugCommand',
+ 'exception', 'other', 'promiseRejection',
+].join('|') + ') in', 'i');
+
function startCLI(args) {
const child = spawn(process.execPath, [CLI, ...args]);
let isFirstStdoutChunk = true;
@@ -88,6 +98,16 @@ function startCLI(args) {
return this.waitFor(/>\s+$/, timeout);
},
+ waitForInitialBreak(timeout = 2000) {
+ return this.waitFor(/break (?:on start )?in/i, timeout)
+ .then(() => {
+ if (/Break on start/.test(this.output)) {
+ return this.command('next', false)
+ .then(() => this.waitFor(/break in/, timeout));
+ }
+ });
+ },
+
ctrlC() {
return this.command('.interrupt');
},
@@ -107,8 +127,10 @@ function startCLI(args) {
.map((match) => +match[1]);
},
- command(input) {
- this.flushOutput();
+ command(input, flush = true) {
+ if (flush) {
+ this.flushOutput();
+ }
child.stdin.write(input);
child.stdin.write('\n');
return this.waitForPrompt();
@@ -119,9 +141,7 @@ function startCLI(args) {
child.stdin.write(input);
child.stdin.write('\n');
return this
- .waitFor(
- /(?:assert|break|debugCommand|exception|other|promiseRejection) in/
- )
+ .waitFor(BREAK_MESSAGE)
.then(() => this.waitForPrompt());
},
diff --git a/deps/node-inspect/test/cli/use-strict.test.js b/deps/node-inspect/test/cli/use-strict.test.js
index 81f4d91a6a..780802a5a6 100644
--- a/deps/node-inspect/test/cli/use-strict.test.js
+++ b/deps/node-inspect/test/cli/use-strict.test.js
@@ -14,7 +14,7 @@ test('for whiles that starts with strict directive', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
diff --git a/deps/node-inspect/test/cli/watchers.test.js b/deps/node-inspect/test/cli/watchers.test.js
index d66f00814c..46bcde19a2 100644
--- a/deps/node-inspect/test/cli/watchers.test.js
+++ b/deps/node-inspect/test/cli/watchers.test.js
@@ -11,7 +11,7 @@ test('stepping through breakpoints', (t) => {
throw error;
}
- return cli.waitFor(/break/)
+ return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('watch("x")'))
.then(() => cli.command('watch("\\"Hello\\"")'))