Skip to content

Commit f65fcac

Browse files
authored
Update for Fastify v5 (#293) (#301)
1 parent ef9aa09 commit f65fcac

File tree

4 files changed

+56
-24
lines changed

4 files changed

+56
-24
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717

1818
jobs:
1919
test:
20-
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
20+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0
2121
with:
2222
lint: true
2323
license-check: true

.taprc

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
ts: false
2-
jsx: false
3-
flow: false
4-
coverage: true
51
jobs: 1
6-
72
files:
83
- test/**/*.test.js

package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
},
2727
"homepage": "https://github.com/fastify/fastify-websocket#readme",
2828
"devDependencies": {
29-
"@fastify/pre-commit": "^2.0.2",
29+
"@fastify/pre-commit": "^2.1.0",
3030
"@fastify/type-provider-typebox": "^4.0.0",
31-
"@types/node": "^20.1.0",
32-
"@types/ws": "^8.2.2",
33-
"fastify": "^4.25.0",
31+
"@types/node": "^20.11.28",
32+
"@types/ws": "^8.5.10",
33+
"fastify": "^4.26.2",
3434
"fastify-tsconfig": "^2.0.0",
35-
"split2": "^4.1.0",
36-
"standard": "^17.0.0",
37-
"tap": "^16.0.0",
35+
"split2": "^4.2.0",
36+
"standard": "^17.1.0",
37+
"tap": "^18.7.1",
3838
"tsd": "^0.31.0"
3939
},
4040
"dependencies": {
41-
"duplexify": "^4.1.2",
42-
"fastify-plugin": "^4.0.0",
43-
"ws": "^8.0.0"
41+
"duplexify": "^4.1.3",
42+
"fastify-plugin": "^4.5.1",
43+
"ws": "^8.16.0"
4444
},
4545
"publishConfig": {
4646
"access": "public"

test/base.test.js

+45-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ test('Should expose a websocket', async (t) => {
3333
await fastify.listen({ port: 0 })
3434

3535
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
36-
t.teardown(() => ws.close())
36+
t.teardown(() => {
37+
if (ws.readyState) {
38+
ws.close()
39+
}
40+
})
3741

3842
const chunkPromise = once(ws, 'message')
3943
await once(ws, 'open')
@@ -94,12 +98,18 @@ test('Should run custom errorHandler on wildcard route handler error', async (t)
9498
await fastify.listen({ port: 0 })
9599

96100
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
97-
t.teardown(() => ws.close())
101+
t.teardown(() => {
102+
if (ws.readyState) {
103+
ws.close()
104+
}
105+
})
98106

99107
await p
100108
})
101109

102110
test('Should run custom errorHandler on error inside websocket handler', async (t) => {
111+
t.plan(1)
112+
103113
const fastify = Fastify()
104114
t.teardown(() => fastify.close())
105115

@@ -125,12 +135,19 @@ test('Should run custom errorHandler on error inside websocket handler', async (
125135

126136
await fastify.listen({ port: 0 })
127137
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
128-
t.teardown(() => ws.close())
138+
139+
t.teardown(() => {
140+
if (ws.readyState) {
141+
ws.close()
142+
}
143+
})
129144

130145
await p
131146
})
132147

133148
test('Should run custom errorHandler on error inside async websocket handler', async (t) => {
149+
t.plan(1)
150+
134151
const fastify = Fastify()
135152
t.teardown(() => fastify.close())
136153

@@ -156,7 +173,11 @@ test('Should run custom errorHandler on error inside async websocket handler', a
156173

157174
await fastify.listen({ port: 0 })
158175
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
159-
t.teardown(() => ws.close())
176+
t.teardown(() => {
177+
if (ws.readyState) {
178+
ws.close()
179+
}
180+
})
160181

161182
await p
162183
})
@@ -188,7 +209,11 @@ test('Should be able to pass custom options to ws', async (t) => {
188209
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port, clientOptions)
189210
const chunkPromise = once(ws, 'message')
190211
await once(ws, 'open')
191-
t.teardown(() => ws.close())
212+
t.teardown(() => {
213+
if (ws.readyState) {
214+
ws.close()
215+
}
216+
})
192217

193218
ws.send('hello')
194219

@@ -228,7 +253,11 @@ test('Should warn if path option is provided to ws', async (t) => {
228253
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port, clientOptions)
229254
const chunkPromise = once(ws, 'message')
230255
await once(ws, 'open')
231-
t.teardown(() => ws.close())
256+
t.teardown(() => {
257+
if (ws.readyState) {
258+
ws.close()
259+
}
260+
})
232261

233262
ws.send('hello')
234263

@@ -269,7 +298,11 @@ test('Should be able to pass a custom server option to ws', async (t) => {
269298
const ws = new WebSocket('ws://localhost:' + externalServerPort)
270299
const chunkPromise = once(ws, 'message')
271300
await once(ws, 'open')
272-
t.teardown(() => ws.close())
301+
t.teardown(() => {
302+
if (ws.readyState) {
303+
ws.close()
304+
}
305+
})
273306

274307
ws.send('hello')
275308

@@ -330,7 +363,11 @@ test('Should be able to pass preClose option to override default', async (t) =>
330363
await fastify.listen({ port: 0 })
331364

332365
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
333-
t.teardown(() => ws.close())
366+
t.teardown(() => {
367+
if (ws.readyState) {
368+
ws.close()
369+
}
370+
})
334371

335372
const chunkPromise = once(ws, 'message')
336373
await once(ws, 'open')

0 commit comments

Comments
 (0)