Skip to content

Commit 4a9511d

Browse files
LiviaMedeirosdanielleadams
authored andcommitted
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>
1 parent 60dc362 commit 4a9511d

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

lib/fs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ function exists(path, callback) {
278278

279279
ObjectDefineProperty(exists, internalUtil.promisify.custom, {
280280
__proto__: null,
281-
value: (path) => {
281+
value: function exists(path) { // eslint-disable-line func-name-matching
282282
return new Promise((resolve) => fs.exists(path, resolve));
283-
}
283+
},
284284
});
285285

286286
// fs.existsSync never throws, it only returns true or false.

lib/readline.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Interface.prototype.question = function(query, options, cb) {
153153
FunctionPrototypeCall(superQuestion, this, query, cb);
154154
}
155155
};
156-
Interface.prototype.question[promisify.custom] = function(query, options) {
156+
Interface.prototype.question[promisify.custom] = function question(query, options) {
157157
options = typeof options === 'object' && options !== null ? options : {};
158158

159159
if (options.signal && options.signal.aborted) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import '../common/index.mjs';
2+
import assert from 'node:assert';
3+
import { promisify } from 'node:util';
4+
5+
// Test that customly promisified methods in [util.promisify.custom]
6+
// have appropriate names
7+
8+
import fs from 'node:fs';
9+
import readline from 'node:readline';
10+
import stream from 'node:stream';
11+
import timers from 'node:timers';
12+
13+
14+
assert.strictEqual(
15+
promisify(fs.exists).name,
16+
'exists'
17+
);
18+
19+
assert.strictEqual(
20+
promisify(readline.Interface.prototype.question).name,
21+
'question',
22+
);
23+
24+
assert.strictEqual(
25+
promisify(stream.finished).name,
26+
'finished'
27+
);
28+
assert.strictEqual(
29+
promisify(stream.pipeline).name,
30+
'pipeline'
31+
);
32+
33+
assert.strictEqual(
34+
promisify(timers.setImmediate).name,
35+
'setImmediate'
36+
);
37+
assert.strictEqual(
38+
promisify(timers.setTimeout).name,
39+
'setTimeout'
40+
);

0 commit comments

Comments
 (0)