fs: fix promisified fs.readdir withFileTypes
PR-URL: https://github.com/nodejs/node/pull/22832 Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
de37ba34c5
commit
16210cad09
@ -317,7 +317,8 @@ async function readdir(path, options) {
|
|||||||
path = toPathIfFileURL(path);
|
path = toPathIfFileURL(path);
|
||||||
validatePath(path);
|
validatePath(path);
|
||||||
const result = await binding.readdir(pathModule.toNamespacedPath(path),
|
const result = await binding.readdir(pathModule.toNamespacedPath(path),
|
||||||
options.encoding, !!options.withTypes,
|
options.encoding,
|
||||||
|
!!options.withFileTypes,
|
||||||
kUsePromises);
|
kUsePromises);
|
||||||
return options.withFileTypes ?
|
return options.withFileTypes ?
|
||||||
getDirectoryEntriesPromise(path, result) :
|
getDirectoryEntriesPromise(path, result) :
|
||||||
|
@ -57,6 +57,14 @@ fs.readdir(readdirDir, {
|
|||||||
assertDirents(dirents);
|
assertDirents(dirents);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Check the promisified version
|
||||||
|
assert.doesNotReject(async () => {
|
||||||
|
const dirents = await fs.promises.readdir(readdirDir, {
|
||||||
|
withFileTypes: true
|
||||||
|
});
|
||||||
|
assertDirents(dirents);
|
||||||
|
});
|
||||||
|
|
||||||
// Check for correct types when the binding returns unknowns
|
// Check for correct types when the binding returns unknowns
|
||||||
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
|
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
|
||||||
const oldReaddir = binding.readdir;
|
const oldReaddir = binding.readdir;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user