Skip to content

Commit 0be8123

Browse files
pd4d10marco-ippolito
authored andcommittedJun 17, 2024
test: improve coverage of lib/readline.js
PR-URL: #38646 Refs: https://coverage.nodejs.org/coverage-16e00a15deafdad0/lib/readline.js.html#L441 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 74753ed commit 0be8123

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎test/parallel/test-readline-interface.js

+30
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,16 @@ for (let i = 0; i < 12; i++) {
10611061
rli.close();
10621062
}
10631063

1064+
// Calling only the first question callback
1065+
{
1066+
const [rli] = getInterface({ terminal });
1067+
rli.question('foo?', common.mustCall((answer) => {
1068+
assert.strictEqual(answer, 'bar');
1069+
}));
1070+
rli.question('hello?', common.mustNotCall());
1071+
rli.write('bar\n');
1072+
}
1073+
10641074
// Calling the question multiple times
10651075
{
10661076
const [rli] = getInterface({ terminal });
@@ -1329,6 +1339,26 @@ for (let i = 0; i < 12; i++) {
13291339
rli.close();
13301340
}), delay);
13311341
}
1342+
1343+
// Write correctly if paused
1344+
{
1345+
const [rli] = getInterface({ terminal });
1346+
rli.on('line', common.mustCall((line) => {
1347+
assert.strictEqual(line, 'bar');
1348+
}));
1349+
rli.pause();
1350+
rli.write('bar\n');
1351+
assert.strictEqual(rli.paused, false);
1352+
rli.close();
1353+
}
1354+
1355+
// Write undefined
1356+
{
1357+
const [rli] = getInterface({ terminal });
1358+
rli.on('line', common.mustNotCall());
1359+
rli.write();
1360+
rli.close();
1361+
}
13321362
});
13331363

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

0 commit comments

Comments
 (0)
Please sign in to comment.