/
default-options.test.ts
139 lines (121 loc) · 4.32 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
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("compilerOptions", () => {
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])
);
});
});
describe("searchCategoryBoosts", () => {
it("Should disallow non-objects", () => {
throws(() => opts.setValue("searchCategoryBoosts", null as never));
});
it("Should disallow non-numbers", () => {
throws(() =>
opts.setValue("searchCategoryBoosts", {
cat: true as any as number,
})
);
});
});
describe("searchGroupBoosts", () => {
it("Should disallow non-objects", () => {
throws(() => opts.setValue("searchGroupBoosts", null as never));
});
it("Should disallow non-numbers", () => {
throws(() =>
opts.setValue("searchGroupBoosts", {
Enum: true as any as number,
})
);
});
it("Should allow groups", () => {
doesNotThrow(() => opts.setValue("searchGroupBoosts", { Enum: 5 }));
});
});
describe("headerLinks", () => {
it("Should disallow non-objects", () => {
throws(() => opts.setValue("headerLinks", null as never));
});
it("Should disallow non-strings", () => {
throws(() =>
opts.setValue("headerLinks", {
"Home": true as any as string,
})
);
});
});
describe("sidebarLinks", () => {
it("Should disallow non-objects", () => {
throws(() => opts.setValue("sidebarLinks", null as never));
});
it("Should disallow non-strings", () => {
throws(() =>
opts.setValue("sidebarLinks", {
"Home": true as any as string,
})
);
});
});
});