major: import Fresh 2.0 code (#2449)

🎉
This commit is contained in:
Marvin Hagemeister
2024-05-24 09:40:08 +02:00
committed by GitHub
parent 990357629e
commit 287929e4d2
958 changed files with 15794 additions and 28287 deletions
+66 -56
View File
@@ -1,71 +1,81 @@
import { assertArrayIncludes, assertEquals } from "$std/assert/mod.ts";
import { withPageName } from "../tests/test_utils.ts";
import { dirname, join } from "$std/path/mod.ts";
import VERSIONS from "../versions.json" with { type: "json" };
import { createHandler } from "../server.ts";
import manifest from "./fresh.gen.ts";
import config from "./fresh.config.ts";
import { app } from "./main.ts";
import { buildProd, withBrowserApp } from "../tests/test_utils.tsx";
import { expect } from "@std/expect";
const dir = dirname(import.meta.url);
const handler = await createHandler(manifest, config);
const handler = await app.handler();
Deno.test("CORS should not set on GET /fresh-badge.svg", async () => {
const req = new Request("http://localhost/fresh-badge.svg");
await buildProd(app);
const resp = await handler(req);
await resp?.body?.cancel();
assertEquals(resp.headers.get("cross-origin-resource-policy"), null);
expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null);
});
Deno.test("shows version selector", async () => {
await withPageName(join(dir, "./main.ts"), async (page, address) => {
await page.goto(`${address}/docs`);
await page.waitForSelector("#version");
Deno.test({
name: "shows version selector",
fn: async () => {
await withBrowserApp(app, 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`);
// 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])");
// 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,
}));
const options = await page
.locator<HTMLSelectElement>("#version")
.evaluate((el) => {
return Array.from(el.options).map((option) => ({
value: option.value,
label: option.textContent,
}));
});
expect(options).toEqual([
{
value: "canary",
label: "canary",
},
{
value: "latest",
label: VERSIONS[0],
},
]);
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 = "canary";
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("canary");
await page.waitForFunction(() => {
const url = new URL(window.location.href);
return url.pathname === "/docs/canary/introduction";
});
});
assertEquals(options.length, 2);
assertArrayIncludes(options, [
{
value: "canary",
label: "canary",
},
{
value: "latest",
label: VERSIONS[0],
},
]);
const selectValue = await page.$eval(
"#version",
(el: HTMLSelectElement) => el.value,
);
assertEquals(selectValue, "latest");
// 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`);
});
},
sanitizeOps: false,
sanitizeResources: false,
});