diff --git a/package.json b/package.json index 536a525..1834956 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "scripts": { "pretest": "eslint --rulesdir=tools/eslint-rules lib test", - "test": "tap \"test/**/*.test.js\"", + "test": "tap test", "posttest": "nlm verify" }, "nlm": { diff --git a/test/cli/backtrace.test.js b/test/cli/backtrace.test.js index 9cd8a82..127ea56 100644 --- a/test/cli/backtrace.test.js +++ b/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/test/cli/break.test.js b/test/cli/break.test.js index 1c662d6..59b12cd 100644 --- a/test/cli/break.test.js +++ b/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/test/cli/exceptions.test.js b/test/cli/exceptions.test.js index b66c09f..18b7f18 100644 --- a/test/cli/exceptions.test.js +++ b/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/test/cli/exec.test.js b/test/cli/exec.test.js index 5c64713..acfd6e3 100644 --- a/test/cli/exec.test.js +++ b/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/test/cli/help.test.js b/test/cli/help.test.js index 11a9358..9f0c081 100644 --- a/test/cli/help.test.js +++ b/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/test/cli/launch.test.js b/test/cli/launch.test.js index 99c6ce0..b57c08a 100644 --- a/test/cli/launch.test.js +++ b/test/cli/launch.test.js @@ -5,18 +5,14 @@ const { test } = require('tap'); const startCLI = require('./start-cli'); -test('examples/empty.js', (t) => { - const script = Path.join('examples', 'empty.js'); +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', - 'forwards child output'); }) .then(() => cli.command('["hello", "world"].join(" ")')) .then(() => { @@ -45,7 +41,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 +68,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 +84,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 +98,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/test/cli/low-level.test.js b/test/cli/low-level.test.js index b6301b2..77e3fc2 100644 --- a/test/cli/low-level.test.js +++ b/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/test/cli/preserve-breaks.test.js b/test/cli/preserve-breaks.test.js index 8de8227..94f6140 100644 --- a/test/cli/preserve-breaks.test.js +++ b/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/test/cli/profile.test.js b/test/cli/profile.test.js index 3ef1896..0f900c5 100644 --- a/test/cli/profile.test.js +++ b/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/test/cli/scripts.test.js b/test/cli/scripts.test.js index cd26411..1546b80 100644 --- a/test/cli/scripts.test.js +++ b/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/test/cli/start-cli.js b/test/cli/start-cli.js index 267aac5..56c3e25 100644 --- a/test/cli/start-cli.js +++ b/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('n') + .then(() => this.waitFor(/break in/, timeout)); + } + }); + }, + ctrlC() { return this.command('.interrupt'); }, @@ -119,9 +139,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/test/cli/use-strict.test.js b/test/cli/use-strict.test.js index 81f4d91..780802a 100644 --- a/test/cli/use-strict.test.js +++ b/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/test/cli/watchers.test.js b/test/cli/watchers.test.js index d66f008..46bcde1 100644 --- a/test/cli/watchers.test.js +++ b/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\\"")')) diff --git a/test/node-inspect.test.js b/test/node-inspect.test.js deleted file mode 100644 index 12e7313..0000000 --- a/test/node-inspect.test.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; -const tap = require('tap'); - -const nodeInspect = require('../'); - -tap.equal( - 9229, - nodeInspect.port, - 'Uses the --inspect default port');