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

Commit

Permalink
Merge pull request #36 from nodejs/jk-embedded-failures
Browse files Browse the repository at this point in the history
Update test suite to pass on latest nightly
  • Loading branch information
jkrems authored Apr 3, 2017
2 parents 4e7add6 + 6ce8c16 commit 7b31acf
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 45 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/backtrace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
6 changes: 3 additions & 3 deletions test/cli/break.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('stepping through breakpoints', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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)'))
Expand Down
11 changes: 8 additions & 3 deletions test/cli/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
})
Expand All @@ -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`);
})
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/cli/exec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion test/cli/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
15 changes: 7 additions & 8 deletions test/cli/launch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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(
Expand Down
11 changes: 7 additions & 4 deletions test/cli/low-level.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions test/cli/preserve-breaks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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`);
})
Expand Down
2 changes: 1 addition & 1 deletion test/cli/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
8 changes: 4 additions & 4 deletions test/cli/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ 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) {
cli.quit();
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,
Expand All @@ -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,
Expand Down
24 changes: 21 additions & 3 deletions test/cli/start-cli.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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');
},
Expand Down Expand Up @@ -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());
},

Expand Down
2 changes: 1 addition & 1 deletion test/cli/use-strict.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/cli/watchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\\"")'))
Expand Down
9 changes: 0 additions & 9 deletions test/node-inspect.test.js

This file was deleted.

0 comments on commit 7b31acf

Please sign in to comment.