-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
49 lines (45 loc) · 1.47 KB
/
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
41
42
43
44
45
46
47
48
49
import { assertEquals } from "https://deno.land/std@0.155.0/testing/asserts.ts";
import { flakyTest } from "https://deno.land/x/flaky_test@v1.0.2/mod.ts";
import { statusCodes } from "./src/status_code.ts";
import { earlyHintsResponse, withEarlyHints } from "./unstable.ts";
const nullBody = new Set([
"204",
"205",
"301",
"302",
"303",
"304",
"307",
"308",
]);
const statusCodeList = Object.keys(statusCodes);
for (const method of ["GET", "POST", "HEAD", "DELETE", "PUT"]) {
for (const status of statusCodeList) {
if (+status < 200) {
continue;
}
Deno.test({
name: `Method: ${method} / Status: ${status}`,
fn: flakyTest(async () => {
const body = nullBody.has(status) ? null : `[[status ${status}]]`;
const controller = new AbortController();
const serverPromise = Deno.serve(
withEarlyHints(function* (_request) {
yield earlyHintsResponse(["/style.css"]);
return new Response(body, { status: +status });
}),
{ signal: controller.signal, onListen: () => {} },
);
try {
const res = await fetch("http://127.0.0.1:9000/", { method });
const text = await res.text();
assertEquals(res.status.toString(), status.toString());
assertEquals(text, body == null || method === "HEAD" ? "" : body);
} finally {
controller.abort();
await serverPromise;
}
}, { count: 10 }),
});
}
}