Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-repl-sigint #11309

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: \n is missing in the expected string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it out because a literal \n in the message output would probably be unhelpful and an escaped \n might be taken to mean that an escaped \n is what is expected.

I'm OK with any of the three possibilities (leave it out, put it in literally, put it in escaped). I chose this one (leave it out) for simplicity. If you feel that it should be there, let me know if you want it escaped or not. And if, like me, you don't feel particularly strongly, then I'll probably just leave it as it is. ¯\(ツ)

);
assert.ok(
stdout.includes('42042\n'),
`Expected stdout to contain "42042", got ${stdout}`
);
});