Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Fastify v5 #293

Merged
merged 6 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0
with:
lint: true
license-check: true
5 changes: 0 additions & 5 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
ts: false
jsx: false
flow: false
coverage: true
jobs: 1

files:
- test/**/*.test.js
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
},
"homepage": "https://github.com/fastify/fastify-websocket#readme",
"devDependencies": {
"@fastify/pre-commit": "^2.0.2",
"@fastify/pre-commit": "^2.1.0",
"@fastify/type-provider-typebox": "^4.0.0",
"@types/node": "^20.1.0",
"@types/ws": "^8.2.2",
"fastify": "^4.25.0",
"@types/node": "^20.11.28",
"@types/ws": "^8.5.10",
"fastify": "^4.26.2",
"fastify-tsconfig": "^2.0.0",
"split2": "^4.1.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"split2": "^4.2.0",
"standard": "^17.1.0",
"tap": "^18.7.1",
"tsd": "^0.31.0"
},
"dependencies": {
"duplexify": "^4.1.2",
"fastify-plugin": "^4.0.0",
"ws": "^8.0.0"
"duplexify": "^4.1.3",
"fastify-plugin": "^4.5.1",
"ws": "^8.16.0"
},
"publishConfig": {
"access": "public"
Expand Down
53 changes: 45 additions & 8 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ test('Should expose a websocket', async (t) => {
await fastify.listen({ port: 0 })

const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
t.teardown(() => ws.close())
t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

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

const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
t.teardown(() => ws.close())
t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

await p
})

test('Should run custom errorHandler on error inside websocket handler', async (t) => {
t.plan(1)

const fastify = Fastify()
t.teardown(() => fastify.close())

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

await fastify.listen({ port: 0 })
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
t.teardown(() => ws.close())

t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

await p
})

test('Should run custom errorHandler on error inside async websocket handler', async (t) => {
t.plan(1)

const fastify = Fastify()
t.teardown(() => fastify.close())

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

await fastify.listen({ port: 0 })
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
t.teardown(() => ws.close())
t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

await p
})
Expand Down Expand Up @@ -188,7 +209,11 @@ test('Should be able to pass custom options to ws', async (t) => {
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port, clientOptions)
const chunkPromise = once(ws, 'message')
await once(ws, 'open')
t.teardown(() => ws.close())
t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

ws.send('hello')

Expand Down Expand Up @@ -228,7 +253,11 @@ test('Should warn if path option is provided to ws', async (t) => {
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port, clientOptions)
const chunkPromise = once(ws, 'message')
await once(ws, 'open')
t.teardown(() => ws.close())
t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

ws.send('hello')

Expand Down Expand Up @@ -269,7 +298,11 @@ test('Should be able to pass a custom server option to ws', async (t) => {
const ws = new WebSocket('ws://localhost:' + externalServerPort)
const chunkPromise = once(ws, 'message')
await once(ws, 'open')
t.teardown(() => ws.close())
t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

ws.send('hello')

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

const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
t.teardown(() => ws.close())
t.teardown(() => {
if (ws.readyState) {
ws.close()
}
})

const chunkPromise = once(ws, 'message')
await once(ws, 'open')
Expand Down