Skip to content

Commit 2881cb9

Browse files
committed
test: improve coverage of lib/readline.js
1 parent 154fa41 commit 2881cb9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/parallel/test-readline-interface.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,16 @@ for (let i = 0; i < 12; i++) {
10101010
rli.close();
10111011
}
10121012

1013+
// Calling only the first question callback
1014+
{
1015+
const [rli] = getInterface({ terminal });
1016+
rli.question('foo?', common.mustCall((answer) => {
1017+
assert.strictEqual(answer, 'bar');
1018+
}));
1019+
rli.question('hello?', common.mustNotCall());
1020+
rli.write('bar\n');
1021+
}
1022+
10131023
// Calling the question multiple times
10141024
{
10151025
const [rli] = getInterface({ terminal });
@@ -1232,6 +1242,26 @@ for (let i = 0; i < 12; i++) {
12321242
rli.close();
12331243
}), delay);
12341244
}
1245+
1246+
// Write correctly if paused
1247+
{
1248+
const [rli] = getInterface({ terminal });
1249+
rli.on('line', common.mustCall((line) => {
1250+
assert.strictEqual(line, 'bar');
1251+
}));
1252+
rli.pause();
1253+
rli.write('bar\n');
1254+
assert.strictEqual(rli.paused, false);
1255+
rli.close();
1256+
}
1257+
1258+
// Write undefined
1259+
{
1260+
const [rli] = getInterface({ terminal });
1261+
rli.on('line', common.mustNotCall());
1262+
rli.write();
1263+
rli.close();
1264+
}
12351265
});
12361266

12371267
// Ensure that the _wordLeft method works even for large input

0 commit comments

Comments
 (0)