-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.ts
40 lines (34 loc) · 1.08 KB
/
main_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { assertEquals } from "$std/testing/asserts.ts";
import { TextLineStream } from "$std/streams/text_line_stream.ts";
import { delay } from "$std/async/delay.ts";
Deno.test("CORS should not set on GET /fresh-badge.svg", {
sanitizeResources: false,
}, async () => {
const serverProcess = new Deno.Command(Deno.execPath(), {
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();
assertEquals(res.headers.get("cross-origin-resource-policy"), null);
await lines.cancel();
serverProcess.kill("SIGTERM");
// await for the server to close
await delay(100);
});