Run test against multiple react versions

This commit is contained in:
Wei Zhu 2017-11-06 17:34:14 +08:00
parent 42e219389d
commit 67fee48c6a
6 changed files with 71 additions and 33 deletions

View File

@ -3,39 +3,27 @@ sudo: false
language: node_js
node_js:
- "8.5"
- 8
env:
matrix:
- TEST_TYPE=lint
- TEST_TYPE=test:dist
- TEST_TYPE=test:lib
- TEST_TYPE=test:es
- TEST_TYPE=test:dom
- TEST_TYPE=test:node
matrix:
fast_finish: true
include:
- env: TEST_TYPE=lint
- env: REACT=16 TEST_TYPE=test:dist
- env: REACT=16 TEST_TYPE=test:lib
- env: REACT=16 TEST_TYPE=test:es
- env: REACT=16 TEST_TYPE=test:dom
- env: REACT=16 TEST_TYPE=test:node
- env: REACT=15 TEST_TYPE=test:dist
- env: REACT=15 TEST_TYPE=test:lib
- env: REACT=15 TEST_TYPE=test:es
- env: REACT=15 TEST_TYPE=test:dom
- env: REACT=15 TEST_TYPE=test:node
allow_failures:
- env: REACT=16 TEST_TYPE=test:dist
before_script:
- export TZ=China/Beijing
- date
- scripts/install-react.sh
script:
- |
if [ "$TEST_TYPE" = lint ]; then
npm run lint
elif [ "$TEST_TYPE" = test:dist ]; then
npm run dist && \
node ./tests/dekko/dist.test.js && \
LIB_DIR=dist npm test -- -w 2
elif [ "$TEST_TYPE" = test:lib ]; then
npm run compile && \
node ./tests/dekko/lib.test.js && \
LIB_DIR=lib npm test -- -w 2
elif [ "$TEST_TYPE" = test:es ]; then
npm run compile && \
LIB_DIR=es npm test -- -w 2
elif [ "$TEST_TYPE" = test:dom ]; then
npm test -- --coverage -w 2 && \
bash <(curl -s https://codecov.io/bash)
elif [ "$TEST_TYPE" = test:node ]; then
npm run test-node -- -w 2
fi
- scripts/travis-script.sh

View File

@ -12,6 +12,9 @@ describe('Form', () => {
describe('wrappedComponentRef', () => {
it('warns on functional component', () => {
if (process.env.REACT === '15') {
return;
}
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
const TestForm = () => <Form />;
const Wrapped = Form.create()(TestForm);

View File

@ -142,7 +142,6 @@
"react-infinite-scroller": "^1.0.15",
"react-intl": "^2.0.1",
"react-sublime-video": "^0.2.0",
"react-test-renderer": "^16.0.0",
"react-virtualized": "^9.10.1",
"remark-frontmatter": "^1.1.0",
"remark-parse": "^4.0.0",

7
scripts/install-react.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -x
if [ "$REACT" = 15 ]; then
npm i --no-save react@15 react-dom@15 react-test-renderer@15 enzyme-adapter-react-15
fi

34
scripts/travis-script.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
set -x
set -e
run_test() {
if [ "$REACT" != 16 ]; then
npm test -- -w 2 -u $*
else
npm test -- -w 2 $*
fi
}
if [ "$TEST_TYPE" = lint ]; then
npm run lint
elif [ "$TEST_TYPE" = test:dist ]; then
npm run dist
node ./tests/dekko/dist.test.js
LIB_DIR=dist run_test
elif [ "$TEST_TYPE" = test:lib ]; then
npm run compile
node ./tests/dekko/lib.test.js
LIB_DIR=lib run_test
elif [ "$TEST_TYPE" = test:es ]; then
npm run compile
LIB_DIR=es run_test
elif [ "$TEST_TYPE" = test:dom ]; then
run_test --coverage
if [ "$REACT" = 16 ]; then
bash <(curl -s https://codecov.io/bash)
fi
elif [ "$TEST_TYPE" = test:node ]; then
npm run test-node -- -w 2 -u
fi

View File

@ -1,3 +1,4 @@
/* eslint-disable global-require */
import { jsdom } from 'jsdom';
// fixed jsdom miss
@ -18,6 +19,12 @@ global.requestAnimationFrame = global.requestAnimationFrame || function (cb) {
};
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
let Adapter;
if (process.env.REACT === '15') {
Adapter = require('enzyme-adapter-react-15');
} else {
Adapter = require('enzyme-adapter-react-16');
}
Enzyme.configure({ adapter: new Adapter() });