chore: speed up server component tests (#1596)

This commit is contained in:
Marvin Hagemeister
2023-08-07 14:49:07 +02:00
committed by GitHub
parent a489aff190
commit d8211dad28
+24 -28
View File
@@ -1,19 +1,21 @@
import { assertEquals } from "./deps.ts"; import { assertEquals } from "./deps.ts";
import { startFreshServer, withPageName } from "./test_utils.ts"; import {
assertTextMany,
fetchHtml,
withFresh,
withPageName,
} from "./test_utils.ts";
import { Status } from "../server.ts"; import { Status } from "../server.ts";
Deno.test({ Deno.test({
name: "render async server component", name: "render async server component",
async fn() { async fn() {
await withPageName( await withFresh(
"./tests/fixture_server_components/main.ts", "./tests/fixture_server_components/main.ts",
async (page, address) => { async (address) => {
await page.goto(`${address}/basic`); const doc = await fetchHtml(`${address}/basic`);
assertTextMany(doc, "h1", ["it works"]);
await page.waitForSelector("h1");
const text = await page.$eval("h1", (el) => el.textContent);
assertEquals(text, "it works");
}, },
); );
}, },
@@ -26,12 +28,11 @@ Deno.test({
name: "uses returned response", name: "uses returned response",
async fn() { async fn() {
await withPageName( await withFresh(
"./tests/fixture_server_components/main.ts", "./tests/fixture_server_components/main.ts",
async (page, address) => { async (address) => {
await page.goto(`${address}/response`); const res = await fetch(`${address}/response`);
const text = await res.text();
const text = await page.$eval("body", (el) => el.textContent);
assertEquals(text, "it works"); assertEquals(text, "it works");
}, },
); );
@@ -69,10 +70,9 @@ Deno.test({
name: "passes context to server component", name: "passes context to server component",
async fn() { async fn() {
const { lines, serverProcess, address } = await startFreshServer({ await withFresh(
args: ["run", "-A", "./tests/fixture_server_components/main.ts"], "./tests/fixture_server_components/main.ts",
}); async (address) => {
const res = await fetch(`${address}/context/foo`); const res = await fetch(`${address}/context/foo`);
const json = await res.json(); const json = await res.json();
@@ -103,9 +103,8 @@ Deno.test({
state: {}, state: {},
}, },
); );
await lines.cancel(); },
serverProcess.kill("SIGTERM"); );
await serverProcess.status;
}, },
sanitizeOps: false, sanitizeOps: false,
@@ -116,19 +115,16 @@ Deno.test({
name: "can call context.renderNotFound()", name: "can call context.renderNotFound()",
async fn() { async fn() {
const { lines, serverProcess, address } = await startFreshServer({ await withFresh(
args: ["run", "-A", "./tests/fixture_server_components/main.ts"], "./tests/fixture_server_components/main.ts",
}); async (address) => {
const res = await fetch(`${address}/fail`); const res = await fetch(`${address}/fail`);
assertEquals(res.status, Status.NotFound); assertEquals(res.status, Status.NotFound);
const html = await res.text(); const html = await res.text();
assertEquals(html, "Not found."); assertEquals(html, "Not found.");
},
await lines.cancel(); );
serverProcess.kill("SIGTERM");
await serverProcess.status;
}, },
sanitizeOps: false, sanitizeOps: false,