-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvl.test.ts
125 lines (107 loc) · 3.04 KB
/
vl.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
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// Copyright 2022 Joona Piirainen
// MIT License
//
import {
assert,
assertEquals,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import "./globals.d.ts";
import "./globals.ts";
Deno.test("[] can be passed to $", async () => {
const flags = ["--oneline", "--decorate", "--color"];
const { exitCode } = await $`git log ${flags}`;
assertEquals(exitCode, 0);
});
Deno.test("Env vars work", async () => {
Deno.env.set("FOO", "foo");
const foo = await $`echo $FOO`;
assertEquals(foo.stdout, "foo\n");
});
Deno.test("Env vars is safe to pass", async () => {
Deno.env.set("FOO", "hi; exit 1");
await $`echo $FOO`;
});
Deno.test("echo works", async () => {
const { stdout } = await $`echo "hello"`;
assertEquals(stdout, "hello\n");
});
Deno.test("noThrow() does not throw", async () => {
const { exitCode } = await noThrow($`exit 42`);
assertEquals(exitCode, 42);
});
Deno.test("Arguments are quoted", async () => {
const bar = 'bar"";baz!$#^$\'&*~*%)({}||\\/';
assertEquals((await $`echo ${bar}`).stdout.trim(), bar);
});
Deno.test("undefined and empty string correctly quoted", async () => {
assertEquals((await $`echo ${undefined}`).stdout.trim(), "undefined");
assertEquals((await $`echo ${""}`).stdout.trim(), "");
});
Deno.test(
"multiple arguments in execution are correctly quoted from list format",
async () => {
const foo = "foo";
const bar = "bar";
const cmd = [`echo`, foo, "to", bar];
assertEquals((await $`${cmd}`).stdout.trim(), "foo to bar");
},
);
Deno.test(
"multiple arguments in execution are correctly quoted from string format",
async () => {
const foo = "foo";
const bar = "bar";
assertEquals((await $`echo ${foo} to ${bar}`).stdout.trim(), "foo to bar");
assertEquals((await $`echo ${foo}:${bar}`).stdout.trim(), "foo:bar");
},
);
Deno.test("Can create a dir with a space in the name", async () => {
const name = "foo bar";
try {
await $`mkdir /tmp/${name}`;
} finally {
await Deno.remove("/tmp/" + name);
}
});
Deno.test(".kill() works", async () => {
const p = noThrow($`sleep 9999`);
setTimeout(() => {
p.kill();
}, 100);
await p;
});
Deno.test("exiting non 0 works", async () => {
try {
await $`exit 1`;
} catch (e) {
assertEquals(e.exitCode, 1);
}
});
Deno.test("quiet() works", async () => {
const p = quiet($`echo "hello"`);
assertEquals(p._quiet, true);
await p;
});
Deno.test("santitize() works", async () => {
const p = sanitize($`echo "hello" SECRET_KEY`, ["SECRET_KEY"]);
assertEquals(p._sanitize, ["SECRET_KEY"]);
// Note that sanitize stopped it from printing but does not remove it from the output of stdout
await p;
});
Deno.test("retry works", async () => {
let exitCode = 0;
const now = Date.now();
try {
await retry(5, 50)`exit 123`;
} catch (p) {
exitCode = p.exitCode;
}
assertEquals(exitCode, 123);
assert(Date.now() >= now + 50 * (5 - 1));
});
Deno.test("spinner works", async () => {
const { stopSpinner } = startSpinner("waiting");
await sleep(1000);
stopSpinner();
});