-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.d.ts
103 lines (86 loc) · 3.11 KB
/
index.d.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
declare module 'superwstest' {
import type { Server } from 'net';
import type { ClientRequestArgs, IncomingMessage } from 'http';
import type { WebSocket, ClientOptions, WebSocketServer } from 'ws';
import type { SuperTest, Test } from 'supertest';
type JsonObject = { [member: string]: JsonValue };
interface JsonArray extends Array<JsonValue> {}
type JsonValue = JsonObject | JsonArray | string | number | boolean | null;
export interface ReceivedMessage {
data: Buffer;
isBinary: boolean;
}
export interface ExpectMessageOptions {
timeout?: number | undefined;
}
export interface RequestOptions {
shutdownDelay?: number | undefined;
defaultExpectOptions?: ExpectMessageOptions | undefined;
}
export interface WSChain extends Promise<WebSocket> {
set(header: string, value: string): this;
set(header: Record<string, string>): this;
unset(header: string): this;
send(
message: any,
options?:
| {
mask?: boolean | undefined;
binary?: boolean | undefined;
compress?: boolean | undefined;
fin?: boolean | undefined;
}
| undefined,
): this;
sendText(message: any): this;
sendJson(message: JsonValue): this;
sendBinary(message: Uint8Array | Buffer | ArrayBuffer | number[]): this;
wait(milliseconds: number): this;
exec(fn: (ws: WebSocket) => Promise<unknown> | void): this;
expectMessage<T>(
conversion: (received: ReceivedMessage) => T,
expected?: T | ((message: T) => boolean | void) | null | undefined,
options?: ExpectMessageOptions | undefined,
): this;
expectText(
expected?: string | RegExp | ((message: string) => boolean | void) | undefined,
options?: ExpectMessageOptions | undefined,
): this;
expectJson(
expected?: JsonValue | ((message: any) => boolean | void) | undefined,
options?: ExpectMessageOptions | undefined,
): this;
expectBinary(
expected?:
| Uint8Array
| Buffer
| ArrayBuffer
| number[]
| ((message: Uint8Array) => boolean | void)
| undefined,
options?: ExpectMessageOptions | undefined,
): this;
close(code?: number | undefined, reason?: string | undefined): this;
expectClosed(
expectedCode?: number | null | undefined,
expectedReason?: string | null | undefined,
): this;
expectUpgrade(test: (upgradeResponse: IncomingMessage) => boolean | void): this;
expectConnectionError(expectedCode?: number | string | null | undefined): Promise<WebSocket>;
}
export interface SuperWSTest extends SuperTest<Test> {
ws(path: string, options?: ClientOptions | ClientRequestArgs | undefined): WSChain;
ws(
path: string,
protocols?: string | string[] | undefined,
options?: ClientOptions | ClientRequestArgs | undefined,
): WSChain;
}
interface SuperWSRequest {
(app: Server | WebSocketServer | string, options?: RequestOptions | undefined): SuperWSTest;
scoped(): SuperWSRequest;
closeAll(): void;
}
const request: SuperWSRequest;
export default request;
}