From 428266c06a192f008a5429e871f783dfb4601f93 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 6 Feb 2024 12:32:58 +0530 Subject: [PATCH] fix(node): add `cp` to fs/promises (#22263) --- cli/tests/unit_node/fs_test.ts | 16 +++++++++++++++- ext/node/polyfills/fs/promises.ts | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cli/tests/unit_node/fs_test.ts b/cli/tests/unit_node/fs_test.ts index 11114823f2..6766c59280 100644 --- a/cli/tests/unit_node/fs_test.ts +++ b/cli/tests/unit_node/fs_test.ts @@ -15,7 +15,7 @@ import { readFileSync, writeFileSync, } from "node:fs"; -import { constants as fsPromiseConstants } from "node:fs/promises"; +import { constants as fsPromiseConstants, cp } from "node:fs/promises"; import { pathToAbsoluteFileUrl } from "../unit/test_util.ts"; Deno.test( @@ -100,3 +100,17 @@ Deno.test( assertEquals(constants, promises.constants); }, ); + +Deno.test( + "[node/fs/promises cp] copy file", + async () => { + const src = mkdtempSync(join(tmpdir(), "foo-")) + "/test.txt"; + const dest = mkdtempSync(join(tmpdir(), "foo-")) + "/test.txt"; + writeFileSync(src, "Hello"); + + await cp(src, dest); + + const dataRead = readFileSync(dest, "utf8"); + assert(dataRead === "Hello"); + }, +); diff --git a/ext/node/polyfills/fs/promises.ts b/ext/node/polyfills/fs/promises.ts index ffdb862d8c..3e5329dbbe 100644 --- a/ext/node/polyfills/fs/promises.ts +++ b/ext/node/polyfills/fs/promises.ts @@ -30,5 +30,6 @@ export const writeFile = fsPromises.writeFile; export const appendFile = fsPromises.appendFile; export const readFile = fsPromises.readFile; export const watch = fsPromises.watch; +export const cp = fsPromises.cp; export default fsPromises;