-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.ts
78 lines (69 loc) · 1.93 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { assert } from "https://deno.land/[email protected]/assert/assert.ts";
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { isAbsolute } from "https://deno.land/[email protected]/path/posix/is_absolute.ts";
import { getDir, open } from "./index.ts";
const { os } = Deno.build;
// Tests for open Deno package
let chromeName: string;
let firefoxName: string;
if (os === "darwin") {
chromeName = "/Applications/Google\ Chrome.app";
firefoxName = "firefox";
} else if (os === "windows") {
chromeName = "Chrome";
firefoxName = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
} else if (os === "linux") {
chromeName = "google-chrome";
firefoxName = "firefox";
}
Deno.test({
name: "getDir works",
fn(): void {
const currentDir = getDir(import.meta.url);
assert(isAbsolute(currentDir));
assertEquals(currentDir.slice(currentDir.length - 4), "open");
},
});
Deno.test({
name: "open works without options",
async fn(): Promise<void> {
const process = await open("index.ts");
process.kill();
await process.output();
},
});
Deno.test({
name: "open waits",
async fn(): Promise<void> {
const process = await open("test.png", { wait: true });
await process.status;
},
});
Deno.test({
name: "url gets encoded",
async fn(): Promise<void> {
const process = await open("https://google.com", { url: true });
process.kill();
await process.output();
},
});
Deno.test({
name: "open works with arguments",
async fn(): Promise<void> {
const process = await open("https://google.com", {
app: [chromeName, "-incognito"],
});
process.kill();
await process.output();
},
});
Deno.test({
name: "returns process",
async fn(): Promise<void> {
const process: Deno.ChildProcess = await open("https://google.com");
assert(typeof process.pid === "number");
assert(process.pid !== 0);
process.kill();
await process.output();
},
});