diff options
Diffstat (limited to 'cli/js/permissions_test.ts')
-rw-r--r-- | cli/js/permissions_test.ts | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/cli/js/permissions_test.ts b/cli/js/permissions_test.ts index 6511c2dcb..d9ba538f0 100644 --- a/cli/js/permissions_test.ts +++ b/cli/js/permissions_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { testPerm, assert, assertEquals } from "./test_util.ts"; +import { test, testPerm, assert, assertEquals } from "./test_util.ts"; -const knownPermissions: Deno.Permission[] = [ +const knownPermissions: Deno.PermissionName[] = [ "run", "read", "write", @@ -11,18 +11,31 @@ const knownPermissions: Deno.Permission[] = [ ]; for (const grant of knownPermissions) { - testPerm({ [grant]: true }, function envGranted(): void { - const perms = Deno.permissions(); - assert(perms !== null); - for (const perm in perms) { - assertEquals(perms[perm], perm === grant); - } + testPerm({ [grant]: true }, async function envGranted(): Promise<void> { + const status0 = await Deno.permissions.query({ name: grant }); + assert(status0 != null); + assertEquals(status0.state, "granted"); - Deno.revokePermission(grant); - - const revoked = Deno.permissions(); - for (const perm in revoked) { - assertEquals(revoked[perm], false); - } + const status1 = await Deno.permissions.revoke({ name: grant }); + assert(status1 != null); + assertEquals(status1.state, "prompt"); }); } + +test(async function permissionInvalidName(): Promise<void> { + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + await Deno.permissions.query({ name: "foo" as any }); + } catch (e) { + assert(e.name === "TypeError"); + } +}); + +test(async function permissionNetInvalidUrl(): Promise<void> { + try { + // Invalid url causes TypeError. + await Deno.permissions.query({ name: "net", url: ":" }); + } catch (e) { + assert(e.name === "TypeError"); + } +}); |