Skip to content

Commit 7a51c76

Browse files
refactor: migrate tests to TypeScript
1 parent 64bd9fb commit 7a51c76

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"url": "git://github.com/socketio/socket.io"
2323
},
2424
"scripts": {
25-
"test": "npm run format:check && tsc && nyc mocha --reporter spec --slow 200 --bail --timeout 10000 test/socket.io.js",
25+
"test": "npm run format:check && tsc && nyc mocha --require ts-node/register --reporter spec --slow 200 --bail --timeout 10000 test/socket.io.ts",
2626
"format:check": "prettier --check 'lib/**/*.ts' 'test/**/*.js'",
2727
"format:fix": "prettier --write 'lib/**/*.ts' 'test/**/*.js'"
2828
},
@@ -37,6 +37,7 @@
3737
"devDependencies": {
3838
"@types/cookie": "^0.4.0",
3939
"@types/cors": "^2.8.7",
40+
"@types/mocha": "^8.0.3",
4041
"@types/node": "^14.11.2",
4142
"babel-eslint": "^10.1.0",
4243
"eslint": "^7.9.0",
@@ -47,6 +48,7 @@
4748
"prettier": "^1.19.1",
4849
"superagent": "^3.8.2",
4950
"supertest": "^3.0.0",
51+
"ts-node": "^9.0.0",
5052
"typescript": "^4.0.3"
5153
},
5254
"contributors": [
File renamed without changes.

test/socket.io.js renamed to test/socket.io.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22

3+
import { Server } from "..";
4+
35
const http = require("http").Server;
46
const io = require("..");
57
const fs = require("fs");
@@ -12,7 +14,7 @@ const expect = require("expect.js");
1214
require("./support/util");
1315

1416
// Creates a socket.io client for the given server
15-
function client(srv, nsp, opts) {
17+
function client(srv, nsp?: string | object, opts?: object) {
1618
if ("object" == typeof nsp) {
1719
opts = nsp;
1820
nsp = null;
@@ -88,7 +90,7 @@ describe("socket.io", () => {
8890
});
8991
});
9092

91-
describe("port", done => {
93+
describe("port", () => {
9294
it("should be bound", done => {
9395
const sockets = io(54010);
9496
request("http://localhost:54010")
@@ -335,7 +337,7 @@ describe("socket.io", () => {
335337
}
336338

337339
it("should stop socket and timers", done => {
338-
exec(fixture("server-close.js"), done);
340+
exec(fixture("server-close.ts"), done);
339341
});
340342
});
341343
});
@@ -345,7 +347,7 @@ describe("socket.io", () => {
345347
const { Namespace } = require("../dist/namespace");
346348

347349
it("should be accessible through .sockets", () => {
348-
const sio = io();
350+
const sio: Server = io();
349351
expect(sio.sockets).to.be.a(Namespace);
350352
});
351353

@@ -1721,8 +1723,11 @@ describe("socket.io", () => {
17211723
});
17221724

17231725
it("should not crash when messing with Object prototype (and other globals)", done => {
1726+
// @ts-ignore
17241727
Object.prototype.foo = "bar";
1728+
// @ts-ignore
17251729
global.File = "";
1730+
// @ts-ignore
17261731
global.Blob = [];
17271732
const srv = http();
17281733
const sio = io(srv);
@@ -2101,7 +2106,7 @@ describe("socket.io", () => {
21012106
});
21022107
});
21032108

2104-
describe("middleware", done => {
2109+
describe("middleware", () => {
21052110
const { Socket } = require("../dist/socket");
21062111

21072112
it("should call functions", done => {
@@ -2270,7 +2275,7 @@ describe("socket.io", () => {
22702275
});
22712276
});
22722277

2273-
describe("socket middleware", done => {
2278+
describe("socket middleware", () => {
22742279
const { Socket } = require("../dist/socket");
22752280

22762281
it("should call functions", done => {
File renamed without changes.

0 commit comments

Comments
 (0)