From 24a35f914abc1c64d3fe30ed2c94a88011d9ea3f 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 PR-URL: https://github.com/nodejs/node/pull/22832 Reviewed-By: Bryan English Reviewed-By: Rich Trott Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat --- 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 f9750aa55a8b11..9ba4a1f8871830 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -299,7 +299,8 @@ async function readdir(path, options) { path = getPathFromURL(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;