From 04c6785faecdef37b3d4eefb61c0a18ff1cbdec0 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sat, 20 Apr 2024 17:11:27 +0530 Subject: fix(ext/node): `cp` into non-existent parent directory (#23469) Fixes https://github.com/denoland/deno/issues/20604 --- tests/unit_node/_fs/_fs_copy_test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit_node/_fs/_fs_copy_test.ts b/tests/unit_node/_fs/_fs_copy_test.ts index 036091303..adc002187 100644 --- a/tests/unit_node/_fs/_fs_copy_test.ts +++ b/tests/unit_node/_fs/_fs_copy_test.ts @@ -2,7 +2,7 @@ import * as path from "@std/path/mod.ts"; import { assert } from "@std/assert/mod.ts"; import { assertCallbackErrorUncaught } from "../_test_utils.ts"; -import { copyFile, copyFileSync, existsSync } from "node:fs"; +import { copyFile, copyFileSync, cpSync, existsSync } from "node:fs"; const destFile = "./destination.txt"; @@ -50,3 +50,13 @@ Deno.test("[std/node/fs] copyFile callback isn't called twice if error is thrown }, }); }); + +Deno.test("[std/node/fs] cp creates destination directory", async () => { + const tempDir = await Deno.makeTempDir(); + const tempFile1 = path.join(tempDir, "file1.txt"); + const tempFile2 = path.join(tempDir, "dir", "file2.txt"); + await Deno.writeTextFile(tempFile1, "hello world"); + cpSync(tempFile1, tempFile2); + assert(existsSync(tempFile2)); + await Deno.remove(tempDir, { recursive: true }); +}); -- cgit v1.2.3