Skip to content

Commit

Permalink
test: refactor test-repl-sigint
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: #11309
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Mar 9, 2017
1 parent b7cbb80 commit 1adfca4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test/parallel/test-repl-sigint.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.\n'), -1);
assert.notStrictEqual(stdout.indexOf('42042\n'), -1);
assert.ok(
stdout.includes('Script execution interrupted.\n'),
`Expected stdout to contain "Script execution interrupted.", got ${stdout}`
);
assert.ok(
stdout.includes('42042\n'),
`Expected stdout to contain "42042", got ${stdout}`
);
});

0 comments on commit 1adfca4

Please sign in to comment.