Skip to content

Commit

Permalink
test: refactor test-repl-sigint-nested-eval
Browse files Browse the repository at this point in the history
* remove debugging code that prints child stdout
* indexOf() -> includes()
* improved messages on assertion failures

PR-URL: nodejs#11303
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
  • Loading branch information
Trott authored and italoacasas committed Feb 14, 2017
1 parent 1dc438f commit b140dec
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test/parallel/test-repl-sigint-nested-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ const child = spawn(process.execPath, [ '-i' ], {

let stdout = '';
child.stdout.setEncoding('utf8');
child.stdout.pipe(process.stdout);
child.stdout.on('data', function(c) {
stdout += c;
});

child.stdin.write = ((original) => {
return (chunk) => {
process.stderr.write(chunk);
return original.call(child.stdin, chunk);
};
})(child.stdin.write);

child.stdout.once('data', common.mustCall(() => {
process.on('SIGUSR2', common.mustCall(() => {
process.kill(child.pid, 'SIGINT');
Expand All @@ -45,6 +37,12 @@ child.stdout.once('data', common.mustCall(() => {

child.on('close', function(code) {
assert.strictEqual(code, 0);
assert.notStrictEqual(stdout.indexOf('Script execution interrupted.'), -1);
assert.notStrictEqual(stdout.indexOf('foobar'), -1);
assert.ok(
stdout.includes('Script execution interrupted.'),
`Expected stdout to contain "Script execution interrupted.", got ${stdout}`
);
assert.ok(
stdout.includes('foobar'),
`Expected stdout to contain "foobar", got ${stdout}`
);
});

0 comments on commit b140dec

Please sign in to comment.