@@ -95,12 +95,15 @@ test('Should expose a websocket on prefixed route with /', (t, end) => {
95
95
} )
96
96
} )
97
97
98
- test ( 'Should expose websocket and http route' , ( t , end ) => {
98
+ test ( 'Should expose websocket and http route' , ( t ) => {
99
99
t . plan ( 4 )
100
100
const fastify = Fastify ( )
101
101
102
102
t . after ( ( ) => fastify . close ( ) )
103
103
104
+ const { promise : clientPromise , resolve : clientResolve } = withResolvers ( )
105
+ const { promise : serverPromise , resolve : serverResolve } = withResolvers ( )
106
+
104
107
fastify . register ( fastifyWebsocket )
105
108
fastify . register (
106
109
function ( instance , _opts , next ) {
@@ -116,6 +119,7 @@ test('Should expose websocket and http route', (t, end) => {
116
119
117
120
socket . once ( 'message' , ( chunk ) => {
118
121
t . assert . deepStrictEqual ( chunk . toString ( ) , 'hello server' )
122
+ clientResolve ( )
119
123
} )
120
124
}
121
125
} )
@@ -149,10 +153,12 @@ test('Should expose websocket and http route', (t, end) => {
149
153
// The whole response has been received. Print out the result.
150
154
response . on ( 'end' , ( ) => {
151
155
t . assert . deepStrictEqual ( data , '{"hello":"world"}' )
152
- end ( )
156
+ serverResolve ( )
153
157
} )
154
158
} )
155
159
} )
160
+
161
+ return Promise . all ( [ clientPromise , serverPromise ] )
156
162
} )
157
163
158
164
test ( 'Should close on unregistered path (with no wildcard route websocket handler defined)' , ( t , end ) => {
0 commit comments