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 -22
View File
@@ -1,32 +1,13 @@
import { assertEquals } from "$std/testing/asserts.ts";
import { TextLineStream } from "$std/streams/text_line_stream.ts";
import { delay } from "$std/async/delay.ts";
import { startFreshServer } from "../tests/test_utils.ts";
Deno.test("CORS should not set on GET /fresh-badge.svg", {
sanitizeResources: false,
}, async () => {
const serverProcess = new Deno.Command(Deno.execPath(), {
const { serverProcess, lines } = await startFreshServer({
args: ["run", "-A", "./main.ts"],
stdin: "null",
stdout: "piped",
stderr: "inherit",
}).spawn();
const decoder = new TextDecoderStream();
const lines = 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");
}
});
const res = await fetch("http://localhost:8000/fresh-badge.svg");
await res.body?.cancel();