-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.test.ts
64 lines (46 loc) · 1.27 KB
/
server.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
63
64
import { Server, STUN_PORT } from "./server.ts";
import {
assertEquals,
assertExists,
} from "https://deno.land/std@0.144.0/testing/asserts.ts";
import { Temporal } from "./deps.ts";
// import {
// describe,
// it,
// beforeEach,
// afterEach,
// } from "https://deno.land/std@0.144.0/testing/bdd.ts";
Deno.test("test Server", async (t) => {
const server = new Server();
server.start();
await t.step("server exists", () => {
assertExists(server);
});
await t.step("connect to server", async () => {
const conn = await Deno.connect({ port: STUN_PORT });
const text = Temporal.Now.instant().toLocaleString();
const encoder = new TextEncoder();
const decoder = new TextDecoder();
// console.log(sample.byteLength);
await conn.write(encoder.encode(text));
let buf = new Uint8Array(32 * 1024);
const n = (await conn.read(buf)) ?? 0;
buf = buf.slice(0, n);
assertEquals(text, decoder.decode(buf));
conn.close();
});
server.stop();
});
// describe("Server", () => {
// const server = new Server();
// beforeEach(() => {
// server.start();
// });
// afterEach(() => {
// server.stop();
// });
// it("should exist", () => {
// assertExists(server);
// });
// });
// Deno.test("test", () => {});