diff options
author | LiviaMedeiros <livia@cirno.name> | 2022-05-26 19:04:09 +0300 |
---|---|---|
committer | LiviaMedeiros <livia@cirno.name> | 2022-06-05 10:56:47 +0300 |
commit | 71071f896aa9696b5d36bb3bec1c7217e7420509 (patch) | |
tree | 20e6adea13d08e70b0d290eef3ad4aec9c428d8b | |
parent | 45d7ca95cd53bbf4045182d5d3419955185e87a1 (diff) |
lib: give names to promisified methods
Affected functions: `fs.exists`, `readline.Interface.prototype.question`
PR-URL: https://github.com/nodejs/node/pull/43218
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
-rw-r--r-- | lib/fs.js | 4 | ||||
-rw-r--r-- | lib/readline.js | 2 | ||||
-rw-r--r-- | test/parallel/test-util-promisify-custom-names.mjs | 40 |
3 files changed, 43 insertions, 3 deletions
diff --git a/lib/fs.js b/lib/fs.js index b251761bd42..a3f72535d77 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -278,9 +278,9 @@ function exists(path, callback) { ObjectDefineProperty(exists, internalUtil.promisify.custom, { __proto__: null, - value: (path) => { + value: function exists(path) { // eslint-disable-line func-name-matching return new Promise((resolve) => fs.exists(path, resolve)); - } + }, }); // fs.existsSync never throws, it only returns true or false. diff --git a/lib/readline.js b/lib/readline.js index 0957de58506..82afaa285d6 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -153,7 +153,7 @@ Interface.prototype.question = function(query, options, cb) { FunctionPrototypeCall(superQuestion, this, query, cb); } }; -Interface.prototype.question[promisify.custom] = function(query, options) { +Interface.prototype.question[promisify.custom] = function question(query, options) { options = typeof options === 'object' && options !== null ? options : {}; if (options.signal && options.signal.aborted) { diff --git a/test/parallel/test-util-promisify-custom-names.mjs b/test/parallel/test-util-promisify-custom-names.mjs new file mode 100644 index 00000000000..3ff05d907b5 --- /dev/null +++ b/test/parallel/test-util-promisify-custom-names.mjs @@ -0,0 +1,40 @@ +import '../common/index.mjs'; +import assert from 'node:assert'; +import { promisify } from 'node:util'; + +// Test that customly promisified methods in [util.promisify.custom] +// have appropriate names + +import fs from 'node:fs'; +import readline from 'node:readline'; +import stream from 'node:stream'; +import timers from 'node:timers'; + + +assert.strictEqual( + promisify(fs.exists).name, + 'exists' +); + +assert.strictEqual( + promisify(readline.Interface.prototype.question).name, + 'question', +); + +assert.strictEqual( + promisify(stream.finished).name, + 'finished' +); +assert.strictEqual( + promisify(stream.pipeline).name, + 'pipeline' +); + +assert.strictEqual( + promisify(timers.setImmediate).name, + 'setImmediate' +); +assert.strictEqual( + promisify(timers.setTimeout).name, + 'setTimeout' +); |