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 { startFreshServer, withPageName } from "./test_utils.ts";
import {
assertTextMany,
fetchHtml,
withFresh,
withPageName,
} from "./test_utils.ts";
import { Status } from "../server.ts";
Deno.test({
name: "render async server component",
async fn() {
await withPageName(
await withFresh(
"./tests/fixture_server_components/main.ts",
async (page, address) => {
await page.goto(`${address}/basic`);
await page.waitForSelector("h1");
const text = await page.$eval("h1", (el) => el.textContent);
assertEquals(text, "it works");
async (address) => {
const doc = await fetchHtml(`${address}/basic`);
assertTextMany(doc, "h1", ["it works"]);
},
);
},
@@ -26,12 +28,11 @@ Deno.test({
name: "uses returned response",
async fn() {
await withPageName(
await withFresh(
"./tests/fixture_server_components/main.ts",
async (page, address) => {
await page.goto(`${address}/response`);
const text = await page.$eval("body", (el) => el.textContent);
async (address) => {
const res = await fetch(`${address}/response`);
const text = await res.text();
assertEquals(text, "it works");
},
);
@@ -69,10 +70,9 @@ Deno.test({
name: "passes context to server component",
async fn() {
const { lines, serverProcess, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture_server_components/main.ts"],
});
await withFresh(
"./tests/fixture_server_components/main.ts",
async (address) => {
const res = await fetch(`${address}/context/foo`);
const json = await res.json();
@@ -103,9 +103,8 @@ Deno.test({
state: {},
},
);
await lines.cancel();
serverProcess.kill("SIGTERM");
await serverProcess.status;
},
);
},
sanitizeOps: false,
@@ -116,19 +115,16 @@ Deno.test({
name: "can call context.renderNotFound()",
async fn() {
const { lines, serverProcess, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture_server_components/main.ts"],
});
await withFresh(
"./tests/fixture_server_components/main.ts",
async (address) => {
const res = await fetch(`${address}/fail`);
assertEquals(res.status, Status.NotFound);
const html = await res.text();
assertEquals(html, "Not found.");
await lines.cancel();
serverProcess.kill("SIGTERM");
await serverProcess.status;
},
);
},
sanitizeOps: false,