diff options
Diffstat (limited to 'cli/tests/unit_node')
-rw-r--r-- | cli/tests/unit_node/fs_test.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/cli/tests/unit_node/fs_test.ts b/cli/tests/unit_node/fs_test.ts index 310113233..d9fe3af76 100644 --- a/cli/tests/unit_node/fs_test.ts +++ b/cli/tests/unit_node/fs_test.ts @@ -3,7 +3,8 @@ import { assert, assertThrows } from "../../../test_util/std/assert/mod.ts"; import { join } from "node:path"; import { tmpdir } from "node:os"; -import { mkdtempSync, readFileSync, writeFileSync } from "node:fs"; +import { existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs"; +import { pathToAbsoluteFileUrl } from "../unit/test_util.ts"; Deno.test( "[node/fs writeFileSync] write file without option", @@ -43,3 +44,39 @@ Deno.test( ); }, ); + +Deno.test( + "[node/fs existsSync] path", + { permissions: { read: true } }, + () => { + assert(existsSync("cli/tests/testdata/assets/fixture.json")); + }, +); + +Deno.test( + "[node/fs existsSync] url", + { permissions: { read: true } }, + () => { + assert(existsSync( + pathToAbsoluteFileUrl("cli/tests/testdata/assets/fixture.json"), + )); + }, +); + +Deno.test( + "[node/fs existsSync] no permission", + { permissions: { read: false } }, + () => { + assertThrows(() => { + existsSync("cli/tests/testdata/assets/fixture.json"); + }, Deno.errors.PermissionDenied); + }, +); + +Deno.test( + "[node/fs existsSync] not exists", + { permissions: { read: true } }, + () => { + assert(!existsSync("bad_filename")); + }, +); |