-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve.test.mjs
121 lines (111 loc) · 3.03 KB
/
serve.test.mjs
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
// @ts-check
import { assertRejects } from "std/testing/asserts.ts";
import serve from "./serve.mjs";
Deno.test("`serve` with option `clientImportMap` not an import map object or `URL` instance.", async () => {
await assertRejects(
() =>
serve({
// @ts-expect-error Testing invalid.
clientImportMap: true,
port: 3000,
}),
TypeError,
"Option `clientImportMap` must be an import map object or `URL` instance.",
);
});
Deno.test("`serve` with option `clientImportMap` an invalid import map object.", async () => {
await assertRejects(
() =>
serve({
clientImportMap: {
// @ts-expect-error Testing invalid.
imports: true,
},
port: 3000,
}),
TypeError,
"Option `clientImportMap` must be an import map object.",
);
});
Deno.test("`serve` with option `esModuleShimsSrc` not a string.", async () => {
await assertRejects(
() =>
serve({
clientImportMap: new URL("./importMap.json", import.meta.url),
// @ts-expect-error Testing invalid.
esModuleShimsSrc: true,
port: 3000,
}),
TypeError,
"Option `esModuleShimsSrc` must be a string.",
);
});
Deno.test("`serve` with option `publicDir` not a `URL` instance.", async () => {
await assertRejects(
() =>
serve({
clientImportMap: new URL("./importMap.json", import.meta.url),
// @ts-expect-error Testing invalid.
publicDir: true,
port: 3000,
}),
TypeError,
"Option `publicDir` must be a `URL` instance.",
);
});
Deno.test(
"`serve` with option `publicDir` not a URL ending with `/`.",
async () => {
await assertRejects(
() =>
serve({
clientImportMap: new URL("./importMap.json", import.meta.url),
publicDir: new URL(import.meta.url),
port: 3000,
}),
TypeError,
"Option `publicDir` must be a URL ending with `/`.",
);
},
);
Deno.test("`serve` with option `htmlComponent` not a function.", async () => {
await assertRejects(
() =>
serve({
clientImportMap: new URL("./importMap.json", import.meta.url),
port: 3000,
// @ts-expect-error Testing invalid.
htmlComponent: true,
}),
TypeError,
"Option `htmlComponent` must be a function.",
);
});
Deno.test("`serve` with option `port` not a number.", async () => {
await assertRejects(
() =>
serve({
clientImportMap: new URL("./importMap.json", import.meta.url),
// @ts-expect-error Testing invalid.
port: true,
}),
TypeError,
"Option `port` must be a number.",
);
});
Deno.test(
"`serve` with option `signal` not an `AbortSignal` instance.",
async () => {
await assertRejects(
() =>
serve({
clientImportMap: new URL("./importMap.json", import.meta.url),
port: 3000,
// @ts-expect-error Testing invalid.
signal: true,
}),
TypeError,
"Option `signal` must be an `AbortSignal` instance.",
);
},
);