summaryrefslogtreecommitdiff
path: root/tests/unit_node
diff options
context:
space:
mode:
authorfamilyboat <84062528+familyboat@users.noreply.github.com>2024-10-27 11:04:35 +0800
committerGitHub <noreply@github.com>2024-10-27 08:34:35 +0530
commitc314b2d8577289078d6b00a0dd58f8f36ff6920a (patch)
tree7ab31f425b81954a896169476f800f5925532ce2 /tests/unit_node
parent05868cc2367d6c827691d7624478157239048bea (diff)
fix(ext/node): add path to `fs.stat` and `fs.statSync` error (#26037)
Diffstat (limited to 'tests/unit_node')
-rw-r--r--tests/unit_node/fs_test.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/unit_node/fs_test.ts b/tests/unit_node/fs_test.ts
index ef8f829cd..631608d7c 100644
--- a/tests/unit_node/fs_test.ts
+++ b/tests/unit_node/fs_test.ts
@@ -26,6 +26,7 @@ import {
cp,
FileHandle,
open,
+ stat,
writeFile,
} from "node:fs/promises";
import process from "node:process";
@@ -124,6 +125,48 @@ Deno.test(
);
Deno.test(
+ "[node/fs statSync] throw error with path information",
+ () => {
+ const file = "non-exist-file";
+ const fileUrl = new URL(file, import.meta.url);
+
+ assertThrows(() => {
+ statSync(file);
+ }, "Error: ENOENT: no such file or directory, stat 'non-exist-file'");
+
+ assertThrows(() => {
+ statSync(fileUrl);
+ }, `Error: ENOENT: no such file or directory, stat '${fileUrl.pathname}'`);
+ },
+);
+
+Deno.test(
+ "[node/fs/promises stat] throw error with path information",
+ async () => {
+ const file = "non-exist-file";
+ const fileUrl = new URL(file, import.meta.url);
+
+ try {
+ await stat(file);
+ } catch (error: unknown) {
+ assertEquals(
+ `${error}`,
+ "Error: ENOENT: no such file or directory, stat 'non-exist-file'",
+ );
+ }
+
+ try {
+ await stat(fileUrl);
+ } catch (error: unknown) {
+ assertEquals(
+ `${error}`,
+ `Error: ENOENT: no such file or directory, stat '${fileUrl.pathname}'`,
+ );
+ }
+ },
+);
+
+Deno.test(
"[node/fs/promises cp] copy file",
async () => {
const src = mkdtempSync(join(tmpdir(), "foo-")) + "/test.txt";