-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
default.test.ts
53 lines (42 loc) · 1.43 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
52
53
import { assertEquals } from '../src/package_test.ts';
import { startServer, fetchWithClose, 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 fetchWithClose(baseUrl + '/home/query-name');
const r2 = await fetchWithClose(baseUrl + '/home/query-name/');
const r3 = await fetchWithClose(baseUrl + '/');
console.log("status", r1.status, r1.status,);
assertEquals(r1.status, 200);
assertEquals(r2.status, 404);
assertEquals(r3.status, 404);
}
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();
console.log("status", response.status);
assertEquals(response.status, 200);
assertEquals(text, "Hey! john")
}
finally {
killServer();
}
},
});