From 68e6673224365120f50286169148539c7043efd8 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 27 Apr 2021 16:04:24 +0200 Subject: [PATCH] test,readline: improve tab completion coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/38465 Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso --- test/parallel/test-readline-tab-complete.js | 48 +++++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-readline-tab-complete.js b/test/parallel/test-readline-tab-complete.js index 7ccdef116492b7..c283d446f9af28 100644 --- a/test/parallel/test-readline-tab-complete.js +++ b/test/parallel/test-readline-tab-complete.js @@ -31,15 +31,15 @@ common.skipIfDumbTerminal(); const width = getStringWidth(char) - 1; class FakeInput extends EventEmitter { - columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3 + columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3 - write = common.mustCall((data) => { - output += data; - }, 6) + write = common.mustCall((data) => { + output += data; + }, 6) - resume() {} - pause() {} - end() {} + resume() {} + pause() {} + end() {} } const fi = new FakeInput(); @@ -47,7 +47,7 @@ common.skipIfDumbTerminal(); input: fi, output: fi, terminal: true, - completer: completer + completer: common.mustCallAtLeast(completer), }); const last = '\r\nFirst group\r\n\r\n' + @@ -68,3 +68,35 @@ common.skipIfDumbTerminal(); rli.close(); }); }); + +{ + let output = ''; + class FakeInput extends EventEmitter { + columns = 80 + + write = common.mustCall((data) => { + output += data; + }, 1) + + resume() {} + pause() {} + end() {} + } + + const fi = new FakeInput(); + const rli = new readline.Interface({ + input: fi, + output: fi, + terminal: true, + completer: + common.mustCallAtLeast((_, cb) => cb(new Error('message'))), + }); + + rli.on('line', common.mustNotCall()); + fi.emit('data', '\t'); + queueMicrotask(() => { + assert.match(output, /^Tab completion error: Error: message/); + output = ''; + }); + rli.close(); +}