-
Notifications
You must be signed in to change notification settings - Fork 24
/
cli_test.ts
73 lines (63 loc) · 1.86 KB
/
cli_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
import { assertStrContains, assertMatch } from "./dev_deps.ts";
const wd = "./test";
const cliArgs = [
"deno",
"run",
"--allow-read",
"--allow-run",
"--allow-env",
"../cli.ts",
];
const expectedOutput = "Works!";
async function runScript(name: string): Promise<string> {
const process = Deno.run({
cmd: [...cliArgs, name],
cwd: wd,
stdout: "piped",
});
const { code } = await process.status();
if (code === 0) {
const rawOutput = await process.output();
process.close();
return new TextDecoder().decode(rawOutput);
} else {
process.close();
throw new Error(`Process exited with error code ${code}`);
}
}
Deno.test("basic script with env variable", async () => {
const output = await runScript("basic");
assertStrContains(output, expectedOutput);
});
Deno.test("deno run", async () => {
const output = await runScript("denorun");
assertStrContains(output, expectedOutput);
});
Deno.test("compact deno run", async () => {
const output = await runScript("compactrun");
assertStrContains(output, expectedOutput);
});
Deno.test("shell script", async () => {
const output = await runScript("sh");
assertStrContains(output, expectedOutput);
});
Deno.test("serial scripts", async () => {
const output = await runScript("multiple");
assertMatch(output, /one[\r\n]+two[\r\n]*/);
});
Deno.test("parallel scripts", async () => {
const output = await runScript("multiplepll");
assertMatch(output, /two[\r\n]+one[\r\n]*/);
});
Deno.test("deno permissions", async () => {
const output = await runScript("allow");
assertStrContains(output, expectedOutput);
});
Deno.test("tsconfig", async () => {
const output = await runScript("tsconfig");
assertStrContains(output, expectedOutput);
});
Deno.test("importmap", async () => {
const output = await runScript("importmap");
assertStrContains(output, expectedOutput);
});