From 832d8c39c7c6067921c9268468bb58f701c7e309 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Wed, 12 Sep 2018 20:47:56 -0700 Subject: [PATCH] fs: fix promisified fs.readdir withFileTypes --- lib/internal/fs/promises.js | 3 ++- test/parallel/test-fs-readdir-types.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 0aa26ba2f97daa..6cae7d1a21ff8d 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -317,7 +317,8 @@ async function readdir(path, options) { path = toPathIfFileURL(path); validatePath(path); const result = await binding.readdir(pathModule.toNamespacedPath(path), - options.encoding, !!options.withTypes, + options.encoding, + !!options.withFileTypes, kUsePromises); return options.withFileTypes ? getDirectoryEntriesPromise(path, result) : diff --git a/test/parallel/test-fs-readdir-types.js b/test/parallel/test-fs-readdir-types.js index 75452895cc178e..0faaeb00dadeb1 100644 --- a/test/parallel/test-fs-readdir-types.js +++ b/test/parallel/test-fs-readdir-types.js @@ -57,6 +57,14 @@ fs.readdir(readdirDir, { 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 const UNKNOWN = constants.UV_DIRENT_UNKNOWN; const oldReaddir = binding.readdir;