Skip to content

Commit ae2a31b

Browse files
wip
1 parent b0a3dae commit ae2a31b

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

test/options.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
4+
const assert = require('node:assert')
45
const { validateOptions } = require('../src/options')
56
const { DEFAULT_PING_INTERVAL, DEFAULT_MAX_RECONNECTION_RETRIES, DEFAULT_RECONNECT_INTERVAL, DEFAULT_RECONNECT_DECAY, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_RECONNECT_ON_CLOSE } = require('../src/options')
7+
68
test('validateOptions', (t) => {
79
const requiredOptions = {
810
upstream: 'someUpstream'
911
}
1012

11-
t.throws(() => validateOptions({}), 'upstream must be specified')
13+
assert.throws(() => validateOptions({}), /upstream must be specified/)
1214

13-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: -1 } }), 'wsReconnect.pingInterval must be a non-negative number')
14-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: '1' } }), 'wsReconnect.pingInterval must be a non-negative number')
15-
t.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: 1 } }))
15+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: -1 } }), /wsReconnect.pingInterval must be a non-negative number/)
16+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: '1' } }), /wsReconnect.pingInterval must be a non-negative number/)
17+
assert.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: 1 } }))
1618

17-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: 0 } }), 'wsReconnect.maxReconnectionRetries must be a number greater than or equal to 1')
18-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: -1 } }), 'wsReconnect.maxReconnectionRetries must be a number greater than or equal to 1')
19-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: '1' } }), 'wsReconnect.maxReconnectionRetries must be a number greater than or equal to 1')
20-
t.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: 1 } }))
19+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: 0 } }), /wsReconnect.maxReconnectionRetries must be a number greater than or equal to 1/)
20+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: -1 } }), /wsReconnect.maxReconnectionRetries must be a number greater than or equal to 1/)
21+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: '1' } }), /wsReconnect.maxReconnectionRetries must be a number greater than or equal to 1/)
22+
assert.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { maxReconnectionRetries: 1 } }))
2123

22-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: 0 } }), 'wsReconnect.reconnectInterval (ms) must be a number greater than or equal to 100')
23-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: -1 } }), 'wsReconnect.reconnectInterval (ms) must be a number greater than or equal to 100')
24-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: '1' } }), 'wsReconnect.reconnectInterval (ms) must be a number greater than or equal to 100')
25-
t.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: 100 } }))
24+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: 0 } }), /wsReconnect.reconnectInterval \(ms\) must be a number greater than or equal to 100/)
25+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: -1 } }), /wsReconnect.reconnectInterval \(ms\) must be a number greater than or equal to 100/)
26+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: '1' } }), /wsReconnect.reconnectInterval \(ms\) must be a number greater than or equal to 100/)
27+
assert.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectInterval: 100 } }))
2628

27-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: 0 } }), 'wsReconnect.reconnectDecay must be a number greater than or equal to 1')
28-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: -1 } }), 'wsReconnect.reconnectDecay must be a number greater than or equal to 1')
29-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: '1' } }), 'wsReconnect.reconnectDecay must be a number greater than or equal to 1')
30-
t.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: 1 } }))
29+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: 0 } }), /wsReconnect.reconnectDecay must be a number greater than or equal to 1/)
30+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: -1 } }), /wsReconnect.reconnectDecay must be a number greater than or equal to 1/)
31+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: '1' } }), /wsReconnect.reconnectDecay must be a number greater than or equal to 1/)
32+
assert.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectDecay: 1 } }))
3133

32-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { connectionTimeout: -1 } }), 'wsReconnect.connectionTimeout must be a non-negative number')
33-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { connectionTimeout: '1' } }), 'wsReconnect.connectionTimeout must be a non-negative number')
34-
t.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { connectionTimeout: 1 } }))
34+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { connectionTimeout: -1 } }), /wsReconnect.connectionTimeout must be a non-negative number/)
35+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { connectionTimeout: '1' } }), /wsReconnect.connectionTimeout must be a non-negative number/)
36+
assert.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { connectionTimeout: 1 } }))
3537

36-
t.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectOnClose: '1' } }), 'wsReconnect.reconnectOnClose must be a boolean')
37-
t.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectOnClose: true } }))
38+
assert.throws(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectOnClose: '1' } }), /wsReconnect.reconnectOnClose must be a boolean/)
39+
assert.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { reconnectOnClose: true } }))
3840

39-
t.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: 1, maxReconnectionRetries: 1, reconnectInterval: 100, reconnectDecay: 1, connectionTimeout: 1, reconnectOnClose: true } }))
41+
assert.doesNotThrow(() => validateOptions({ ...requiredOptions, wsReconnect: { pingInterval: 1, maxReconnectionRetries: 1, reconnectInterval: 100, reconnectDecay: 1, connectionTimeout: 1, reconnectOnClose: true } }))
4042

41-
t.equal(validateOptions({ ...requiredOptions, wsReconnect: { } }), {
43+
assert.deepEqual(validateOptions({ ...requiredOptions, wsReconnect: { } }), {
4244
...requiredOptions,
4345
wsReconnect: {
4446
pingInterval: DEFAULT_PING_INTERVAL,
@@ -49,6 +51,4 @@ test('validateOptions', (t) => {
4951
reconnectOnClose: DEFAULT_RECONNECT_ON_CLOSE
5052
}
5153
})
52-
53-
t.end()
5454
})

test/ws-reconnect.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict'
22

3+
const { test } = require('node:test')
4+
const assert = require('node:assert')
35
const { createServer } = require('node:http')
46
const { promisify } = require('node:util')
57
const { once } = require('node:events')
68
const { setTimeout: wait } = require('node:timers/promises')
7-
const { test } = require('tap')
89
const Fastify = require('fastify')
910
const WebSocket = require('ws')
1011
const pinoTest = require('pino-test')
@@ -52,7 +53,7 @@ async function createServices ({ t, upstream, wsReconnectOptions, wsTargetOption
5253
const client = new WebSocket(`ws://127.0.0.1:${proxy.server.address().port}`)
5354
await once(client, 'open')
5455

55-
t.teardown(async () => {
56+
t.after(async () => {
5657
client.close()
5758
targetWs.close()
5859
targetServer.close()
@@ -85,7 +86,7 @@ test('should use ping/pong to verify connection is alive - from source (server o
8586

8687
await wait(250)
8788

88-
t.ok(counter > 0)
89+
assert.ok(counter > 0)
8990
})
9091

9192
test('should reconnect on broken connection', async (t) => {
@@ -108,8 +109,6 @@ test('should reconnect on broken connection', async (t) => {
108109
await waitForLogMessage(loggerSpy, 'proxy ws connection is broken')
109110
await waitForLogMessage(loggerSpy, 'proxy ws target close event')
110111
await waitForLogMessage(loggerSpy, 'proxy ws reconnected')
111-
112-
// TODO fix with source.removeAllListeners
113112
})
114113

115114
test('should not reconnect after max retries', async (t) => {

0 commit comments

Comments
 (0)