mock-tls-server 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/index.js +14 -6
- package/package.json +5 -26
- package/types/index.d.ts +51 -51
- package/types/kernel.d.ts +7 -3
- package/types/net.d.ts +60 -60
- package/types/socket.d.ts +19 -7
- package/types/utils.d.ts +6 -6
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ import {MockTLSServer, connect} from 'mock-tls-server';
|
|
|
30
30
|
// Expected output: "Welcome!\nexample\n"
|
|
31
31
|
|
|
32
32
|
const server = new MockTLSServer();
|
|
33
|
-
server.listen(4000, sock => {
|
|
33
|
+
await server.listen(4000, sock => {
|
|
34
34
|
sock.write('Welcome!\n');
|
|
35
35
|
sock.pipe(sock);
|
|
36
36
|
});
|
|
@@ -77,7 +77,7 @@ import tls from 'node:tls';
|
|
|
77
77
|
const server = new MockTLSServer({
|
|
78
78
|
notBefore: new Date(new Date().getTime() + 10000), // Invalid because of time
|
|
79
79
|
});
|
|
80
|
-
server.listen();
|
|
80
|
+
await server.listen();
|
|
81
81
|
await pEvent(server, 'listening');
|
|
82
82
|
const socket = plainConnect(server.port);
|
|
83
83
|
tls.connect({
|
package/lib/index.js
CHANGED
|
@@ -42,6 +42,11 @@ export class MockTLSServer extends net.Server {
|
|
|
42
42
|
*/
|
|
43
43
|
#key;
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @type {Promise<void>|undefined}
|
|
47
|
+
*/
|
|
48
|
+
#init = undefined;
|
|
49
|
+
|
|
45
50
|
/** @type {string | Buffer | Array<string | Buffer> | undefined} */
|
|
46
51
|
ca;
|
|
47
52
|
|
|
@@ -74,6 +79,7 @@ export class MockTLSServer extends net.Server {
|
|
|
74
79
|
...tls_opts,
|
|
75
80
|
});
|
|
76
81
|
const temit = tsock.emit;
|
|
82
|
+
// @ts-expect-error Monkey patch
|
|
77
83
|
tsock.emit = (eventName, ...args) => {
|
|
78
84
|
log('tls', eventName, ...classNames(args));
|
|
79
85
|
// @ts-ignore
|
|
@@ -101,10 +107,11 @@ export class MockTLSServer extends net.Server {
|
|
|
101
107
|
const issueOpts = getIssueOptions(cert_opts);
|
|
102
108
|
issueOpts.temp = true;
|
|
103
109
|
issueOpts.mute = true;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
this.#init = authority.issueNew(issueOpts).then(serverProps => {
|
|
111
|
+
this.cert = serverProps.cert;
|
|
112
|
+
this.ca = serverProps.ca?.cert;
|
|
113
|
+
this.#key = serverProps.key;
|
|
114
|
+
});
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
if (local_opts.secureConnectionListener) {
|
|
@@ -120,16 +127,17 @@ export class MockTLSServer extends net.Server {
|
|
|
120
127
|
* @param {number|ListenOptions} [options] Port number or options object.
|
|
121
128
|
* @param {Function} [secureConnectionListener] If it exists, installed as
|
|
122
129
|
* a listener for the 'secureConnection' event.
|
|
123
|
-
* @returns {
|
|
130
|
+
* @returns {Promise<this>} This.
|
|
124
131
|
*/
|
|
125
132
|
// @ts-ignore TS2416: This is compatible-enough with the base class.
|
|
126
|
-
listen(options, secureConnectionListener) {
|
|
133
|
+
async listen(options, secureConnectionListener) {
|
|
127
134
|
const {port, secureConnectionListener: onConnect} =
|
|
128
135
|
normalizeArgs(options, {secureConnectionListener});
|
|
129
136
|
|
|
130
137
|
if (onConnect) {
|
|
131
138
|
this.on('secureConnection', onConnect);
|
|
132
139
|
}
|
|
140
|
+
await this.#init;
|
|
133
141
|
super.listen(port);
|
|
134
142
|
return this;
|
|
135
143
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mock-tls-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,13 +9,6 @@
|
|
|
9
9
|
"lib",
|
|
10
10
|
"types"
|
|
11
11
|
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"test": "c8 ava",
|
|
14
|
-
"lint": "eslint .",
|
|
15
|
-
"docs": "typedoc",
|
|
16
|
-
"types": "tsc",
|
|
17
|
-
"build": "npm run lint && npm run types && npm run docs && npm run test && npm pack --dry-run"
|
|
18
|
-
},
|
|
19
12
|
"keywords": [
|
|
20
13
|
"tls",
|
|
21
14
|
"ssl",
|
|
@@ -33,25 +26,11 @@
|
|
|
33
26
|
"license": "MIT",
|
|
34
27
|
"repository": "hildjj/mock-tls-server",
|
|
35
28
|
"dependencies": {
|
|
36
|
-
"@cto.af/ca": "
|
|
37
|
-
"@cto.af/utils": "
|
|
38
|
-
},
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@cto.af/eslint-config": "6.0.14",
|
|
41
|
-
"@eslint/markdown": "7.2.0",
|
|
42
|
-
"@types/jsrsasign": "10.5.15",
|
|
43
|
-
"@types/node": "24.5.2",
|
|
44
|
-
"ava": "6.4.1",
|
|
45
|
-
"c8": "10.1.3",
|
|
46
|
-
"eslint": "9.36.0",
|
|
47
|
-
"eslint-plugin-ava": "^15.1.0",
|
|
48
|
-
"eslint-plugin-jsdoc": "60.1.1",
|
|
49
|
-
"p-event": "7.0.0",
|
|
50
|
-
"typedoc": "0.28.13",
|
|
51
|
-
"typescript": "^5.9.2"
|
|
29
|
+
"@cto.af/ca": "4.0.2",
|
|
30
|
+
"@cto.af/utils": "2.0.1"
|
|
52
31
|
},
|
|
53
|
-
"packageManager": "pnpm@
|
|
32
|
+
"packageManager": "pnpm@12.15.0",
|
|
54
33
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
34
|
+
"node": ">=22"
|
|
56
35
|
}
|
|
57
36
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import * as net from './net.js';
|
|
2
|
+
import { CertificateAuthority } from '@cto.af/ca';
|
|
3
|
+
import tls from 'node:tls';
|
|
4
|
+
export type SecureConnectionCallback = (sock: tls.TLSSocket) => void;
|
|
5
|
+
export type LocalOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* A CA instance to use. If you
|
|
8
|
+
* are creating lots of servers, create one CA to pass into each of them, so
|
|
9
|
+
* that certs don't need to be created from scratch for each.
|
|
10
|
+
*/
|
|
11
|
+
authority?: CertificateAuthority;
|
|
12
|
+
/**
|
|
13
|
+
* Installed
|
|
14
|
+
* as a listener for the 'secureConnection' event.
|
|
15
|
+
*/
|
|
16
|
+
secureConnectionListener?: SecureConnectionCallback;
|
|
17
|
+
};
|
|
18
|
+
export type ServerOpts = LocalOptions & tls.TLSSocketOptions & import('@cto.af/ca').CertOptions & import('./net.js').ServerOpts;
|
|
19
|
+
export type ListenOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* The port to listen on.
|
|
22
|
+
*/
|
|
23
|
+
port: number;
|
|
24
|
+
/**
|
|
25
|
+
* If it exists,
|
|
26
|
+
* installed as a listener for the 'secureConnection' event.
|
|
27
|
+
*/
|
|
28
|
+
secureConnectionListener?: SecureConnectionCallback;
|
|
29
|
+
};
|
|
10
30
|
/**
|
|
11
31
|
* @typedef {(sock: tls.TLSSocket) => void} SecureConnectionCallback
|
|
12
32
|
*/
|
|
@@ -34,7 +54,11 @@ export function connect(options: tls.ConnectionOptions | number, secureListener?
|
|
|
34
54
|
/**
|
|
35
55
|
* A TLS server that mocks the network, but all of the crypto code is real.
|
|
36
56
|
*/
|
|
37
|
-
export class MockTLSServer extends net.Server {
|
|
57
|
+
export declare class MockTLSServer extends net.Server {
|
|
58
|
+
#private;
|
|
59
|
+
cert: string | (string | Buffer<ArrayBufferLike>)[] | Buffer<ArrayBufferLike> | undefined;
|
|
60
|
+
/** @type {string | Buffer | Array<string | Buffer> | undefined} */
|
|
61
|
+
ca: string | Buffer | Array<string | Buffer> | undefined;
|
|
38
62
|
/**
|
|
39
63
|
* Create a MockTLSServer instance.
|
|
40
64
|
*
|
|
@@ -43,9 +67,6 @@ export class MockTLSServer extends net.Server {
|
|
|
43
67
|
* a listener for the 'secureConnection' event.
|
|
44
68
|
*/
|
|
45
69
|
constructor(options?: ServerOpts | SecureConnectionCallback, secureConnectionListener?: SecureConnectionCallback);
|
|
46
|
-
/** @type {string | Buffer | Array<string | Buffer> | undefined} */
|
|
47
|
-
ca: string | Buffer | Array<string | Buffer> | undefined;
|
|
48
|
-
cert: string | Buffer<ArrayBufferLike> | (string | Buffer<ArrayBufferLike>)[] | undefined;
|
|
49
70
|
/**
|
|
50
71
|
* Listen for incoming connections. Whenever `connect` is called on this
|
|
51
72
|
* server's port, create a mock socket wrapped in a TLSSocket.
|
|
@@ -53,44 +74,23 @@ export class MockTLSServer extends net.Server {
|
|
|
53
74
|
* @param {number|ListenOptions} [options] Port number or options object.
|
|
54
75
|
* @param {Function} [secureConnectionListener] If it exists, installed as
|
|
55
76
|
* a listener for the 'secureConnection' event.
|
|
56
|
-
* @returns {
|
|
77
|
+
* @returns {Promise<this>} This.
|
|
57
78
|
*/
|
|
58
|
-
listen(options?: number | ListenOptions, secureConnectionListener?: Function):
|
|
59
|
-
#private;
|
|
60
|
-
}
|
|
61
|
-
export const plainConnect: typeof net.connect;
|
|
62
|
-
declare namespace _default {
|
|
63
|
-
export { MockTLSServer };
|
|
64
|
-
export { connect };
|
|
65
|
-
export { plainConnect };
|
|
79
|
+
listen(options?: number | ListenOptions, secureConnectionListener?: Function): Promise<this>;
|
|
66
80
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
82
|
-
export type ServerOpts = LocalOptions & tls.TLSSocketOptions & import("@cto.af/ca").CertOptions & import("./net.js").ServerOpts;
|
|
83
|
-
export type ListenOptions = {
|
|
84
|
-
/**
|
|
85
|
-
* The port to listen on.
|
|
86
|
-
*/
|
|
87
|
-
port: number;
|
|
88
|
-
/**
|
|
89
|
-
* If it exists,
|
|
90
|
-
* installed as a listener for the 'secureConnection' event.
|
|
91
|
-
*/
|
|
92
|
-
secureConnectionListener?: SecureConnectionCallback | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Create a client connection to a listening server.
|
|
83
|
+
*
|
|
84
|
+
* @param {tls.ConnectionOptions|number} options Port to connect to.
|
|
85
|
+
* @param {() => void} [secureListener] If specified, function is
|
|
86
|
+
* registered for the 'secure' event.
|
|
87
|
+
* @returns {tls.TLSSocket} Socket.
|
|
88
|
+
*/
|
|
89
|
+
export declare function connect(options: tls.ConnectionOptions | number, secureListener?: () => void): tls.TLSSocket;
|
|
90
|
+
export declare const plainConnect: typeof net.connect;
|
|
91
|
+
declare const _default: {
|
|
92
|
+
MockTLSServer: typeof MockTLSServer;
|
|
93
|
+
connect: typeof connect;
|
|
94
|
+
plainConnect: typeof net.connect;
|
|
93
95
|
};
|
|
94
|
-
|
|
95
|
-
import * as net from './net.js';
|
|
96
|
-
import { CertificateAuthority } from '@cto.af/ca';
|
|
96
|
+
export default _default;
|
package/types/kernel.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
export type EventEmitter = import('node:events').EventEmitter;
|
|
1
2
|
/**
|
|
2
3
|
* @typedef {import('node:events').EventEmitter} EventEmitter
|
|
3
4
|
*/
|
|
4
5
|
/**
|
|
5
6
|
* Simulate the bit of the OS kernel that uses port numbers to make endpoints.
|
|
6
7
|
*/
|
|
7
|
-
export class Kernel {
|
|
8
|
+
export declare class Kernel {
|
|
8
9
|
/** @type {Record<number, EventEmitter>} */
|
|
9
10
|
ports: Record<number, EventEmitter>;
|
|
10
11
|
/** @type {any} */
|
|
11
12
|
timer: any;
|
|
12
13
|
count: number;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of Kernel.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
13
18
|
/**
|
|
14
19
|
* Store the Server associated with a given port number in the kernel.
|
|
15
20
|
*
|
|
@@ -29,5 +34,4 @@ export class Kernel {
|
|
|
29
34
|
*/
|
|
30
35
|
lookup(port: number): EventEmitter;
|
|
31
36
|
}
|
|
32
|
-
export const globalKernel: Kernel;
|
|
33
|
-
export type EventEmitter = import("node:events").EventEmitter;
|
|
37
|
+
export declare const globalKernel: Kernel;
|
package/types/net.d.ts
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { MockSocket } from './socket.js';
|
|
3
|
+
export type DuplexStream = import('node:stream').Duplex;
|
|
4
|
+
export type SocketConnectOpts = {
|
|
5
|
+
/**
|
|
6
|
+
* Listening server port to connect to.
|
|
7
|
+
*/
|
|
8
|
+
port: number;
|
|
9
|
+
/**
|
|
10
|
+
* If set to false, then the
|
|
11
|
+
* socket will automatically end the writable side when the readable side
|
|
12
|
+
* ends.
|
|
13
|
+
*/
|
|
14
|
+
allowHalfOpen?: boolean;
|
|
15
|
+
connectListener?: SocketCallback;
|
|
16
|
+
};
|
|
17
|
+
export type ServerOpts = {
|
|
18
|
+
/**
|
|
19
|
+
* If set to false, then the
|
|
20
|
+
* socket will automatically end the writable side when the readable side
|
|
21
|
+
* ends.
|
|
22
|
+
*/
|
|
23
|
+
allowHalfOpen?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type ListenOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* The port to listen on.
|
|
28
|
+
*/
|
|
29
|
+
port: number;
|
|
30
|
+
/**
|
|
31
|
+
* If it exists, installed as
|
|
32
|
+
* a listener for the 'listening' event.
|
|
33
|
+
*/
|
|
34
|
+
listeningListener: () => void;
|
|
35
|
+
};
|
|
36
|
+
export type PlainCallback = () => void;
|
|
37
|
+
export type CountCallback = (err?: Error, count?: number) => void;
|
|
1
38
|
/**
|
|
2
39
|
* @typedef {import('node:stream').Duplex} DuplexStream
|
|
3
40
|
*/
|
|
@@ -42,30 +79,26 @@
|
|
|
42
79
|
* @returns {DuplexStream} The client side HalfSocket.
|
|
43
80
|
* @throws {TypeError} Invalid type for port.
|
|
44
81
|
*/
|
|
45
|
-
export function connect(options: number | (SocketConnectOpts & import(
|
|
82
|
+
export declare function connect(options: number | (SocketConnectOpts & import('node:stream').DuplexOptions), connectListener?: SocketCallback): DuplexStream;
|
|
46
83
|
/**
|
|
47
84
|
* Get the Server associated with a port.
|
|
48
85
|
*
|
|
49
86
|
* @param {SocketConnectOpts|number} options Port to look up.
|
|
50
87
|
* @returns {Server} The server that was found, or null if none found.
|
|
51
88
|
*/
|
|
52
|
-
export function getServer(options: SocketConnectOpts | number): Server;
|
|
53
|
-
|
|
54
|
-
* Creates an instance of Server.
|
|
55
|
-
*
|
|
56
|
-
* @param {ServerOpts|SocketCallback} [opts] Options for the server.
|
|
57
|
-
* @param {SocketCallback} [connectionListener] Register this as the event
|
|
58
|
-
* listener for the 'listening' event, if provided.
|
|
59
|
-
* @returns {Server} The created Server.
|
|
60
|
-
*/
|
|
61
|
-
export function createServer(opts?: ServerOpts | SocketCallback, connectionListener?: SocketCallback): Server;
|
|
89
|
+
export declare function getServer(options: SocketConnectOpts | number): Server;
|
|
90
|
+
export type SocketCallback = (socket: DuplexStream) => void;
|
|
62
91
|
/**
|
|
63
92
|
* @typedef {(socket: DuplexStream) => void} SocketCallback
|
|
64
93
|
*/
|
|
65
94
|
/**
|
|
66
95
|
* A mock server socket, more-or-less like net.Server.
|
|
67
96
|
*/
|
|
68
|
-
export class Server extends EventEmitter
|
|
97
|
+
export declare class Server extends EventEmitter {
|
|
98
|
+
clients: Set<any>;
|
|
99
|
+
port: number | null;
|
|
100
|
+
listening: boolean;
|
|
101
|
+
closing: boolean;
|
|
69
102
|
/**
|
|
70
103
|
* Creates an instance of Server.
|
|
71
104
|
*
|
|
@@ -74,10 +107,6 @@ export class Server extends EventEmitter<[never]> {
|
|
|
74
107
|
* listener for the 'listening' event, if provided.
|
|
75
108
|
*/
|
|
76
109
|
constructor(options?: ServerOpts | SocketCallback, connectionListener?: SocketCallback);
|
|
77
|
-
clients: Set<any>;
|
|
78
|
-
port: number | null;
|
|
79
|
-
listening: boolean;
|
|
80
|
-
closing: boolean;
|
|
81
110
|
/**
|
|
82
111
|
* Add debug logging to EventEmitter. Start with NODE_DEBUG=mock-tls-server
|
|
83
112
|
* to see all events.
|
|
@@ -128,48 +157,19 @@ export class Server extends EventEmitter<[never]> {
|
|
|
128
157
|
*/
|
|
129
158
|
getConnections(cb: CountCallback): Server;
|
|
130
159
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
export
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
* If set to false, then the
|
|
146
|
-
* socket will automatically end the writable side when the readable side
|
|
147
|
-
* ends.
|
|
148
|
-
*/
|
|
149
|
-
allowHalfOpen?: boolean | undefined;
|
|
150
|
-
connectListener?: SocketCallback | undefined;
|
|
151
|
-
};
|
|
152
|
-
export type ServerOpts = {
|
|
153
|
-
/**
|
|
154
|
-
* If set to false, then the
|
|
155
|
-
* socket will automatically end the writable side when the readable side
|
|
156
|
-
* ends.
|
|
157
|
-
*/
|
|
158
|
-
allowHalfOpen?: boolean | undefined;
|
|
159
|
-
};
|
|
160
|
-
export type ListenOptions = {
|
|
161
|
-
/**
|
|
162
|
-
* The port to listen on.
|
|
163
|
-
*/
|
|
164
|
-
port: number;
|
|
165
|
-
/**
|
|
166
|
-
* If it exists, installed as
|
|
167
|
-
* a listener for the 'listening' event.
|
|
168
|
-
*/
|
|
169
|
-
listeningListener: () => void;
|
|
160
|
+
/**
|
|
161
|
+
* Creates an instance of Server.
|
|
162
|
+
*
|
|
163
|
+
* @param {ServerOpts|SocketCallback} [opts] Options for the server.
|
|
164
|
+
* @param {SocketCallback} [connectionListener] Register this as the event
|
|
165
|
+
* listener for the 'listening' event, if provided.
|
|
166
|
+
* @returns {Server} The created Server.
|
|
167
|
+
*/
|
|
168
|
+
export declare function createServer(opts?: ServerOpts | SocketCallback, connectionListener?: SocketCallback): Server;
|
|
169
|
+
declare const _default: {
|
|
170
|
+
connect: typeof connect;
|
|
171
|
+
createServer: typeof createServer;
|
|
172
|
+
getServer: typeof getServer;
|
|
173
|
+
Server: typeof Server;
|
|
170
174
|
};
|
|
171
|
-
export
|
|
172
|
-
export type CountCallback = (err?: Error | undefined, count?: number | undefined) => void;
|
|
173
|
-
export type SocketCallback = (socket: DuplexStream) => void;
|
|
174
|
-
import { EventEmitter } from 'node:events';
|
|
175
|
-
import { MockSocket } from './socket.js';
|
|
175
|
+
export default _default;
|
package/types/socket.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import stream from 'node:stream';
|
|
2
|
+
import util from 'node:util';
|
|
1
3
|
/**
|
|
2
4
|
* One end of a socket, either client or server. Serves as a pass-through to
|
|
3
5
|
* the other side.
|
|
@@ -5,7 +7,8 @@
|
|
|
5
7
|
* @fires {HalfSocket#written} When data is written to this side of the socket
|
|
6
8
|
* to be sent.
|
|
7
9
|
*/
|
|
8
|
-
export class HalfSocket extends stream.Duplex {
|
|
10
|
+
export declare class HalfSocket extends stream.Duplex {
|
|
11
|
+
name: string;
|
|
9
12
|
/**
|
|
10
13
|
* Creates an instance of HalfSocket.
|
|
11
14
|
*
|
|
@@ -13,7 +16,6 @@ export class HalfSocket extends stream.Duplex {
|
|
|
13
16
|
* @param {stream.DuplexOptions} opts Options for the socket end.
|
|
14
17
|
*/
|
|
15
18
|
constructor(name: string, opts: stream.DuplexOptions);
|
|
16
|
-
name: string;
|
|
17
19
|
/**
|
|
18
20
|
* Add debug logging to EventEmitter. Start with NODE_DEBUG=mock-tls-server
|
|
19
21
|
* to see all events.
|
|
@@ -24,6 +26,18 @@ export class HalfSocket extends stream.Duplex {
|
|
|
24
26
|
* otherwise.
|
|
25
27
|
*/
|
|
26
28
|
emit(eventName: string, ...args: any[]): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* A chunk was written to the stream.
|
|
31
|
+
*
|
|
32
|
+
* @param {any} chunk
|
|
33
|
+
* @param {BufferEncoding} encoding
|
|
34
|
+
* @param {(error?: Error | null) => void} cb
|
|
35
|
+
*/
|
|
36
|
+
_write(chunk: any, encoding: BufferEncoding, cb: (error?: Error | null) => void): void;
|
|
37
|
+
/**
|
|
38
|
+
* @param {number} _sz
|
|
39
|
+
*/
|
|
40
|
+
_read(_sz: number): void;
|
|
27
41
|
[util.inspect.custom](): string;
|
|
28
42
|
}
|
|
29
43
|
/**
|
|
@@ -31,7 +45,9 @@ export class HalfSocket extends stream.Duplex {
|
|
|
31
45
|
* connections are created, so this can be used for testing no matter what
|
|
32
46
|
* permissions you have in your CI system.
|
|
33
47
|
*/
|
|
34
|
-
export class MockSocket extends stream.Duplex {
|
|
48
|
+
export declare class MockSocket extends stream.Duplex {
|
|
49
|
+
clientSocket: HalfSocket;
|
|
50
|
+
serverSocket: HalfSocket;
|
|
35
51
|
/**
|
|
36
52
|
* Creates an instance of MockSocket.
|
|
37
53
|
*
|
|
@@ -39,8 +55,4 @@ export class MockSocket extends stream.Duplex {
|
|
|
39
55
|
* sides.
|
|
40
56
|
*/
|
|
41
57
|
constructor(opts: stream.DuplexOptions);
|
|
42
|
-
clientSocket: HalfSocket;
|
|
43
|
-
serverSocket: HalfSocket;
|
|
44
58
|
}
|
|
45
|
-
import stream from 'node:stream';
|
|
46
|
-
import util from 'node:util';
|
package/types/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import util from 'node:util';
|
|
2
|
+
export type Many<T> = T | Readonly<T[]>;
|
|
1
3
|
/**
|
|
2
4
|
* @template T
|
|
3
5
|
* @typedef {T | Readonly<T[]>} Many
|
|
@@ -13,7 +15,7 @@
|
|
|
13
15
|
* @returns {U & {port?: number} & T} The normalized options.
|
|
14
16
|
* @throws {TypeError} No callback allowed for this function.
|
|
15
17
|
*/
|
|
16
|
-
export function normalizeArgs<T extends Record<string, Function | undefined>, U>(options?: number | U, listener?: T): U & {
|
|
18
|
+
export declare function normalizeArgs<T extends Record<string, Function | undefined>, U>(options?: number | U, listener?: T): U & {
|
|
17
19
|
port?: number;
|
|
18
20
|
} & T;
|
|
19
21
|
/**
|
|
@@ -23,15 +25,13 @@ export function normalizeArgs<T extends Record<string, Function | undefined>, U>
|
|
|
23
25
|
* @param {object} opts Extra properties for error (e.g. {code: 'EADDRINUSE'}).
|
|
24
26
|
* @returns {Error} The extended error.
|
|
25
27
|
*/
|
|
26
|
-
export function extendedError(message: string, opts: object): Error;
|
|
28
|
+
export declare function extendedError(message: string, opts: object): Error;
|
|
27
29
|
/**
|
|
28
30
|
* Transform an array of event args to something readable.
|
|
29
31
|
*
|
|
30
32
|
* @param {any[]} args Array of event args to transform.
|
|
31
33
|
* @returns {string[]}
|
|
32
34
|
*/
|
|
33
|
-
export function classNames(args: any[]): string[];
|
|
35
|
+
export declare function classNames(args: any[]): string[];
|
|
34
36
|
/** @type {util.DebugLoggerFunction|util.DebugLogger} */
|
|
35
|
-
export let log: util.DebugLoggerFunction | util.DebugLogger;
|
|
36
|
-
export type Many<T> = T | Readonly<T[]>;
|
|
37
|
-
import util from 'node:util';
|
|
37
|
+
export declare let log: util.DebugLoggerFunction | util.DebugLogger;
|