deno.land / x / servest@v1.3.4 / _adapter_test.ts

_adapter_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
// Copyright 2019-2020 Yusuke Sakurai. All rights reserved. MIT license.import { BufReader, BufWriter } from "./vendor/https/deno.land/std/io/bufio.ts";import { assertEquals } from "./vendor/https/deno.land/std/testing/asserts.ts";import { classicAdapter, nativeAdapter } from "./_adapter.ts";import { group } from "./_test_util.ts";
group("adapter", ({ test }) => { async function doTest() { const resp = await fetch("http://localhost:8899", { method: "POST", body: "hello", }); assertEquals(resp.status, 200); assertEquals(resp.headers.get("content-type"), "text/html"); assertEquals(await resp.text(), "hello"); } test("classic", async () => { async function serve() { const l = Deno.listen({ port: 8899 }); const conn = await l.accept(); const bufReader = new BufReader(conn); const bufWriter = new BufWriter(conn); const adapter = classicAdapter({ conn, bufReader, bufWriter }); const req = await adapter.next({}); await adapter.respond({ status: 200, headers: new Headers({ "content-type": "text/html", }), body: req!.body, }); adapter.close(); l.close(); } serve(); await doTest(); }); test("native", async () => { async function serve() { const l = Deno.listen({ port: 8899 }); const conn = await l.accept(); const adapter = nativeAdapter(conn); const req = await adapter.next({}); await adapter.respond({ status: 200, headers: new Headers({ "content-type": "text/html", }), body: req!.body, }); adapter.close(); l.close(); } serve(); await doTest(); });});
servest

Version Info

Tagged at
2 years ago