/
main_test.ts
79 lines (65 loc) · 2.2 KB
/
main_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
import { assertArrayIncludes, assertEquals } from "$std/testing/asserts.ts";
import { delay } from "$std/async/delay.ts";
import { startFreshServer, withPageName } from "../tests/test_utils.ts";
import { dirname, join } from "$std/path/mod.ts";
const dir = dirname(import.meta.url);
Deno.test("CORS should not set on GET /fresh-badge.svg", {
sanitizeResources: false,
}, async () => {
const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", join(dir, "./main.ts")],
});
const res = await fetch(`${address}/fresh-badge.svg`);
await res.body?.cancel();
assertEquals(res.headers.get("cross-origin-resource-policy"), null);
await lines.cancel();
serverProcess.kill("SIGTERM");
// await for the server to close
await delay(100);
});
Deno.test("shows version selector", {
sanitizeResources: false,
}, async () => {
await withPageName(join(dir, "./main.ts"), async (page, address) => {
await page.goto(`${address}/docs`);
await page.waitForSelector("#version");
// Check that we redirected to the first page
assertEquals(page.url(), `${address}/docs/introduction`);
// Wait for version selector to be enabled
await page.waitForSelector("#version:not([disabled])");
const options = await page.$eval("#version", (el: HTMLSelectElement) => {
return Array.from(el.options).map((option) => ({
value: option.value,
label: option.textContent,
}));
});
assertEquals(options.length, 2);
assertArrayIncludes(options, [
{
value: "canary",
label: "canary",
},
{
value: "1.2",
label: "1.2.x",
},
]);
const selectValue = await page.$eval(
"#version",
(el: HTMLSelectElement) => el.value,
);
assertEquals(selectValue, "1.2");
// Go to canary page
await Promise.all([
page.waitForNavigation(),
page.select("#version", "canary"),
]);
await page.waitForSelector("#version:not([disabled])");
const selectValue2 = await page.$eval(
"#version",
(el: HTMLSelectElement) => el.value,
);
assertEquals(selectValue2, "canary");
assertEquals(page.url(), `${address}/docs/canary/introduction`);
});
});