From d57d47bc342f5ae53f51a01c6aa17dc849838e7b Mon Sep 17 00:00:00 2001 From: antsmartian Date: Mon, 9 Sep 2019 21:33:10 +0530 Subject: [PATCH] repl: add autocomplete support for fs.promises PR-URL: https://github.com/nodejs/node/pull/29400 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Anna Henningsen Reviewed-By: Yongsheng Zhang --- lib/repl.js | 3 +- test/parallel/test-repl-tab-complete.js | 60 +++++++++++++------------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 5c5b1c88cab3f0..9bbf4ee2caadba 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1005,6 +1005,7 @@ ArrayStream.prototype.resume = function() {}; ArrayStream.prototype.write = function() {}; const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?(?:[\w@./-]*))/; +const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/; const simpleExpressionRE = /(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/; @@ -1173,7 +1174,7 @@ function complete(line, callback) { } completionGroupsLoaded(); - } else if (match = line.match(/fs\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/)) { + } else if (match = line.match(fsAutoCompleteRE)) { let filePath = match[1]; let fileList; diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index 364d880e8cc479..5c1936b3f5a120 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -402,37 +402,39 @@ testMe.complete('obj.', common.mustCall((error, data) => { putIn.run(['.clear']); process.chdir(__dirname); - const readFileSync = 'fs.readFileSync("'; - const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`; + const readFileSyncs = ['fs.readFileSync("', 'fs.promises.readFileSync("']; if (!common.isWindows) { - testMe.complete(fixturePath, common.mustCall((err, data) => { - assert.strictEqual(err, null); - assert.ok(data[0][0].includes('.hiddenfiles')); - assert.ok(data[0][1].includes('hellorandom.txt')); - assert.ok(data[0][2].includes('helloworld.js')); - })); + readFileSyncs.forEach((readFileSync) => { + const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`; + testMe.complete(fixturePath, common.mustCall((err, data) => { + assert.strictEqual(err, null); + assert.ok(data[0][0].includes('.hiddenfiles')); + assert.ok(data[0][1].includes('hellorandom.txt')); + assert.ok(data[0][2].includes('helloworld.js')); + })); - testMe.complete(`${fixturePath}/hello`, - common.mustCall((err, data) => { - assert.strictEqual(err, null); - assert.ok(data[0][0].includes('hellorandom.txt')); - assert.ok(data[0][1].includes('helloworld.js')); - }) - ); - - testMe.complete(`${fixturePath}/.h`, - common.mustCall((err, data) => { - assert.strictEqual(err, null); - assert.ok(data[0][0].includes('.hiddenfiles')); - }) - ); - - testMe.complete(`${readFileSync}./xxxRandom/random`, - common.mustCall((err, data) => { - assert.strictEqual(err, null); - assert.strictEqual(data[0].length, 0); - }) - ); + testMe.complete(`${fixturePath}/hello`, + common.mustCall((err, data) => { + assert.strictEqual(err, null); + assert.ok(data[0][0].includes('hellorandom.txt')); + assert.ok(data[0][1].includes('helloworld.js')); + }) + ); + + testMe.complete(`${fixturePath}/.h`, + common.mustCall((err, data) => { + assert.strictEqual(err, null); + assert.ok(data[0][0].includes('.hiddenfiles')); + }) + ); + + testMe.complete(`${readFileSync}./xxxRandom/random`, + common.mustCall((err, data) => { + assert.strictEqual(err, null); + assert.strictEqual(data[0].length, 0); + }) + ); + }); } }