Showing
3 changed files
with
42 additions
and
1 deletions
1 | { | 1 | { |
2 | "dependencies": { | 2 | "dependencies": { |
3 | + "@types/chai": "^4.2.18", | ||
3 | "@types/express": "^4.17.11", | 4 | "@types/express": "^4.17.11", |
5 | + "@types/mocha": "^8.2.2", | ||
4 | "@types/node": "^15.3.1", | 6 | "@types/node": "^15.3.1", |
5 | "@types/socket.io": "^3.0.2", | 7 | "@types/socket.io": "^3.0.2", |
8 | + "@types/socket.io-client": "^3.0.0", | ||
6 | "@types/uuid": "^8.3.0", | 9 | "@types/uuid": "^8.3.0", |
10 | + "chai": "^4.3.4", | ||
7 | "express": "^4.17.1", | 11 | "express": "^4.17.1", |
12 | + "mocha": "^8.4.0", | ||
8 | "nodemon": "^2.0.7", | 13 | "nodemon": "^2.0.7", |
9 | "socket.io": "^4.1.2", | 14 | "socket.io": "^4.1.2", |
15 | + "socket.io-client": "^4.1.2", | ||
10 | "ts-node": "^9.1.1", | 16 | "ts-node": "^9.1.1", |
11 | "typescript": "^4.2.4", | 17 | "typescript": "^4.2.4", |
12 | "uuid": "^8.3.2" | 18 | "uuid": "^8.3.2" |
13 | }, | 19 | }, |
14 | "scripts": { | 20 | "scripts": { |
15 | - "start": "nodemon index.ts" | 21 | + "start": "nodemon index.ts", |
22 | + "test": "mocha -r ts-node/register ./**/*.test.ts" | ||
16 | } | 23 | } |
17 | } | 24 | } | ... | ... |
server/test.test.ts
0 → 100644
1 | +import ioclient, { Socket } from "socket.io-client"; | ||
2 | +import { MessageResponse, MessageType } from "./message/types"; | ||
3 | +import { expect } from "chai"; | ||
4 | +import { Server } from "./Server"; | ||
5 | + | ||
6 | +describe("server", () => { | ||
7 | + const PORT = 3000; | ||
8 | + | ||
9 | + var server: Server; | ||
10 | + var client: Socket; | ||
11 | + | ||
12 | + before((done) => { | ||
13 | + client = ioclient(`http://localhost:${PORT}`); | ||
14 | + client.on("connect", done); | ||
15 | + | ||
16 | + server = new Server(3000); | ||
17 | + }); | ||
18 | + | ||
19 | + after(() => { | ||
20 | + server.close(); | ||
21 | + client.close(); | ||
22 | + }); | ||
23 | + | ||
24 | + it("login", (done) => { | ||
25 | + client.emit( | ||
26 | + MessageType.LOGIN, | ||
27 | + { username: "guest" }, | ||
28 | + (response: MessageResponse) => { | ||
29 | + expect(response.ok).to.equals(true); | ||
30 | + done(); | ||
31 | + } | ||
32 | + ); | ||
33 | + }); | ||
34 | +}); |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment