Skip to content

Commit

Permalink
Update for Fastify v5
Browse files Browse the repository at this point in the history
  • Loading branch information
synapse committed Mar 18, 2024
1 parent 25d37d2 commit e2411d5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
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
8 changes: 0 additions & 8 deletions .taprc

This file was deleted.

28 changes: 16 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,31 @@
},
"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",
"tsd": "^0.30.1"
"split2": "^4.2.0",
"standard": "^17.1.0",
"tap": "^18.7.1",
"tsd": "^0.30.7"
},
"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"
},
"pre-commit": [
"lint",
"test"
]
],
"tap": {
"jobs": 1,
"files": ["test/**/*.test.js"]
}
}
22 changes: 13 additions & 9 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,21 @@ test('Should run custom errorHandler on wildcard route handler error', async (t)

fastify.get('/*', { websocket: true }, (conn) => {
conn.pipe(conn)
t.teardown(() => conn.destroy())
return Promise.reject(new Error('Fail'))
})

await fastify.listen({ port: 0 })

const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
const client = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' })
t.teardown(() => client.destroy())
await p

t.teardown(() => client.destroy())
})

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

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

Expand All @@ -122,29 +124,30 @@ test('Should run custom errorHandler on error inside websocket handler', async (

fastify.get('/', { websocket: true }, function wsHandler (conn) {
conn.pipe(conn)
t.teardown(() => conn.destroy())
throw new Error('Fail')
})

await fastify.listen({ port: 0 })
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
const client = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' })
t.teardown(() => client.destroy())

await p

t.teardown(() => client.destroy())
})

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

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

let _resolve
const p = new Promise((resolve) => {
_resolve = resolve
})
const promise = new Promise((resolve) => { _resolve = resolve })

const options = {
errorHandler: function (error) {
console.log('Error received')
t.equal(error.message, 'Fail')
_resolve()
}
Expand All @@ -154,15 +157,16 @@ test('Should run custom errorHandler on error inside async websocket handler', a

fastify.get('/', { websocket: true }, async function wsHandler (conn) {
conn.pipe(conn)
t.teardown(() => conn.destroy())
throw new Error('Fail')
})

await fastify.listen({ port: 0 })
const ws = new WebSocket('ws://localhost:' + fastify.server.address().port)
const client = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' })

await promise

t.teardown(() => client.destroy())
await p
})

test('Should be able to pass custom options to websocket-stream', async (t) => {
Expand Down

0 comments on commit e2411d5

Please sign in to comment.