/
_mock_conn.ts
50 lines (49 loc) · 1.28 KB
/
_mock_conn.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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
/** Create dummy `Deno.Conn` object with given base properties. */
export function mockConn(base: Partial<Deno.Conn> = {}): Deno.Conn {
return {
localAddr: {
transport: "tcp",
hostname: "",
port: 0,
},
remoteAddr: {
transport: "tcp",
hostname: "",
port: 0,
},
rid: -1,
closeWrite: () => {
return Promise.resolve();
},
read: (): Promise<number | null> => {
return Promise.resolve(0);
},
write: (): Promise<number> => {
return Promise.resolve(-1);
},
close: (): void => {},
readable: new ReadableStream({
type: "bytes",
async pull(_controller) {
},
cancel() {
},
autoAllocateChunkSize: 1,
}),
writable: new WritableStream({
async write(_chunk, _controller) {
},
close() {
},
abort() {
},
}),
// TODO(ry) Remove the following ts-ignore.
// @ts-ignore This was added to workaround incompatibilities between Deno versions.
setNoDelay: (_nodelay?: boolean): void => {},
// @ts-ignore This was added to workaround incompatibilities between Deno versions.
setKeepAlive: (_keepalive?: boolean): void => {},
...base,
};
}