()
| 2 | import expect = require("expect.js"); |
| 3 | |
| 4 | export function createServer() { |
| 5 | const server = new Server(3210, { |
| 6 | pingInterval: 2000, |
| 7 | connectionStateRecovery: {}, |
| 8 | allowRequest: (req, callback) => { |
| 9 | // add a fixed delay to test the connection timeout on the client side |
| 10 | setTimeout(() => callback(null, true), 10); |
| 11 | }, |
| 12 | }); |
| 13 | |
| 14 | server.of("/foo").on("connection", (socket) => { |
| 15 | socket.on("getId", (cb) => { |
| 16 | cb(socket.id); |
| 17 | }); |
| 18 | }); |
| 19 | |
| 20 | server.of("/timeout_socket").on("connection", () => { |
| 21 | // register namespace |
| 22 | }); |
| 23 | |
| 24 | server.of("/valid").on("connection", () => { |
| 25 | // register namespace |
| 26 | }); |
| 27 | |
| 28 | server.of("/asd").on("connection", () => { |
| 29 | // register namespace |
| 30 | }); |
| 31 | |
| 32 | server.of("/abc").on("connection", (socket) => { |
| 33 | socket.emit("handshake", socket.handshake); |
| 34 | }); |
| 35 | |
| 36 | server.use((socket, next) => { |
| 37 | // @ts-ignore |
| 38 | if (socket.request._query.fail) |
| 39 | return next(new Error("Auth failed (main namespace)")); |
| 40 | next(); |
| 41 | }); |
| 42 | |
| 43 | server.of("/no").use((socket, next) => { |
| 44 | next(new Error("Auth failed (custom namespace)")); |
| 45 | }); |
| 46 | |
| 47 | server.on("connection", (socket) => { |
| 48 | // simple test |
| 49 | socket.on("hi", () => { |
| 50 | socket.emit("hi"); |
| 51 | }); |
| 52 | |
| 53 | socket.on("echo", (arg, cb) => { |
| 54 | cb(arg); |
| 55 | }); |
| 56 | |
| 57 | // ack tests |
| 58 | socket.on("ack", () => { |
| 59 | socket.emit("ack", (a, b) => { |
| 60 | if (a === 5 && b.test) { |
| 61 | socket.emit("got it"); |
no test coverage detected