chore: speed up server component tests (#1596)
This commit is contained in:
@@ -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,43 +70,41 @@ 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 json = await res.json();
|
||||||
|
|
||||||
const res = await fetch(`${address}/context/foo`);
|
assertEquals(typeof json.localAddr, "object");
|
||||||
const json = await res.json();
|
assertEquals(typeof json.remoteAddr, "object");
|
||||||
|
json.localAddr.port = 8000;
|
||||||
|
json.remoteAddr.port = 8000;
|
||||||
|
|
||||||
assertEquals(typeof json.localAddr, "object");
|
assertEquals(
|
||||||
assertEquals(typeof json.remoteAddr, "object");
|
json,
|
||||||
json.localAddr.port = 8000;
|
{
|
||||||
json.remoteAddr.port = 8000;
|
localAddr: {
|
||||||
|
hostname: "localhost",
|
||||||
assertEquals(
|
port: 8000,
|
||||||
json,
|
transport: "tcp",
|
||||||
{
|
},
|
||||||
localAddr: {
|
remoteAddr: {
|
||||||
hostname: "localhost",
|
hostname: "localhost",
|
||||||
port: 8000,
|
port: 8000,
|
||||||
transport: "tcp",
|
transport: "tcp",
|
||||||
},
|
},
|
||||||
remoteAddr: {
|
renderNotFound: "AsyncFunction",
|
||||||
hostname: "localhost",
|
url: `${address}/context/foo`,
|
||||||
port: 8000,
|
route: "/context/:id",
|
||||||
transport: "tcp",
|
params: {
|
||||||
},
|
id: "foo",
|
||||||
renderNotFound: "AsyncFunction",
|
},
|
||||||
url: `${address}/context/foo`,
|
state: {},
|
||||||
route: "/context/:id",
|
},
|
||||||
params: {
|
);
|
||||||
id: "foo",
|
|
||||||
},
|
|
||||||
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);
|
||||||
|
const html = await res.text();
|
||||||
assertEquals(res.status, Status.NotFound);
|
assertEquals(html, "Not found.");
|
||||||
const html = await res.text();
|
},
|
||||||
assertEquals(html, "Not found.");
|
);
|
||||||
|
|
||||||
await lines.cancel();
|
|
||||||
serverProcess.kill("SIGTERM");
|
|
||||||
await serverProcess.status;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user