From ef8b9efaa4bec9780323bd203a6c7905a5e086ce Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sat, 18 Nov 2023 22:24:49 -0800 Subject: [PATCH] Fixes #7201 --- src/js/node/fs.js | 5 ++++- test/js/node/fs/cp.test.ts | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/js/node/fs.js b/src/js/node/fs.js index e5129c46b9..963afb11ef 100644 --- a/src/js/node/fs.js +++ b/src/js/node/fs.js @@ -1199,10 +1199,13 @@ function cpSync(src, dest, options) { } function cp(src, dest, options, callback) { - if (typeof options === "function") { + if ($isCallable(options)) { callback = options; options = undefined; } + + ensureCallback(callback); + promises.cp(src, dest, options).then(() => callback(), callback); } diff --git a/test/js/node/fs/cp.test.ts b/test/js/node/fs/cp.test.ts index eae8a0e778..41f5dd1e7b 100644 --- a/test/js/node/fs/cp.test.ts +++ b/test/js/node/fs/cp.test.ts @@ -286,3 +286,10 @@ for (const [name, copy] of impls) { }); }); } + +test("cp with missing callback throws", () => { + expect(() => { + // @ts-expect-error + fs.cp("a", "b" as any); + }).toThrow(/callback/); +});