-
Notifications
You must be signed in to change notification settings - Fork 17
/
static_test.ts
62 lines (56 loc) · 1.26 KB
/
static_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
50
51
52
53
54
55
56
57
58
59
60
61
62
import { assertEquals } from "./vendor/https/deno.land/std/testing/asserts.ts";
import { App } from "./mod.ts";
const testPort = 8376;
const host = `http://localhost:${testPort}`;
interface testCase {
name: string;
path: string;
expected: string;
}
const testCases: Array<testCase> = [
{
name: "valid normal path",
path: "index.js",
expected: "ok",
},
{
name: "valid index path",
path: "",
expected: "ok",
},
{
name: "valid nested normal path",
path: "nested/index.js",
expected: "ok",
},
{
name: "valid nested index path",
path: "nested",
expected: "ok",
},
{
name: "invalid not found",
path: "nonExistencePath",
expected: "not found",
},
{
name: "invalid parent path",
path: "../static_test.ts",
expected: "not found",
},
];
for (const tc of testCases) {
Deno.test({
name: tc.name,
async fn() {
const app = new App(testPort, true, "testdata/static");
app.serve();
const res = await fetch(`${host}/${tc.path}`);
const actual = await res.text();
const contentLength = res.headers.get("content-length");
assertEquals(actual, tc.expected);
assertEquals(contentLength, tc.expected.length.toString());
app.close();
},
});
}