Skip to content

Commit 2e27071

Browse files
committed
Setup unit tests using jest
1 parent 10b986a commit 2e27071

File tree

4 files changed

+1960
-35
lines changed

4 files changed

+1960
-35
lines changed

jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
"roots": [
3+
"<rootDir>/src"
4+
],
5+
"transform": {
6+
"^.+\\.tsx?$": "ts-jest"
7+
},
8+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
9+
"moduleFileExtensions": [
10+
"ts",
11+
"tsx",
12+
"js",
13+
"jsx",
14+
"json",
15+
"node"
16+
],
17+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"license": "Apache-2.0",
66
"scripts": {
77
"lint": "tsfmt --verify",
8-
"start": "ts-node ./bin/www.ts"
8+
"start": "ts-node ./bin/www.ts",
9+
"test": "npm run lint && jest --env node"
910
},
1011
"dependencies": {
1112
"codechain-keystore": "git://github.com/CodeChain-io/codechain-keystore.git#a168fc7eb01d31269d6e29ab9075315ae557471b",
@@ -25,10 +26,16 @@
2526
"@types/debug": "^0.0.30",
2627
"@types/express": "^4.16.0",
2728
"@types/http-errors": "^1.6.1",
29+
"@types/jest": "^23.3.1",
2830
"@types/lodash": "^4.14.116",
2931
"@types/morgan": "^1.7.35",
3032
"@types/node-sass-middleware": "^0.0.30",
3133
"@types/request-promise": "^4.1.42",
34+
"@types/supertest": "^2.0.5",
35+
"jest": "^23.5.0",
36+
"superagent": "^3.8.3",
37+
"supertest": "^3.1.0",
38+
"ts-jest": "^23.1.3",
3239
"tsc": "^1.20150623.0",
3340
"tslint": "^5.11.0",
3441
"tslint-config-prettier": "^1.14.0"

src/__test__/pign.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Application } from "express";
2+
import { createApp } from "../app";
3+
import * as request from "supertest";
4+
5+
let app: Application;
6+
7+
beforeEach(async () => {
8+
app = (await createApp())[0];
9+
});
10+
11+
test("ping", async () => {
12+
const response = await request(app).get("/ping");
13+
expect(response.status).toBe(200);
14+
});

0 commit comments

Comments
 (0)