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
+5 -27
View File
@@ -1,6 +1,7 @@
import { assert, delay, puppeteer, TextLineStream } from "./deps.ts";
import { assert, delay, puppeteer } from "./deps.ts";
import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
import { startFreshServer } from "./test_utils.ts";
/**
* Start the server with the main file.
@@ -8,34 +9,10 @@ import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
* Returns a page instance and a method to terminate the server.
*/
async function setUpServer(path: string) {
const serverProcessCmd = new Deno.Command("deno", {
args: [
"run",
"-A",
path,
],
stdout: "piped",
stderr: "inherit",
const { lines, serverProcess } = await startFreshServer({
args: ["run", "-A", path],
});
const serverProcess = serverProcessCmd.spawn();
const lines = serverProcess.stdout
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream());
let started = false;
for await (const line of lines) {
if (line.includes("Listening on http://")) {
started = true;
break;
}
}
if (!started) {
throw new Error("Server didn't start up");
}
await delay(100);
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
@@ -45,6 +22,7 @@ async function setUpServer(path: string) {
* terminate server
*/
const terminate = async () => {
await lines.cancel();
await browser.close();
serverProcess.kill("SIGKILL");