-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
default.test.ts
51 lines (44 loc) · 1.36 KB
/
default.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
import { assertEquals } from "../src/deps_test.ts";
import { startServer, killServer } from "./test.utils.ts";
const { test } = Deno;
/**
* Test cases
*/
test({
name: "[http] default server should response 200, 404",
async fn(): Promise<void> {
await startServer("./examples/default/app.ts");
const baseUrl = "http://localhost:8000";
try {
const r1 = await fetch(baseUrl + "/home/query-name");
const r2 = await fetch(baseUrl + "/home/query-name/");
const r3 = await fetch(baseUrl + "/");
const text_r1 = await r1.text();
const text_r2 = await r2.text();
const text_r3 = await r3.text();
assertEquals(r1.status, 200);
assertEquals(r2.status, 404);
assertEquals(r3.status, 200);
assertEquals(text_r1, "Hey! undefined");
assertEquals(text_r2, "Not found");
assertEquals(text_r3, "Hello world");
} finally {
killServer();
}
},
});
test({
name: "[http] default server should response with query",
async fn(): Promise<void> {
await startServer("./examples/default/app.ts");
const baseUrl = "http://localhost:8000";
try {
const response = await fetch(baseUrl + "/home/query-name?name=john");
const text = await response.text();
assertEquals(response.status, 200);
assertEquals(text, "Hey! john");
} finally {
killServer();
}
},
});