forked from oakserver/oak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_server_native_test.ts
More file actions
46 lines (40 loc) · 1.22 KB
/
http_server_native_test.ts
File metadata and controls
46 lines (40 loc) · 1.22 KB
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
// Copyright 2018-2021 the oak authors. All rights reserved. MIT license.
import { assertEquals, assertStrictEquals } from "./test_deps.ts";
import { hasNativeHttp, NativeRequest } from "./http_server_native.ts";
const { test } = Deno;
function createMockConn() {
return {
localAddr: { transport: "tcp", hostname: "localhost", port: 8000 },
remoteAddr: { transport: "tcp", hostname: "remote", port: 4567 },
rid: 1,
} as Deno.Conn;
}
test({
name: "hasNativeHttp()",
fn() {
assertEquals(hasNativeHttp(), "serveHttp" in Deno);
},
});
test({
name: "NativeRequest",
async fn() {
const respondWithStack: Array<Response | Promise<Response>> = [];
const request = new Request("http://localhost:8000/", {
method: "POST",
body: `{"a":"b"}`,
});
const conn = createMockConn();
const nativeRequest = new NativeRequest({
request,
respondWith(v) {
respondWithStack.push(v);
return Promise.resolve();
},
}, { conn });
assertEquals(nativeRequest.url, `/`);
assertEquals(respondWithStack.length, 1);
const response = new Response("hello deno");
nativeRequest.respond(response);
assertStrictEquals(await respondWithStack[0], response);
},
});