Skip to content

Commit eee25a4

Browse files
cellogmarkerikson
authored andcommitted
Implement testing in React 0.14, 15, 16, add wallaby.js, use enzyme (#984)
* begin work * enable testing on 4 react versions on travis * enable local testing on 4 versions * enable running wallaby if installed * Fix tests in 0.14, 15, and 16 * remove 15.4, not really necessary and it requires a tweak to the install script * fix 2 major potential issues 1) by putting all the installs in setupTestEnv into a single npm command, npm --no-save becomes possible. When they are on separate lines, the 2nd npm i removes the previous line's work 2) after test runs, we restore the node_modules to what devDependencies says * update contributing docs and add missing test:watch * re-work to use subdirectories for testing specific react versions caveat: collecting coverage does not work yet, we need to combine the lcov reports * fully working! with merged coverage! * fix linting, remove unnecessary file * fix test:watch * fix travis tests to run in parallel for each version * oops, didn't make travis run the CI test * sigh... npm syntax error * speed up test suites by only installing the specific version needed * remove unused plugin * simplify test script options in package.json use the REACT env variable to run tests for a specific version, set it to "all" to run for all supported versions * simpler gitignore * remove unnecessary coverage merging, codecov does that automagically * simplify test running * new docs on testing specific React versions * move scripts to test/, remove unused dep * revert unintentional cosmetic changes * add default version for "npm test" * revert unintentional cosmetic changes to test import order * restore the correct test renderer version * fix travis, add a note about the matrix needing update on adding a React version * Add cross-spawn dependency * Use cross-spawn for consistent NPM installations cross-platform
1 parent 3e53ff9 commit eee25a4

27 files changed

+30304
-543
lines changed

.babelrc

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"env": {
2626
"test": {
2727
"plugins": [
28-
"istanbul",
2928
["transform-es2015-modules-commonjs", { "loose": true }]
3029
]
3130
},

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ lib
66
.nyc_output
77
coverage
88
es
9+
test/**/lcov.info
10+
test/**/lcov-report
11+
test/react/*/test/**/*.spec.js
12+
test/react/**/src
13+
lcov.info

.travis.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
language: node_js
22
node_js:
33
- "8"
4+
before_install:
5+
- 'nvm install-latest-npm'
6+
env:
7+
matrix:
8+
- REACT=0.14
9+
- REACT=15
10+
- REACT=16.2
11+
- REACT=16.3
12+
- REACT=16.4
13+
sudo: false
414
script:
515
- npm run lint
6-
- npm test
16+
- npm run test
717
after_success:
818
- npm run coverage

CONTRIBUTING.md

+116-2
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,135 @@ npm run build:umd:min
3535

3636
### Testing and Linting
3737

38-
To run the tests:
38+
To run the tests in the latest React version:
3939
```
4040
npm run test
4141
```
4242

43+
To run in explicit React versions (the number is the version, so `test:16.3` will run in React version `16.3`):
44+
```
45+
REACT=16.4 npm run test:ci
46+
```
47+
48+
To run tests in all supported React versions, `0.14`, `15`, `16.2`, `16.3`, `16.4`,
49+
```
50+
REACT=all npm run test:ci
51+
```
52+
4353
To continuously watch and run tests, run the following:
4454
```
45-
npm run test:watch
55+
npm run test -- --watch
4656
```
4757

4858
To perform linting with `eslint`, run the following:
4959
```
5060
npm run lint
5161
```
5262

63+
#### Adding a new React version for testing
64+
65+
To add a new version of React to test react-redux against, create a directory structure
66+
in this format for React version `XX`:
67+
68+
```
69+
test/
70+
react/
71+
XX/
72+
package.json
73+
test/
74+
getTestDeps.js
75+
```
76+
77+
So, for example, to test against React 15.4:
78+
79+
80+
```
81+
test/
82+
react/
83+
15.4/
84+
package.json
85+
test/
86+
getTestDeps.js
87+
```
88+
89+
The package.json must include the correct versions of `react`, `react-dom`,
90+
`react-test-renderer` and the correct enzyme adapter for the React version
91+
being used, as well as the needed `create-react-class`, `jest`, `enzyme` versions
92+
and the `jest` and `scripts` sections copied verbatim like this:
93+
94+
```json
95+
{
96+
"private": true,
97+
"devDependencies": {
98+
"create-react-class": "^15.6.3",
99+
"enzyme": "^3.3.0",
100+
"enzyme-adapter-react-15.4": "^1.0.6",
101+
"jest": "^23.4.2",
102+
"react": "15.4",
103+
"react-dom": "15.4",
104+
"react-test-renderer": "15.4"
105+
},
106+
"jest": {
107+
"testURL": "http://localhost",
108+
"collectCoverage": true,
109+
"coverageDirectory": "./coverage"
110+
},
111+
"scripts": {
112+
"test": "jest"
113+
}
114+
}
115+
```
116+
117+
`getTestDeps.js` should load the version-specific enzyme adapter and
118+
test renderer (all versions newer than 0.14 use `react-test-renderer`,
119+
0.14 uses `react-addons-test-utils`):
120+
121+
```js
122+
import enzyme from 'enzyme'
123+
import TestRenderer from 'react-test-renderer'
124+
import Adapter from 'enzyme-adapter-react-15.4'
125+
126+
enzyme.configure({ adapter: new Adapter() })
127+
128+
export { TestRenderer, enzyme }
129+
```
130+
131+
Then you can run tests against this version with:
132+
133+
```
134+
REACT=15.4 npm run test
135+
```
136+
137+
and the new version will also be automatically included in
138+
139+
```
140+
REACT=all npm run test
141+
```
142+
143+
In addition, the new version should be added to the .travis.yml matrix list:
144+
145+
```yaml
146+
language: node_js
147+
node_js:
148+
- "8"
149+
before_install:
150+
- 'nvm install-latest-npm'
151+
env:
152+
matrix:
153+
- REACT=0.14
154+
- REACT=15
155+
- REACT=15.4
156+
- REACT=16.2
157+
- REACT=16.3
158+
- REACT=16.4
159+
sudo: false
160+
script:
161+
- npm run lint
162+
- npm run test
163+
after_success:
164+
- npm run coverage
165+
```
166+
53167
### New Features
54168
55169
Please open an issue with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept.

0 commit comments

Comments
 (0)