Skip to content

Commit 479e1ec

Browse files
apapirovskitargos
authored andcommitted
fs: fix promisified fs.readdir withFileTypes
PR-URL: #22832 Reviewed-By: Bryan English <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 81fd5d2 commit 479e1ec

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/internal/fs/promises.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ async function readdir(path, options) {
311311
path = toPathIfFileURL(path);
312312
validatePath(path);
313313
const result = await binding.readdir(pathModule.toNamespacedPath(path),
314-
options.encoding, !!options.withTypes,
314+
options.encoding,
315+
!!options.withFileTypes,
315316
kUsePromises);
316317
return options.withFileTypes ?
317318
getDirectoryEntriesPromise(path, result) :

test/parallel/test-fs-readdir-types.js

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ fs.readdir(readdirDir, {
5757
assertDirents(dirents);
5858
}));
5959

60+
// Check the promisified version
61+
assert.doesNotReject(async () => {
62+
const dirents = await fs.promises.readdir(readdirDir, {
63+
withFileTypes: true
64+
});
65+
assertDirents(dirents);
66+
});
67+
6068
// Check for correct types when the binding returns unknowns
6169
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
6270
const oldReaddir = binding.readdir;

0 commit comments

Comments
 (0)