Skip to content

Commit ab0a13f

Browse files
committed
fix: handle WebSocket close event and improve data chunk handling in tests
1 parent fd2729c commit ab0a13f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

test/viewer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ describe('WebSocket server', function () {
4747
].join('\r\n'));
4848
});
4949

50+
socket.on('close', function () {
51+
server.close(done);
52+
});
53+
5054
let count = 0;
5155
socket.on('data', function (chunk) {
5256
++count;
@@ -59,16 +63,14 @@ describe('WebSocket server', function () {
5963
''
6064
].join('\r\n'));
6165

66+
// Because data may be received in multiple chunks, only check the first one
6267
if (count === 1) {
6368
expect(chunk.equals(expected)).to.be.true;
6469
}
6570

6671
// Send a WebSocket frame with a reserved opcode (5) to trigger an error
6772
// to be emitted on the server.
6873
socket.write(Buffer.from([0x85, 0x00]));
69-
socket.on('close', function () {
70-
server.close(done);
71-
});
7274
});
7375
})
7476
.catch(done);

0 commit comments

Comments
 (0)