chore: speed up some tests (#1630)

This commit is contained in:
Marvin Hagemeister
2023-08-13 12:35:07 +02:00
committed by GitHub
parent 6a599dbed5
commit 563b61d849
2 changed files with 50 additions and 81 deletions
+3
View File
@@ -490,6 +490,9 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({
+19 -53
View File
@@ -12,9 +12,13 @@ import manifest from "./fixture/fresh.gen.ts";
import options from "./fixture/options.ts"; import options from "./fixture/options.ts";
import { BUILD_ID } from "../src/server/build_id.ts"; import { BUILD_ID } from "../src/server/build_id.ts";
import { import {
assertSelector,
assertTextMany,
fetchHtml,
parseHtml, parseHtml,
startFreshServer, startFreshServer,
waitForText, waitForText,
withFresh,
withPageName, withPageName,
} from "./test_utils.ts"; } from "./test_utils.ts";
@@ -850,17 +854,8 @@ Deno.test("throw on route export 'handlers' instead of 'handler'", {
assertMatch(text, /Did you mean "handler"\?/); assertMatch(text, /Did you mean "handler"\?/);
}); });
Deno.test("rendering custom _500.tsx page for default handlers", { Deno.test("rendering custom _500.tsx page for default handlers", async (t) => {
sanitizeOps: false, await withFresh("./tests/fixture_custom_500/main.ts", async (address) => {
sanitizeResources: false,
}, async (t) => {
// Preparation
const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture_custom_500/main.ts"],
});
await delay(100);
await t.step("SSR error is shown", async () => { await t.step("SSR error is shown", async () => {
const resp = await fetch(address); const resp = await fetch(address);
assertEquals(resp.status, Status.InternalServerError); assertEquals(resp.status, Status.InternalServerError);
@@ -868,23 +863,12 @@ Deno.test("rendering custom _500.tsx page for default handlers", {
assertStringIncludes(text, "Custom 500: Pickle Rick!"); assertStringIncludes(text, "Custom 500: Pickle Rick!");
}); });
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
const page = await browser.newPage();
await page.goto(address, {
waitUntil: "networkidle2",
});
await t.step("error page is shown with error message", async () => { await t.step("error page is shown with error message", async () => {
const el = await page.waitForSelector(".custom-500"); const doc = await fetchHtml(address);
const text = await page.evaluate((el) => el.textContent, el); const text = doc.querySelector(".custom-500")?.textContent!;
assertStringIncludes(text, "Custom 500: Pickle Rick!"); assertStringIncludes(text, "Custom 500: Pickle Rick!");
}); });
});
await browser.close();
await lines.cancel();
serverProcess.kill("SIGTERM");
}); });
Deno.test("renders error boundary", { Deno.test("renders error boundary", {
@@ -898,16 +882,12 @@ Deno.test("renders error boundary", {
}); });
}); });
Deno.test({ Deno.test("Resolves routes with non-latin characters", async () => {
name: "Resolves routes with non-latin characters", await withFresh("./tests/fixture/main.ts", async (address) => {
async fn() {
await withPageName("./tests/fixture/main.ts", async (page, address) => {
// Check that we can navigate to the page // Check that we can navigate to the page
await page.goto(`${address}/umlaut-äöüß`); const doc = await fetchHtml(`${address}/umlaut-äöüß`);
await page.waitForSelector("h1"); assertSelector(doc, "h1");
const text = await page.$eval("h1", (el) => el.textContent); assertTextMany(doc, "h1", ["it works"]);
assertEquals(text, "it works");
// Check the manifest // Check the manifest
const mod = (await import("./fixture/fresh.gen.ts")).default; const mod = (await import("./fixture/fresh.gen.ts")).default;
@@ -917,28 +897,18 @@ Deno.test({
"Umlaut route not found", "Umlaut route not found",
); );
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test("Generate a single nonce value per page", async () => {
name: "Generate a single nonce value per page", await withFresh("./tests/fixture/main.ts", async (address) => {
const doc = await fetchHtml(address);
async fn() { const nonceValues = Array.from(
await withPageName("./tests/fixture/main.ts", async (page, address) => {
await page.goto(address);
await page.waitForSelector("p");
const nonceValues = await page.evaluate(() =>
Array.from(
new Set( new Set(
Array.from(document.querySelectorAll("[nonce]")).map((el) => Array.from(doc.querySelectorAll("[nonce]")).map((el) =>
el.getAttribute("nonce") el.getAttribute("nonce")
), ),
), ),
)
); );
assertEquals( assertEquals(
@@ -947,10 +917,6 @@ Deno.test({
`Found more than 1 nonce value per render`, `Found more than 1 nonce value per render`,
); );
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ Deno.test({