Skip to content

Commit 2079ca5

Browse files
committed
[test] Increase code coverage
1 parent d1a8af4 commit 2079ca5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/websocket-server.test.js

+36
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ describe('WebSocketServer', () => {
320320
const wss = new WebSocket.Server({ noServer: true, path: '/foo' });
321321

322322
assert.strictEqual(wss.shouldHandle({ url: '/foo' }), true);
323+
assert.strictEqual(wss.shouldHandle({ url: '/foo?bar=baz' }), true);
323324
});
324325

325326
it("returns false when the path doesn't match", () => {
@@ -546,6 +547,41 @@ describe('WebSocketServer', () => {
546547
});
547548
});
548549

550+
it('handles unsupported extensions', (done) => {
551+
const wss = new WebSocket.Server(
552+
{
553+
perMessageDeflate: true,
554+
port: 0
555+
},
556+
() => {
557+
const req = http.get({
558+
port: wss.address().port,
559+
headers: {
560+
Connection: 'Upgrade',
561+
Upgrade: 'websocket',
562+
'Sec-WebSocket-Key': 'dGhlIHNhbXBsZSBub25jZQ==',
563+
'Sec-WebSocket-Version': 13,
564+
'Sec-WebSocket-Extensions': 'foo; bar'
565+
}
566+
});
567+
568+
req.on('upgrade', (res, socket, head) => {
569+
if (head.length) socket.unshift(head);
570+
571+
socket.once('data', (chunk) => {
572+
assert.strictEqual(chunk[0], 0x88);
573+
wss.close(done);
574+
});
575+
});
576+
}
577+
);
578+
579+
wss.on('connection', (ws) => {
580+
assert.strictEqual(ws.extensions, '');
581+
ws.close();
582+
});
583+
});
584+
549585
describe('`verifyClient`', () => {
550586
it('can reject client synchronously', (done) => {
551587
const wss = new WebSocket.Server(

0 commit comments

Comments
 (0)