chore(tests): use to spin up server (#1261)
This commit is contained in:
+3
-27
@@ -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>",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user