deno.land / x / velociraptor@1.5.0 / 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { assertEquals, assertMatch, assertStringIncludes } from "./dev_deps.ts";const yamlWd = "./test/yaml";const tsWd = "./test/ts";const jsonWd = "./test/json";const cliArgs = [ "deno", "run", "-qA", "../../cli.ts",];const expectedOutput = "Works!";
async function runScript( name: string, wd: string = yamlWd, additionalArgs: Array<string> = [],): Promise<string> { const process = Deno.run({ cmd: [...cliArgs, name, ...additionalArgs], cwd: wd, stdout: "piped", }); const { code } = await process.status(); const rawOutput: Uint8Array = await process.output(); const stdout: string = new TextDecoder().decode(rawOutput); if (code === 0) { process.close(); return stdout; } else { process.close(); throw new Error(`Process exited with error code ${code}\n${stdout}`); }}
Deno.test("basic script with env variable", async () => { const output = await runScript( Deno.build.os === "windows" ? "basic:win" : "basic", ); assertEquals( output.trim(), "Works! Works 1! Works 2! Works 3! Works 4!", );});
Deno.test("ts config file", async () => { const output = await runScript("test", tsWd); assertStringIncludes(output, expectedOutput);});
Deno.test("deno.json(c) config file", async () => { const output = await runScript("test", jsonWd); assertStringIncludes(output, expectedOutput);});
Deno.test("deno run", async () => { const output = await runScript("denorun"); assertStringIncludes(output, expectedOutput);});
Deno.test("compact deno run", async () => { const output = await runScript("compactrun"); assertStringIncludes(output, expectedOutput);});
Deno.test("shell script", async () => { const output = await runScript("sh"); assertStringIncludes(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"); assertStringIncludes(output, expectedOutput);});
Deno.test("tsconfig", async () => { const output = await runScript("tsconfig"); assertStringIncludes(output, expectedOutput);});
Deno.test("config", async () => { const output = await runScript("config", yamlWd); assertMatch(output, /^\s*$/);});
Deno.test("import map", async () => { const output = await runScript("importMap"); assertStringIncludes(output, expectedOutput);});
Deno.test("--help", async () => { const output = await runScript("--help"); assertStringIncludes(output, "--version");});
Deno.test("forward arguments", async () => { const output = await runScript("forward", yamlWd, ["--shuffle=1234"]); assertStringIncludes( output.replace(/\r\n|\r|\n/g, " "), "deno test --lock=lock.json --cached-only --shuffle=1234", );});
velociraptor

Version Info

Tagged at
2 years ago