Skip to content

Commit

Permalink
Implement testing in React 0.14, 15, 16, add wallaby.js, use enzyme (r…
Browse files Browse the repository at this point in the history
…eduxjs#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
  • Loading branch information
cellog authored and josepot committed Sep 21, 2018
1 parent 6a1e72a commit 6638d95
Show file tree
Hide file tree
Showing 27 changed files with 30,304 additions and 543 deletions.
1 change: 0 additions & 1 deletion .babelrc
Expand Up @@ -25,7 +25,6 @@
"env": {
"test": {
"plugins": [
"istanbul",
["transform-es2015-modules-commonjs", { "loose": true }]
]
},
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -6,3 +6,8 @@ lib
.nyc_output
coverage
es
test/**/lcov.info
test/**/lcov-report
test/react/*/test/**/*.spec.js
test/react/**/src
lcov.info
12 changes: 11 additions & 1 deletion .travis.yml
@@ -1,8 +1,18 @@
language: node_js
node_js:
- "8"
before_install:
- 'nvm install-latest-npm'
env:
matrix:
- REACT=0.14
- REACT=15
- REACT=16.2
- REACT=16.3
- REACT=16.4
sudo: false
script:
- npm run lint
- npm test
- npm run test
after_success:
- npm run coverage
118 changes: 116 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -35,21 +35,135 @@ npm run build:umd:min

### Testing and Linting

To run the tests:
To run the tests in the latest React version:
```
npm run test
```

To run in explicit React versions (the number is the version, so `test:16.3` will run in React version `16.3`):
```
REACT=16.4 npm run test:ci
```

To run tests in all supported React versions, `0.14`, `15`, `16.2`, `16.3`, `16.4`,
```
REACT=all npm run test:ci
```

To continuously watch and run tests, run the following:
```
npm run test:watch
npm run test -- --watch
```

To perform linting with `eslint`, run the following:
```
npm run lint
```

#### Adding a new React version for testing

To add a new version of React to test react-redux against, create a directory structure
in this format for React version `XX`:

```
test/
react/
XX/
package.json
test/
getTestDeps.js
```

So, for example, to test against React 15.4:


```
test/
react/
15.4/
package.json
test/
getTestDeps.js
```

The package.json must include the correct versions of `react`, `react-dom`,
`react-test-renderer` and the correct enzyme adapter for the React version
being used, as well as the needed `create-react-class`, `jest`, `enzyme` versions
and the `jest` and `scripts` sections copied verbatim like this:

```json
{
"private": true,
"devDependencies": {
"create-react-class": "^15.6.3",
"enzyme": "^3.3.0",
"enzyme-adapter-react-15.4": "^1.0.6",
"jest": "^23.4.2",
"react": "15.4",
"react-dom": "15.4",
"react-test-renderer": "15.4"
},
"jest": {
"testURL": "http://localhost",
"collectCoverage": true,
"coverageDirectory": "./coverage"
},
"scripts": {
"test": "jest"
}
}
```

`getTestDeps.js` should load the version-specific enzyme adapter and
test renderer (all versions newer than 0.14 use `react-test-renderer`,
0.14 uses `react-addons-test-utils`):

```js
import enzyme from 'enzyme'
import TestRenderer from 'react-test-renderer'
import Adapter from 'enzyme-adapter-react-15.4'

enzyme.configure({ adapter: new Adapter() })

export { TestRenderer, enzyme }
```

Then you can run tests against this version with:

```
REACT=15.4 npm run test
```

and the new version will also be automatically included in

```
REACT=all npm run test
```

In addition, the new version should be added to the .travis.yml matrix list:

```yaml
language: node_js
node_js:
- "8"
before_install:
- 'nvm install-latest-npm'
env:
matrix:
- REACT=0.14
- REACT=15
- REACT=15.4
- REACT=16.2
- REACT=16.3
- REACT=16.4
sudo: false
script:
- npm run lint
- npm run test
after_success:
- npm run coverage
```

### New Features

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.
Expand Down

0 comments on commit 6638d95

Please sign in to comment.