-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.ts
55 lines (52 loc) · 1.37 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
import { cli } from "./cli.ts";
import { assertMatch } from "https://deno.land/std@0.97.0/testing/asserts.ts";
import { wait } from "./_utils.ts";
Deno.test("serve prints help text", async () => {
let output = "";
await cli({
args: ["--help"],
stdin: {
read: (_: Uint8Array) => {
return Promise.resolve(null);
},
},
stdout: {
write: (p: Uint8Array) => {
output += new TextDecoder().decode(p);
return Promise.resolve(p.byteLength);
},
},
});
assertMatch(output, /--allow-net/);
assertMatch(output, /--allow-read/);
assertMatch(output, /--help/);
assertMatch(output, /--hostname/);
assertMatch(output, /--port/);
assertMatch(output, /--path/);
assertMatch(output, /https:\/\/deno\.land\/x\/wsfs\/cli\.ts/);
assertMatch(output, /https:\/\/github.com\/eibens\/wsfs/);
});
Deno.test("serve runs server", async () => {
let output = "";
let done = false;
await cli({
args: [],
stdin: {
read: async (p: Uint8Array) => {
if (done) return null;
done = true;
await wait(1000);
p[0] = "q".charCodeAt(0);
p[1] = "\n".charCodeAt(0);
return 2;
},
},
stdout: {
write: (p: Uint8Array) => {
output += new TextDecoder().decode(p);
return Promise.resolve(p.byteLength);
},
},
});
assertMatch(output, /wsfs/);
});