강동현

간단한 테스트 로직 작성

{
"dependencies": {
"@types/chai": "^4.2.18",
"@types/express": "^4.17.11",
"@types/mocha": "^8.2.2",
"@types/node": "^15.3.1",
"@types/socket.io": "^3.0.2",
"@types/socket.io-client": "^3.0.0",
"@types/uuid": "^8.3.0",
"chai": "^4.3.4",
"express": "^4.17.1",
"mocha": "^8.4.0",
"nodemon": "^2.0.7",
"socket.io": "^4.1.2",
"socket.io-client": "^4.1.2",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"uuid": "^8.3.2"
},
"scripts": {
"start": "nodemon index.ts"
"start": "nodemon index.ts",
"test": "mocha -r ts-node/register ./**/*.test.ts"
}
}
......
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();
}
);
});
});
This diff is collapsed. Click to expand it.