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

Fix done is undefined error #200

Merged
merged 1 commit into from
May 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function fastifyWebsocket (fastify, opts, next) {
done()
})

fastify.addHook('onResponse', (request, reply, error, done) => {
fastify.addHook('onResponse', (request, reply, done) => {
if (request.ws) {
request.raw[kWs].destroy()
}
Expand Down
10 changes: 8 additions & 2 deletions test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const net = require('net')
const Fastify = require('fastify')
const fastifyWebsocket = require('..')
const WebSocket = require('ws')
const split = require('split2')

test('Should run onRequest, preValidation, preHandler hooks', t => {
t.plan(7)
Expand Down Expand Up @@ -335,8 +336,9 @@ test('Should not hijack reply for an normal request to a websocket route that is
})

test('Should not hijack reply for an WS request to a WS route that gets sent a normal HTTP response in a hook', t => {
t.plan(2)
const fastify = Fastify()
t.plan(6)
const stream = split(JSON.parse)
const fastify = Fastify({ logger: { stream } })

fastify.register(fastifyWebsocket)
fastify.register(async function (fastify) {
Expand All @@ -348,6 +350,10 @@ test('Should not hijack reply for an WS request to a WS route that gets sent a n
})
})

stream.on('data', (chunk) => {
t.ok(chunk.level < 50)
})

fastify.listen({ port: 0 }, err => {
t.error(err)

Expand Down