refactor: add integrationTest() helper to reduce test boilerplate (#3711)
## Summary - Adds an `integrationTest()` wrapper in `packages/fresh/src/test_utils.ts` that calls `Deno.test` with `sanitizeOps: false` and `sanitizeResources: false` - Converts ~88 integration tests across 5 files to use the new helper, removing repetitive sanitizer boilerplate - Net reduction of ~344 lines (-1678/+1334) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
196509274f
commit
a872a70e5f
+68
-74
@@ -8,6 +8,7 @@ import {
|
||||
buildVite,
|
||||
launchProd,
|
||||
} from "../packages/plugin-vite/tests/test_utils.ts";
|
||||
import { integrationTest } from "../packages/fresh/src/test_utils.ts";
|
||||
|
||||
let result: Awaited<ReturnType<typeof buildVite>>;
|
||||
|
||||
@@ -19,87 +20,80 @@ Deno.test.afterAll(async () => {
|
||||
await result?.[Symbol.asyncDispose]();
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "CORS should not set on GET /fresh-badge.svg",
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
fn: async () => {
|
||||
integrationTest(
|
||||
"CORS should not set on GET /fresh-badge.svg",
|
||||
async () => {
|
||||
await launchProd({ cwd: result.tmp }, 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",
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
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");
|
||||
integrationTest("shows version selector", 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";
|
||||
});
|
||||
// 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";
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user