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: stricten readline keypress failure test condition #31300

Closed
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
13 changes: 9 additions & 4 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,20 @@ function isWarned(emitter) {
{ input: fi, output: fi, terminal: true }
);
const keys = [];
const err = new Error('bad thing happened');
fi.on('keypress', function(key) {
keys.push(key);
if (key === 'X') {
throw new Error('bad thing happened');
throw err;
}
});
try {
fi.emit('data', 'fooX');
} catch { }
assert.throws(
() => fi.emit('data', 'fooX'),
(e) => {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a validation function, can't this just be err?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would also work but I wanted to have a reference equality check. That would not be checked if I'd use err directly.

assert.strictEqual(e, err);
return true;
}
);
fi.emit('data', 'bar');
assert.strictEqual(keys.join(''), 'fooXbar');
rli.close();
Expand Down