Skip to content

Commit 64e2832

Browse files
authored
Merge pull request #17 from iCHEF/chore/jest-setup
Setup unit test with jest, ts-jest and enzyme
2 parents 887ba5e + 7eeff31 commit 64e2832

26 files changed

+1623
-97
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88

99
### Added
10+
- Add `test` and `test:watch` scripts in root directory and every single package.(#17)
11+
- Add `jest`, `ts-jest`, `enzyme`, `enzyme-adapter-react-16` dependency.(#17)
12+
- Add a sample test of `ResponsiveLayer`. (#17)
1013
- Add a custom effect `useChartDimensions` to calculate the outer and inner dimension of the chart. (#16)
1114
- Add `useCartesianEncodings` to calculate the processed data and the visual encodings that we need in order to draw the graph. (#16)
1215
- Add a <SvgWithAxisFrame> component to deal with the size of the chart container, SVG, and the axes that generally used across different charts. (#16)
@@ -29,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2932
- Makes simple components such as `<Foo>` and `<ResponsiveLayer>` as an experiment to see if the project settings go well. (#1)
3033

3134
# Changed
35+
- Replace `lodash-es` with `lodash`.(#17)
3236
- Remove `selectors` from `AxisScale` and `ColorScale`. (#16)
3337
- Modify the config of `tslint` so that it won't continuing warning about the lack of dangling commas in functions. (#16)
3438
- Fix `HoverLayer` default props. (#14)

config/jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
globals: {
5+
'ts-jest': {
6+
tsConfig: '<rootDir>/config/tsconfig.base.json',
7+
},
8+
},
9+
setupFilesAfterEnv: ['<rootDir>/setupTests.js'],
10+
rootDir: '../',
11+
};

config/tsconfig.base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"baseUrl": "./packages",
44
"outDir": "lib",
55
"module": "es6",
6+
"esModuleInterop": true,
67
"target": "es5",
78
"lib": ["es2015", "dom"],
89
"sourceMap": true,

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,26 @@
1111
"type-check:watch": "lerna run type-check:watch --parallel --stream -- -- --preserveWatchOutput",
1212
"prepublish": "lerna run prepublish",
1313
"lint": "lerna run lint --parallel --stream",
14-
"clean": "lerna run --parallel clean"
14+
"clean": "lerna run --parallel clean",
15+
"test": "jest ./packages --config=config/jest.config.js --coverage",
16+
"test:watch": "jest ./packages --watch --config=config/jest.config.js"
1517
},
1618
"devDependencies": {
1719
"@types/d3": "^5.7.0",
18-
"@types/lodash-es": "^4.17.1",
20+
"@types/enzyme": "^3.9.0",
21+
"@types/enzyme-adapter-react-16": "^1.0.5",
22+
"@types/jest": "^24.0.9",
23+
"@types/lodash": "^4.14.122",
1924
"@types/memoize-one": "^4.1.0",
25+
"@types/react": "^16.8.7",
2026
"@types/react-dom": "^16.8.0",
2127
"@types/styled-components": "^4.1.6",
2228
"docz": "^0.13.7",
2329
"docz-theme-default": "^0.13.7",
2430
"fork-ts-checker-webpack-plugin": "^1.0.0",
31+
"enzyme": "^3.9.0",
32+
"enzyme-adapter-react-16": "^1.10.0",
33+
"jest": "^24.1.0",
2534
"lerna": "^3.8.0",
2635
"npm-run-all": "^4.1.5",
2736
"prop-types": "^15.7.1",
@@ -30,6 +39,7 @@
3039
"react-spring": "^8.0.7",
3140
"rimraf": "^2.6.3",
3241
"styled-components": "^4.1.3",
42+
"ts-jest": "^24.0.0",
3343
"tslint": "^5.12.0",
3444
"tslint-config-airbnb": "^5.11.1",
3545
"tslint-eslint-rules": "^5.4.0",

packages/animation/__tests__/animation.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/animation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"scripts": {
2626
"prepublish": "npm run clean && npm run build",
2727
"build": "run-p \"build:*\"",
28-
"build:esm": "tsc -p ./src",
28+
"build:esm": "tsc -p ./src/tsconfig.esm.json",
2929
"build:cjs": "tsc -p ./src/tsconfig.cjs.json",
3030
"clean": "rimraf ./dist ./lib ./es5 ./deploy",
3131
"lint": "tslint --project ./src",

packages/animation/setupTests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var enzyme = require('enzyme');
2+
var Adapter = require('enzyme-adapter-react-16');
3+
4+
enzyme.configure({ adapter: new Adapter() });

packages/animation/src/tsconfig.cjs.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
"compilerOptions": {
44
"module": "commonjs",
55
"outDir": "../lib/cjs"
6-
}
6+
},
7+
"exclude": [
8+
"node_modules",
9+
"**/*.test.tsx"
10+
]
711
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "./",
5+
"outDir": "../lib/esm"
6+
},
7+
"exclude": [
8+
"node_modules",
9+
"**/*.test.tsx"
10+
]
11+
}

packages/chart/__tests__/chart.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)