test.test.ts 706 Bytes
import ioclient, { Socket } from "socket.io-client";
import { MessageResponse, MessageType } from "./message/types";
import { expect } from "chai";
import { Server } from "./Server";

describe("server", () => {
  const PORT = 3000;

  var server: Server;
  var client: Socket;

  before((done) => {
    client = ioclient(`http://localhost:${PORT}`);
    client.on("connect", done);

    server = new Server(3000);
  });

  after(() => {
    server.close();
    client.close();
  });

  it("login", (done) => {
    client.emit(
      MessageType.LOGIN,
      { username: "guest" },
      (response: MessageResponse) => {
        expect(response.ok).to.equals(true);
        done();
      }
    );
  });
});