Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: give names to promisified methods
Affected functions: `fs.exists`, `readline.Interface.prototype.question`

PR-URL: #43218
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
LiviaMedeiros committed Jun 5, 2022
commit 71071f896aa9696b5d36bb3bec1c7217e7420509
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
40 changes: 40 additions & 0 deletions test/parallel/test-util-promisify-custom-names.mjs
Original file line number Diff line number Diff line change
@@ -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'
);