Skip to content
Merged
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
test: improve coverage of lib/readline.js
  • Loading branch information
pd4d10 committed May 6, 2024
commit 9b9edd6197736303f242dc7e04054ca16529327b
30 changes: 30 additions & 0 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,16 @@ for (let i = 0; i < 12; i++) {
rli.close();
}

// Calling only the first question callback
{
const [rli] = getInterface({ terminal });
rli.question('foo?', common.mustCall((answer) => {
assert.strictEqual(answer, 'bar');
}));
rli.question('hello?', common.mustNotCall());
rli.write('bar\n');
}

// Calling the question multiple times
{
const [rli] = getInterface({ terminal });
Expand Down Expand Up @@ -1329,6 +1339,26 @@ for (let i = 0; i < 12; i++) {
rli.close();
}), delay);
}

// Write correctly if paused
{
const [rli] = getInterface({ terminal });
rli.on('line', common.mustCall((line) => {
assert.strictEqual(line, 'bar');
}));
rli.pause();
rli.write('bar\n');
assert.strictEqual(rli.paused, false);
rli.close();
}

// Write undefined
{
const [rli] = getInterface({ terminal });
rli.on('line', common.mustNotCall());
rli.write();
rli.close();
}
});

// Ensure that the _wordLeft method works even for large input
Expand Down