/
default-options.test.ts
71 lines (63 loc) · 2.3 KB
/
default-options.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
import { ok, throws, strictEqual, doesNotThrow } from "assert";
import { BUNDLED_THEMES } from "shiki";
import { Logger, Options } from "../../../lib/utils";
describe("Default Options", () => {
const opts = new Options(new Logger());
opts.addDefaultDeclarations();
describe("Highlighting theme", () => {
it("Errors if an invalid theme is provided", () => {
throws(() =>
opts.setValue("lightHighlightTheme", "randomTheme" as never)
);
opts.setValue("lightHighlightTheme", BUNDLED_THEMES[0]);
strictEqual(
opts.getValue("lightHighlightTheme"),
BUNDLED_THEMES[0]
);
throws(() =>
opts.setValue("darkHighlightTheme", "randomTheme" as never)
);
opts.setValue("darkHighlightTheme", BUNDLED_THEMES[0]);
strictEqual(opts.getValue("darkHighlightTheme"), BUNDLED_THEMES[0]);
});
});
describe("sort", () => {
it("Errors if an invalid sort version is provided", () => {
throws(() =>
opts.setValue("sort", ["random", "alphabetical"] as never)
);
});
it("Reports which sort option(s) was invalid", () => {
try {
opts.setValue("sort", [
"random",
"alphabetical",
"foo",
] as never);
} catch (e) {
ok(e instanceof Error);
ok(e.message.includes("random"));
ok(e.message.includes("foo"));
}
});
});
describe("markedOptions", () => {
it("Errors if given a non-object", () => {
throws(() => opts.setValue("markedOptions", null));
throws(() => opts.setValue("markedOptions", "bad"));
throws(() => opts.setValue("markedOptions", []));
});
});
describe("requiredToBeDocumented", () => {
it("Works with valid values", () => {
doesNotThrow(() =>
opts.setValue("requiredToBeDocumented", ["Enum"])
);
});
it("Throws on invalid values", () => {
throws(() =>
opts.setValue("requiredToBeDocumented", ["Enum2" as never])
);
});
});
});