forked from coder/code-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.test.ts
More file actions
126 lines (118 loc) · 3.38 KB
/
Copy pathcli.test.ts
File metadata and controls
126 lines (118 loc) · 3.38 KB
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
126
import * as assert from "assert"
import * as path from "path"
import { parse } from "../src/node/cli"
import { xdgLocalDir } from "../src/node/util"
describe("cli", () => {
it("should set defaults", () => {
assert.deepEqual(parse([]), {
_: [],
"extensions-dir": path.join(xdgLocalDir, "extensions"),
"user-data-dir": xdgLocalDir,
})
})
it("should parse all available options", () => {
assert.deepEqual(
parse([
"--auth",
"none",
"--extensions-dir",
"foo",
"--builtin-extensions-dir",
"foobar",
"--extra-extensions-dir",
"nozzle",
"1",
"--extra-builtin-extensions-dir",
"bazzle",
"--verbose",
"2",
"--log",
"error",
"--help",
"--open",
"--socket",
"mumble",
"3",
"--user-data-dir",
"bar",
"--cert",
"baz",
"--cert-key",
"qux",
"--version",
"--json",
"--port",
"8081",
"--host",
"0.0.0.0",
"4",
"--",
"-5",
"--6",
]),
{
_: ["1", "2", "3", "4", "-5", "--6"],
auth: "none",
"builtin-extensions-dir": path.resolve("foobar"),
"cert-key": path.resolve("qux"),
cert: {
value: path.resolve("baz"),
},
"extensions-dir": path.resolve("foo"),
"extra-builtin-extensions-dir": [path.resolve("bazzle")],
"extra-extensions-dir": [path.resolve("nozzle")],
help: true,
host: "0.0.0.0",
json: true,
log: "trace",
open: true,
port: 8081,
socket: path.resolve("mumble"),
"user-data-dir": path.resolve("bar"),
verbose: true,
version: true,
}
)
})
it("should work with short options", () => {
assert.deepEqual(parse(["-vvv", "-v"]), {
_: [],
"extensions-dir": path.join(xdgLocalDir, "extensions"),
"user-data-dir": xdgLocalDir,
log: "trace",
verbose: true,
version: true,
})
})
it("should error if value isn't provided", () => {
assert.throws(() => parse(["--auth"]), /--auth requires a value/)
})
it("should error if number option is invalid", () => {
assert.throws(() => parse(["--port", "foo"]), /--port must be a number/)
assert.throws(() => parse(["--auth", "invalid"]), /--auth valid values: \[password, none\]/)
})
it("should error if the option doesn't exist", () => {
assert.throws(() => parse(["--foo"]), /Unknown option --foo/)
})
it("should not error if the value is optional", () => {
assert.deepEqual(parse(["--cert"]), {
_: [],
"extensions-dir": path.join(xdgLocalDir, "extensions"),
"user-data-dir": xdgLocalDir,
cert: {
value: undefined,
},
})
})
it("should not allow option-like values", () => {
assert.throws(() => parse(["--socket", "--socket-path-value"]), /--socket requires a value/)
// If you actually had a path like this you would do this instead:
assert.deepEqual(parse(["--socket", "./--socket-path-value"]), {
_: [],
"extensions-dir": path.join(xdgLocalDir, "extensions"),
"user-data-dir": xdgLocalDir,
socket: path.resolve("--socket-path-value"),
})
assert.throws(() => parse(["--cert", "--socket-path-value"]), /Unknown option --socket-path-value/)
})
})