chore(tests): use to spin up server (#1261)

This commit is contained in:
Marvin Hagemeister
2023-06-09 11:27:56 +02:00
committed by GitHub
parent 5724b73e71
commit 894f56b9c9
5 changed files with 18 additions and 117 deletions
+3 -27
View File
@@ -5,8 +5,8 @@ import {
delay,
Page,
puppeteer,
TextLineStream,
} from "./deps.ts";
import { startFreshServer } from "./test_utils.ts";
Deno.test({
name: "island tests",
@@ -64,24 +64,11 @@ function withPage(fn: (page: Page) => Promise<void>) {
}
async function withPageName(name: string, fn: (page: Page) => Promise<void>) {
const serverProcess = new Deno.Command(Deno.execPath(), {
const { lines, serverProcess } = await startFreshServer({
args: ["run", "-A", name],
stdout: "piped",
stderr: "inherit",
}).spawn();
const textDecoderStream = new TextDecoderStream();
const textLineStream = new TextLineStream();
const lines = serverProcess.stdout
.pipeThrough(textDecoderStream)
.pipeThrough(textLineStream);
});
try {
if (!await didServerStart(lines)) {
throw new Error("Server didn't start up");
}
await delay(100);
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
@@ -101,17 +88,6 @@ async function withPageName(name: string, fn: (page: Page) => Promise<void>) {
}
}
async function didServerStart(
stdoutLines: ReadableStream<string>,
): Promise<boolean> {
for await (const line of stdoutLines) {
if (line.includes("Listening on http://")) {
return true;
}
}
return false;
}
Deno.test({
name: "island tests with </script>",