Skip to content

Commit 2c0a81c

Browse files
ZachHaberdarrachequesne
authored andcommitted
chore(tests): fix issues due to client#id type change
1 parent f8d2644 commit 2c0a81c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

test/namespaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
createClient,
77
successFn,
88
createPartialDone,
9+
assert,
910
} from "./support/util";
1011

1112
describe("namespaces", () => {
@@ -417,6 +418,7 @@ describe("namespaces", () => {
417418
socket1.on("a", successFn(done, io, socket1, socket2));
418419

419420
socket2.on("connect", () => {
421+
assert(socket2.id);
420422
io.except(socket2.id).emit("a");
421423
});
422424
});
@@ -435,6 +437,7 @@ describe("namespaces", () => {
435437
socket1.on("a", successFn(done, io, socket1, socket2));
436438

437439
socket2.on("connect", () => {
440+
assert(socket2.id);
438441
nsp.except(socket2.id).emit("a");
439442
});
440443
});

test/support/util.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ export function successFn(
6363
return () => success(done, sio, ...clientSockets);
6464
}
6565

66+
/**
67+
* Asserts a condition so that typescript will recognize the assertion!
68+
*
69+
* Uses expect's `ok` check on condition
70+
* @param condition
71+
*/
72+
export function assert(condition: any): asserts condition {
73+
expect(condition).to.be.ok();
74+
}
75+
6676
export function getPort(io: Server): number {
6777
// @ts-ignore
6878
return io.httpServer.address().port;

test/uws.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Server } from "..";
77
import { io as ioc, Socket as ClientSocket } from "socket.io-client";
88
import request from "supertest";
99
import expect from "expect.js";
10+
import { assert } from "./support/util";
1011

1112
const createPartialDone = (done: (err?: Error) => void, count: number) => {
1213
let i = 0;
@@ -134,6 +135,8 @@ describe("socket.io with uWebSocket.js-based engine", () => {
134135
clientWSOnly.on("hello", partialDone);
135136
clientPollingOnly.on("hello", partialDone);
136137
clientCustomNamespace.on("hello", shouldNotHappen(done));
138+
assert(clientWSOnly.id);
139+
assert(clientPollingOnly.id);
137140

138141
io.of("/").sockets.get(clientWSOnly.id)!.join("room1");
139142
io.of("/").sockets.get(clientPollingOnly.id)!.join("room1");
@@ -148,6 +151,8 @@ describe("socket.io with uWebSocket.js-based engine", () => {
148151
clientWSOnly.on("hello", partialDone);
149152
clientPollingOnly.on("hello", partialDone);
150153
clientCustomNamespace.on("hello", shouldNotHappen(done));
154+
assert(clientWSOnly.id);
155+
assert(clientPollingOnly.id);
151156

152157
io.of("/").sockets.get(clientWSOnly.id)!.join("room1");
153158
io.of("/").sockets.get(clientPollingOnly.id)!.join("room2");
@@ -163,6 +168,8 @@ describe("socket.io with uWebSocket.js-based engine", () => {
163168
clientPollingOnly.on("hello", shouldNotHappen(done));
164169
clientCustomNamespace.on("hello", shouldNotHappen(done));
165170

171+
assert(clientWSOnly.id);
172+
assert(clientPollingOnly.id);
166173
io.of("/").sockets.get(clientWSOnly.id)!.join("room1");
167174
io.of("/").sockets.get(clientPollingOnly.id)!.join("room2");
168175

@@ -177,6 +184,9 @@ describe("socket.io with uWebSocket.js-based engine", () => {
177184
clientPollingOnly.on("hello", partialDone);
178185
clientCustomNamespace.on("hello", shouldNotHappen(done));
179186

187+
assert(client.id);
188+
assert(clientWSOnly.id);
189+
assert(clientPollingOnly.id);
180190
io.of("/").sockets.get(client.id)!.join("room1");
181191
io.of("/").sockets.get(clientPollingOnly.id)!.join("room1");
182192

@@ -189,6 +199,7 @@ describe("socket.io with uWebSocket.js-based engine", () => {
189199
it("should not crash when socket is disconnected before the upgrade", (done) => {
190200
client.on("disconnect", () => done());
191201

202+
assert(client.id);
192203
io.of("/").sockets.get(client.id)!.disconnect();
193204
});
194205

0 commit comments

Comments
 (0)