summaryrefslogtreecommitdiff
path: root/cli/js/os_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/os_test.ts')
-rw-r--r--cli/js/os_test.ts102
1 files changed, 24 insertions, 78 deletions
diff --git a/cli/js/os_test.ts b/cli/js/os_test.ts
index 0b859836b..e77678ec1 100644
--- a/cli/js/os_test.ts
+++ b/cli/js/os_test.ts
@@ -116,23 +116,7 @@ test(function osIsTTYSmoke(): void {
console.log(Deno.isTTY());
});
-testPerm({ env: true }, function homeDir(): void {
- assertNotEquals(Deno.homeDir(), "");
-});
-
-testPerm({ env: false }, function homeDirPerm(): void {
- let caughtError = false;
- try {
- Deno.homeDir();
- } catch (err) {
- caughtError = true;
- assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
- assertEquals(err.name, "PermissionDenied");
- }
- assert(caughtError);
-});
-
-testPerm({ env: true }, function getUserDir(): void {
+testPerm({ env: true }, function getDir(): void {
type supportOS = "mac" | "win" | "linux";
interface Runtime {
@@ -141,15 +125,13 @@ testPerm({ env: true }, function getUserDir(): void {
}
interface Scenes {
- name: string;
- fn: string;
+ kind: Deno.DirKind;
runtime: Runtime[];
}
const scenes: Scenes[] = [
{
- name: "config",
- fn: "configDir",
+ kind: "config",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -157,8 +139,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "cache",
- fn: "cacheDir",
+ kind: "cache",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -166,8 +147,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "data",
- fn: "dataDir",
+ kind: "data",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -175,8 +155,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "data local",
- fn: "dataLocalDir",
+ kind: "data_local",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -184,8 +163,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "audio",
- fn: "audioDir",
+ kind: "audio",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -193,8 +171,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "desktop",
- fn: "desktopDir",
+ kind: "desktop",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -202,8 +179,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "document",
- fn: "documentDir",
+ kind: "document",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -211,8 +187,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "download",
- fn: "downloadDir",
+ kind: "download",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -220,8 +195,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "font",
- fn: "fontDir",
+ kind: "font",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: false },
@@ -229,8 +203,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "picture",
- fn: "pictureDir",
+ kind: "picture",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -238,8 +211,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "public",
- fn: "publicDir",
+ kind: "public",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -247,8 +219,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "template",
- fn: "templateDir",
+ kind: "template",
runtime: [
{ os: "mac", shouldHaveValue: false },
{ os: "win", shouldHaveValue: true },
@@ -256,8 +227,7 @@ testPerm({ env: true }, function getUserDir(): void {
]
},
{
- name: "video",
- fn: "videoDir",
+ kind: "video",
runtime: [
{ os: "mac", shouldHaveValue: true },
{ os: "win", shouldHaveValue: true },
@@ -267,52 +237,28 @@ testPerm({ env: true }, function getUserDir(): void {
];
for (const s of scenes) {
- console.log(`test Deno.${s.fn}()`);
- const fn = Deno[s.fn];
-
for (const r of s.runtime) {
if (Deno.build.os !== r.os) continue;
if (r.shouldHaveValue) {
- assertNotEquals(fn(), "");
+ assertNotEquals(Deno.dir(s.kind), "");
} else {
// if not support your platform. it should throw an error
assertThrows(
- () => fn(),
+ () => Deno.dir(s.kind),
Deno.DenoError,
- `Could not get user ${s.name} directory.`
+ `Could not get user ${s.kind} directory.`
);
}
}
}
});
-testPerm({}, function getUserDirWithoutPermission(): void {
- const funcs: string[] = [
- "configDir",
- "cacheDir",
- "dataDir",
- "dataLocalDir",
- "audioDir",
- "desktopDir",
- "documentDir",
- "downloadDir",
- "fontDir",
- "pictureDir",
- "publicDir",
- "templateDir",
- "videoDir"
- ];
-
- for (const fnName of funcs) {
- console.log(`test Deno.${fnName}()`);
- const fn = Deno[fnName];
-
- assertThrows(
- () => fn(),
- Deno.DenoError,
- `run again with the --allow-env flag`
- );
- }
+testPerm({}, function getDirWithoutPermission(): void {
+ assertThrows(
+ () => Deno.dir("home"),
+ Deno.DenoError,
+ `run again with the --allow-env flag`
+ );
});
testPerm({ env: true }, function execPath(): void {