diff options
author | River <22485304+actual-size@users.noreply.github.com> | 2020-06-12 02:36:20 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-11 12:36:20 -0400 |
commit | 818a8010928cb8cef0b7043bd881c8cdce9b6efc (patch) | |
tree | 1502e74c9eb01901df8da118257d60d4f962b0e4 /cli/tests/unit/read_file_test.ts | |
parent | 813210d4337bf6e174f1da1f1a6c6fb9b073afa2 (diff) |
feat: URL support in Deno filesystem methods (#5990)
Diffstat (limited to 'cli/tests/unit/read_file_test.ts')
-rw-r--r-- | cli/tests/unit/read_file_test.ts | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/cli/tests/unit/read_file_test.ts b/cli/tests/unit/read_file_test.ts index 0d3cdf422..cae9037ab 100644 --- a/cli/tests/unit/read_file_test.ts +++ b/cli/tests/unit/read_file_test.ts @@ -1,5 +1,10 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { unitTest, assert, assertEquals } from "./test_util.ts"; +import { + unitTest, + assert, + assertEquals, + pathToAbsoluteFileUrl, +} from "./test_util.ts"; unitTest({ perms: { read: true } }, function readFileSyncSuccess(): void { const data = Deno.readFileSync("cli/tests/fixture.json"); @@ -10,6 +15,17 @@ unitTest({ perms: { read: true } }, function readFileSyncSuccess(): void { assertEquals(pkg.name, "deno"); }); +unitTest({ perms: { read: true } }, function readFileSyncUrl(): void { + const data = Deno.readFileSync( + pathToAbsoluteFileUrl("cli/tests/fixture.json") + ); + assert(data.byteLength > 0); + const decoder = new TextDecoder("utf-8"); + const json = decoder.decode(data); + const pkg = JSON.parse(json); + assertEquals(pkg.name, "deno"); +}); + unitTest({ perms: { read: false } }, function readFileSyncPerm(): void { let caughtError = false; try { @@ -34,6 +50,19 @@ unitTest({ perms: { read: true } }, function readFileSyncNotFound(): void { assert(data === undefined); }); +unitTest({ perms: { read: true } }, async function readFileUrl(): Promise< + void +> { + const data = await Deno.readFile( + pathToAbsoluteFileUrl("cli/tests/fixture.json") + ); + assert(data.byteLength > 0); + const decoder = new TextDecoder("utf-8"); + const json = decoder.decode(data); + const pkg = JSON.parse(json); + assertEquals(pkg.name, "deno"); +}); + unitTest({ perms: { read: true } }, async function readFileSuccess(): Promise< void > { |