Skip to content

Commit b423375

Browse files
committed
test: Add jest config
1 parent 09e47eb commit b423375

7 files changed

+1725
-57
lines changed

.eslintrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
},
88
"env": {
99
"browser": true,
10-
"node": true
10+
"node": true,
11+
"jest/globals": true
1112
},
12-
"plugins": ["@typescript-eslint", "react", "react-hooks", "jsx-a11y", "import"],
13+
"plugins": ["@typescript-eslint", "react", "react-hooks", "jsx-a11y", "import", "jest"],
1314
"globals": {
1415
"importScripts": true,
1516
"workbox": true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
node_modules/
33
dist/
44
public/
5+
coverage/
56

67
npm-debug.log
78
yarn-error.log

jest.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
roots: ['./test'],
3+
transform: {
4+
'^.+\\.tsx?$': 'ts-jest',
5+
'\\.(less)$': '<rootDir>/jest.transformer.js',
6+
},
7+
collectCoverage: true,
8+
};

jest.transformer.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
process(src, filename) {
5+
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
6+
},
7+
};

package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"client": "./node_modules/.bin/ts-node build/dev-server.ts",
1010
"build": "./node_modules/.bin/ts-node build/build.ts",
1111
"lint": "./node_modules/.bin/eslint ./ --ext js,jsx,ts,tsx --ignore-pattern .eslintignore --cache",
12-
"move-dist": "rm -rf public/audio && rm -rf public/avatar && rm -rf public/css && rm -rf public/fonts && rm -rf public/img && rm -rf public/js && mv -f dist/fiora/* public"
12+
"move-dist": "rm -rf public/audio && rm -rf public/avatar && rm -rf public/css && rm -rf public/fonts && rm -rf public/img && rm -rf public/js && mv -f dist/fiora/* public",
13+
"test": "jest"
1314
},
1415
"pre-commit": [
1516
"lint"
@@ -74,7 +75,10 @@
7475
"xss": "^0.3.7"
7576
},
7677
"devDependencies": {
78+
"@types/enzyme": "^3.10.3",
79+
"@types/enzyme-adapter-react-16": "^1.0.5",
7780
"@types/ip": "^1.1.0",
81+
"@types/jest": "^24.0.18",
7882
"@types/koa": "^2.0.49",
7983
"@types/koa-send": "^4.1.2",
8084
"@types/koa-static": "^4.0.1",
@@ -100,9 +104,12 @@
100104
"copy-webpack-plugin": "^4.5.1",
101105
"cross-env": "^5.1.6",
102106
"css-loader": "^3.2.0",
107+
"enzyme": "^3.10.0",
108+
"enzyme-adapter-react-16": "^1.14.0",
103109
"eslint": "^6.1.0",
104110
"eslint-config-airbnb": "^18.0.1",
105111
"eslint-plugin-import": "^2.18.2",
112+
"eslint-plugin-jest": "^22.15.2",
106113
"eslint-plugin-jsx-a11y": "^6.2.3",
107114
"eslint-plugin-react": "^7.14.3",
108115
"eslint-plugin-react-hooks": "^1.7.0",
@@ -114,6 +121,7 @@
114121
"function-bind": "^1.1.0",
115122
"html-webpack-plugin": "^3.2.0",
116123
"http-proxy-middleware": "^0.17.3",
124+
"jest": "^24.9.0",
117125
"less": "^3.10.3",
118126
"less-loader": "^4.1.0",
119127
"less-plugin-autoprefix": "^1.5.1",
@@ -129,6 +137,7 @@
129137
"script-ext-html-webpack-plugin": "^2.0.1",
130138
"semver": "^5.3.0",
131139
"style-loader": "^0.15.0",
140+
"ts-jest": "^24.0.2",
132141
"ts-loader": "^6.0.4",
133142
"ts-node": "^8.3.0",
134143
"typescript": "^3.5.3",

test/example.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// import { configure, mount } from 'enzyme';
2+
// import Adapter from 'enzyme-adapter-react-16';
3+
4+
// configure({ adapter: new Adapter() });
5+
6+
// const popup = mount(
7+
// <Popup visible onClose={() => popup.setProps({ visible: false })}>
8+
// <p className="content">content</p>
9+
// </Popup>,
10+
// );
11+
12+
// // toMatchSnapshot
13+
// expect(popup).toMatchSnapshot({});
14+
15+
test('example', () => {
16+
expect(1 + 1).toBe(2);
17+
});

0 commit comments

Comments
 (0)