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