-
Notifications
You must be signed in to change notification settings - Fork 754
Expand file tree
/
Copy pathmain_test.ts
More file actions
93 lines (81 loc) · 2.92 KB
/
Copy pathmain_test.ts
File metadata and controls
93 lines (81 loc) · 2.92 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
import {
withBrowser,
withChildProcessServer,
} from "../packages/fresh/tests/test_utils.tsx";
import { expect } from "@std/expect";
import { retry } from "@std/async/retry";
import { buildVite } from "../packages/plugin-vite/tests/test_utils.ts";
const result = await buildVite(import.meta.dirname!);
Deno.test("CORS should not set on GET /fresh-badge.svg", async () => {
await withChildProcessServer(
{
cwd: result.tmp,
args: ["serve", "-A", "--port", "0", ".fresh/server.js"],
},
async (address) => {
const resp = await fetch(`${address}/fresh-badge.svg`);
await resp?.body?.cancel();
expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null);
},
);
});
Deno.test({
name: "shows version selector",
fn: async () => {
await retry(async () => {
await withChildProcessServer(
{
cwd: result.tmp,
args: ["serve", "-A", "--port", "0", ".fresh/server.js"],
},
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/docs`);
await page.waitForSelector("#version");
// Check that we redirected to the first page
await page.waitForFunction(() => {
const url = new URL(window.location.href);
return url.pathname === "/docs/introduction";
});
// Wait for version selector to be enabled
await page.waitForSelector("#version:not([disabled])");
const options = await page
.locator<HTMLSelectElement>("#version")
.evaluate((el) => {
return Array.from(el.options).map((option) => ({
value: option.value,
label: option.textContent,
}));
});
expect(options.map((item) => item.value)).toEqual([
"latest",
"1.x",
]);
const selectValue = await page
.locator<HTMLSelectElement>("#version")
.evaluate((el) => el.value);
expect(selectValue).toEqual("latest");
// Go to canary page
await page.evaluate(() => {
const el = document.querySelector(
"#version",
) as HTMLSelectElement;
el.value = "1.x";
el.dispatchEvent(new Event("change"));
});
await new Promise((r) => setTimeout(r, 1000));
await page.waitForSelector("#version:not([disabled])");
const selectValue2 = await page
.locator<HTMLSelectElement>("#version")
.evaluate((el) => el.value);
expect(selectValue2).toEqual("1.x");
await page.waitForFunction(() => {
const url = new URL(window.location.href);
return url.pathname === "/docs/1.x/introduction";
});
});
},
);
});
},
});