Skip to content

Commit 441e8e5

Browse files
committed
fix: use promises
1 parent a35440a commit 441e8e5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/router.test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,15 @@ test('Should expose a websocket on prefixed route with /', (t, end) => {
9595
})
9696
})
9797

98-
test('Should expose websocket and http route', (t, end) => {
98+
test('Should expose websocket and http route', (t) => {
9999
t.plan(4)
100100
const fastify = Fastify()
101101

102102
t.after(() => fastify.close())
103103

104+
const { promise: clientPromise, resolve: clientResolve } = withResolvers()
105+
const { promise: serverPromise, resolve: serverResolve } = withResolvers()
106+
104107
fastify.register(fastifyWebsocket)
105108
fastify.register(
106109
function (instance, _opts, next) {
@@ -116,6 +119,7 @@ test('Should expose websocket and http route', (t, end) => {
116119

117120
socket.once('message', (chunk) => {
118121
t.assert.deepStrictEqual(chunk.toString(), 'hello server')
122+
clientResolve()
119123
})
120124
}
121125
})
@@ -149,10 +153,12 @@ test('Should expose websocket and http route', (t, end) => {
149153
// The whole response has been received. Print out the result.
150154
response.on('end', () => {
151155
t.assert.deepStrictEqual(data, '{"hello":"world"}')
152-
end()
156+
serverResolve()
153157
})
154158
})
155159
})
160+
161+
return Promise.all([clientPromise, serverPromise])
156162
})
157163

158164
test('Should close on unregistered path (with no wildcard route websocket handler defined)', (t, end) => {

0 commit comments

Comments
 (0)