Skip to content

Commit b2f29b5

Browse files
authored
Test: Fastify #5555 - move to node test runner (#404)
* test: updated export tests * test: updated socket.io.js * test: updated test.js * test: updated utils.js * test: updated websocket pathname * test: updated websocket querystring * test: updated websocket * test: updated ws-prefix-rewrite-core * test: updated ws-prefix-rewrite * test: added borp and removed tap * test: moved equals to strict
1 parent 2f2001a commit b2f29b5

12 files changed

+275
-278
lines changed

.borp.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
files:
2+
- 'test/**/*.js'

.taprc

Lines changed: 0 additions & 2 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "eslint",
1010
"lint:fix": "eslint --fix",
1111
"lint:typescript": "npm run lint:fix - --parser @typescript-eslint/parser --plugin typescript \"test/types/*.ts\"",
12-
"test": "npm run lint && tap \"test/*.js\" && npm run typescript",
12+
"test": "npm run lint && borp -C --check-coverage --reporter=@jsumners/line-reporter && npm run typescript",
1313
"typescript": "tsd"
1414
},
1515
"repository": {
@@ -59,8 +59,10 @@
5959
"devDependencies": {
6060
"@fastify/pre-commit": "^2.1.0",
6161
"@fastify/websocket": "^11.0.1",
62+
"@jsumners/line-reporter": "^1.0.1",
6263
"@types/node": "^22.0.0",
6364
"@types/ws": "^8.5.10",
65+
"borp": "^0.19.0",
6466
"eslint": "^9.17.0",
6567
"express": "^4.19.2",
6668
"express-http-proxy": "^2.0.0",
@@ -73,7 +75,6 @@
7375
"simple-get": "^4.0.1",
7476
"socket.io": "^4.7.5",
7577
"socket.io-client": "^4.7.5",
76-
"tap": "^18.7.2",
7778
"tsd": "^0.31.0",
7879
"typescript": "~5.7.2",
7980
"why-is-node-running": "^3.0.0"

test/export.js

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

3-
const t = require('tap')
3+
const test = require('node:test')
44

55
const fastifyHttpProxy = require('..')
66
const defaultExport = require('..').default
77
const { fastifyHttpProxy: namedExport } = require('..')
88

9-
t.test('module export', function (t) {
9+
test('module export', function (t) {
1010
t.plan(1)
11-
t.equal(typeof fastifyHttpProxy, 'function')
11+
t.assert.strictEqual(typeof fastifyHttpProxy, 'function')
1212
})
1313

14-
t.test('default export', function (t) {
14+
test('default export', function (t) {
1515
t.plan(1)
16-
t.equal(typeof defaultExport, 'function')
16+
t.assert.strictEqual(typeof defaultExport, 'function')
1717
})
1818

19-
t.test('named export', function (t) {
19+
test('named export', function (t) {
2020
t.plan(1)
21-
t.equal(typeof namedExport, 'function')
21+
t.assert.strictEqual(typeof namedExport, 'function')
2222
})

test/socket.io.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const Fastify = require('fastify')
55
const proxy = require('../')
66
const ioServer = require('socket.io')
@@ -9,44 +9,51 @@ const { createServer } = require('node:http')
99
const { promisify } = require('node:util')
1010
const { once } = require('node:events')
1111

12-
test('proxy socket.io', async t => {
12+
test('proxy socket.io', async (t) => {
1313
t.plan(2)
1414

1515
const srvUpstream = createServer()
16-
t.teardown(srvUpstream.close.bind(srvUpstream))
16+
t.after(() => {
17+
srvUpstream.close()
18+
})
1719

1820
const srvSocket = new ioServer.Server(srvUpstream)
19-
t.teardown(srvSocket.close.bind(srvSocket))
21+
t.after(() => {
22+
srvSocket.close()
23+
})
2024

2125
await promisify(srvUpstream.listen.bind(srvUpstream))(0)
2226

2327
const srvProxy = Fastify()
24-
t.teardown(srvProxy.close.bind(srvProxy))
28+
t.after(() => {
29+
srvProxy.close()
30+
})
2531

2632
srvProxy.register(proxy, {
2733
upstream: `http://127.0.0.1:${srvUpstream.address().port}`,
28-
websocket: true
34+
websocket: true,
2935
})
3036

3137
await srvProxy.listen({ port: 0, host: '127.0.0.1' })
3238

33-
srvSocket.on('connection', socket => {
34-
socket.on('hello', data => {
35-
t.equal(data, 'world')
39+
srvSocket.on('connection', (socket) => {
40+
socket.on('hello', (data) => {
41+
t.assert.strictEqual(data, 'world')
3642
socket.emit('hi', 'socket')
3743
})
3844
})
3945

40-
const cliSocket = ioClient(`http://127.0.0.1:${srvProxy.server.address().port}`)
41-
t.teardown(cliSocket.close.bind(cliSocket))
46+
const cliSocket = ioClient(
47+
`http://127.0.0.1:${srvProxy.server.address().port}`
48+
)
49+
t.after(() => {
50+
cliSocket.close()
51+
})
4252

4353
cliSocket.emit('hello', 'world')
4454

45-
const out = await once(cliSocket, 'hi')
46-
t.equal(out[0], 'socket')
55+
const [out] = await once(cliSocket, 'hi')
56+
t.assert.strictEqual(out, 'socket')
4757

48-
await Promise.all([
49-
once(cliSocket, 'disconnect'),
50-
srvProxy.close()
51-
])
58+
await Promise.all([once(cliSocket, 'disconnect'), srvProxy.close()])
5259
})

0 commit comments

Comments
 (0)