|
1 | | -const http = require("http").Server; |
2 | | -const io = require("socket.io"); |
3 | | -const ioc = require("socket.io-client"); |
4 | | -const expect = require("expect.js"); |
5 | | -const adapter = require(".."); |
| 1 | +import { createServer } from "http"; |
| 2 | +import { Server } from "socket.io"; |
| 3 | +import { io as ioc } from "socket.io-client"; |
| 4 | +import expect = require("expect.js"); |
| 5 | +import { createAdapter } from ".."; |
| 6 | +import type { AddressInfo } from "net"; |
6 | 7 |
|
7 | 8 | const ioredis = require("ioredis").createClient; |
8 | 9 |
|
@@ -65,7 +66,7 @@ let socket1, socket2, socket3; |
65 | 66 | }); |
66 | 67 | }); |
67 | 68 |
|
68 | | - it("uses a namespace to broadcast to rooms", () => { |
| 69 | + it("uses a namespace to broadcast to rooms", (done) => { |
69 | 70 | socket1.join("woot"); |
70 | 71 | client2.emit("do broadcast"); |
71 | 72 | socket2.on("do broadcast", () => { |
@@ -242,22 +243,24 @@ let socket1, socket2, socket3; |
242 | 243 | }); |
243 | 244 |
|
244 | 245 | function _create(options) { |
245 | | - return (nsp, fn) => { |
246 | | - const srv = http(); |
247 | | - const sio = io(srv); |
248 | | - sio.adapter(adapter(typeof options === "function" ? options() : options)); |
249 | | - srv.listen((err) => { |
| 246 | + return (nsp, fn?) => { |
| 247 | + const httpServer = createServer(); |
| 248 | + const sio = new Server(httpServer); |
| 249 | + sio.adapter( |
| 250 | + createAdapter(typeof options === "function" ? options() : options) |
| 251 | + ); |
| 252 | + httpServer.listen((err) => { |
250 | 253 | if (err) throw err; // abort tests |
251 | 254 | if ("function" == typeof nsp) { |
252 | 255 | fn = nsp; |
253 | 256 | nsp = ""; |
254 | 257 | } |
255 | 258 | nsp = nsp || "/"; |
256 | | - const addr = srv.address(); |
| 259 | + const addr = httpServer.address() as AddressInfo; |
257 | 260 | const url = "http://localhost:" + addr.port + nsp; |
258 | 261 |
|
259 | 262 | const namespace = sio.of(nsp); |
260 | | - const client = ioc(url, { reconnect: false }); |
| 263 | + const client = ioc(url, { reconnection: false }); |
261 | 264 |
|
262 | 265 | namespace.on("connection", (socket) => { |
263 | 266 | fn(namespace, client, socket); |
|
0 commit comments