chore(test): extract shared start server code (#1250)

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
Marvin Hagemeister
2023-06-05 18:52:22 +02:00
committed by GitHub
parent da5d507b77
commit cd760b90d4
3 changed files with 45 additions and 149 deletions
+28
View File
@@ -0,0 +1,28 @@
import { TextLineStream } from "./deps.ts";
export async function startFreshServer(options: Deno.CommandOptions) {
const serverProcess = new Deno.Command(Deno.execPath(), {
...options,
stdin: "null",
stdout: "piped",
stderr: "inherit",
}).spawn();
const decoder = new TextDecoderStream();
const lines: ReadableStream<string> = serverProcess.stdout
.pipeThrough(decoder)
.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");
}
return { serverProcess, lines };
}