diff options
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 > { |