You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+116-2
Original file line number
Diff line number
Diff line change
@@ -35,21 +35,135 @@ npm run build:umd:min
35
35
36
36
### Testing and Linting
37
37
38
-
To run the tests:
38
+
To run the tests in the latest React version:
39
39
```
40
40
npm run test
41
41
```
42
42
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
+
43
53
To continuously watch and run tests, run the following:
44
54
```
45
-
npm run test:watch
55
+
npm run test -- --watch
46
56
```
47
57
48
58
To perform linting with `eslint`, run the following:
49
59
```
50
60
npm run lint
51
61
```
52
62
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
+
importenzymefrom'enzyme'
123
+
importTestRendererfrom'react-test-renderer'
124
+
importAdapterfrom'enzyme-adapter-react-15.4'
125
+
126
+
enzyme.configure({ adapter:newAdapter() })
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
+
53
167
### New Features
54
168
55
169
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