Skip to content

Commit 810696a

Browse files
authored
Fix done is undefined error (#200)
Signed-off-by: Matteo Collina <[email protected]>
1 parent 5a5120b commit 810696a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function fastifyWebsocket (fastify, opts, next) {
9393
done()
9494
})
9595

96-
fastify.addHook('onResponse', (request, reply, error, done) => {
96+
fastify.addHook('onResponse', (request, reply, done) => {
9797
if (request.ws) {
9898
request.raw[kWs].destroy()
9999
}

test/hooks.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const net = require('net')
55
const Fastify = require('fastify')
66
const fastifyWebsocket = require('..')
77
const WebSocket = require('ws')
8+
const split = require('split2')
89

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

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

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

353+
stream.on('data', (chunk) => {
354+
t.ok(chunk.level < 50)
355+
})
356+
351357
fastify.listen({ port: 0 }, err => {
352358
t.error(err)
353359

0 commit comments

Comments
 (0)