chore: speed up some tests (#1630)
This commit is contained in:
@@ -490,6 +490,9 @@ Deno.test({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sanitizeOps: false,
|
||||||
|
sanitizeResources: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
|
|||||||
+47
-81
@@ -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,41 +854,21 @@ 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,
|
await t.step("SSR error is shown", async () => {
|
||||||
}, async (t) => {
|
const resp = await fetch(address);
|
||||||
// Preparation
|
assertEquals(resp.status, Status.InternalServerError);
|
||||||
const { serverProcess, lines, address } = await startFreshServer({
|
const text = await resp.text();
|
||||||
args: ["run", "-A", "./tests/fixture_custom_500/main.ts"],
|
assertStringIncludes(text, "Custom 500: Pickle Rick!");
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("error page is shown with error message", async () => {
|
||||||
|
const doc = await fetchHtml(address);
|
||||||
|
const text = doc.querySelector(".custom-500")?.textContent!;
|
||||||
|
assertStringIncludes(text, "Custom 500: Pickle Rick!");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await delay(100);
|
|
||||||
|
|
||||||
await t.step("SSR error is shown", async () => {
|
|
||||||
const resp = await fetch(address);
|
|
||||||
assertEquals(resp.status, Status.InternalServerError);
|
|
||||||
const text = await resp.text();
|
|
||||||
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 () => {
|
|
||||||
const el = await page.waitForSelector(".custom-500");
|
|
||||||
const text = await page.evaluate((el) => el.textContent, el);
|
|
||||||
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,59 +882,41 @@ 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) => {
|
||||||
|
// Check that we can navigate to the page
|
||||||
|
const doc = await fetchHtml(`${address}/umlaut-äöüß`);
|
||||||
|
assertSelector(doc, "h1");
|
||||||
|
assertTextMany(doc, "h1", ["it works"]);
|
||||||
|
|
||||||
async fn() {
|
// Check the manifest
|
||||||
await withPageName("./tests/fixture/main.ts", async (page, address) => {
|
const mod = (await import("./fixture/fresh.gen.ts")).default;
|
||||||
// Check that we can navigate to the page
|
|
||||||
await page.goto(`${address}/umlaut-äöüß`);
|
|
||||||
await page.waitForSelector("h1");
|
|
||||||
const text = await page.$eval("h1", (el) => el.textContent);
|
|
||||||
assertEquals(text, "it works");
|
|
||||||
|
|
||||||
// Check the manifest
|
assert(
|
||||||
const mod = (await import("./fixture/fresh.gen.ts")).default;
|
"./routes/umlaut-äöüß.tsx" in mod.routes,
|
||||||
|
"Umlaut route not found",
|
||||||
assert(
|
);
|
||||||
"./routes/umlaut-äöüß.tsx" in mod.routes,
|
});
|
||||||
"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) => {
|
new Set(
|
||||||
await page.goto(address);
|
Array.from(doc.querySelectorAll("[nonce]")).map((el) =>
|
||||||
await page.waitForSelector("p");
|
el.getAttribute("nonce")
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
const nonceValues = await page.evaluate(() =>
|
assertEquals(
|
||||||
Array.from(
|
nonceValues.length,
|
||||||
new Set(
|
1,
|
||||||
Array.from(document.querySelectorAll("[nonce]")).map((el) =>
|
`Found more than 1 nonce value per render`,
|
||||||
el.getAttribute("nonce")
|
);
|
||||||
),
|
});
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
nonceValues.length,
|
|
||||||
1,
|
|
||||||
`Found more than 1 nonce value per render`,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
sanitizeOps: false,
|
|
||||||
sanitizeResources: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
|
|||||||
Reference in New Issue
Block a user