1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00
denoland-deno/cli/js/permissions_test.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, testPerm, assert, assertEquals } from "./test_util.ts";
const knownPermissions: Deno.PermissionName[] = [
2019-03-07 21:56:56 -05:00
"run",
"read",
"write",
"net",
"env",
"hrtime"
2019-03-07 21:56:56 -05:00
];
for (const grant of knownPermissions) {
testPerm({ [grant]: true }, async function envGranted(): Promise<void> {
const status0 = await Deno.permissions.query({ name: grant });
assert(status0 != null);
assertEquals(status0.state, "granted");
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");
}
});