Skip to content

Support React 16 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ env:
- REACT_VERSION=0.13
- REACT_VERSION=0.14
- REACT_VERSION=15
- REACT_VERSION=*
before_install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g [email protected] ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g [email protected] ;; 2.*) npm install -g npm@2 ;; esac ; fi'
- 'if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g [email protected] ; elif [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi'
install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g [email protected] && npm install -g [email protected] && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
- REACT_VERSION=16
before_script:
- ./install-dependencies.sh || echo "ignoring errors during setup"
script:
Expand Down
25 changes: 16 additions & 9 deletions install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
#!/bin/bash
set -ev

echo "installing React $REACT_VERSION"
REACT_VERSION_NORMALIZED=$REACT_VERSION
if [ "${REACT_VERSION:0:2}" = "0." ]; then
REACT_VERSION_NORMALIZED=${REACT_VERSION:2}
fi

echo "installing React $REACT_VERSION ($REACT_VERSION_NORMALIZED)"
echo "Travis Node Version $TRAVIS_NODE_VERSION"
node --version
npm --version

npm uninstall --no-save react react-dom react-addons-test-utils react-test-renderer
rm -rf node_modules/.bin/npm node_modules/.bin/npm.cmd node_modules/react node_modules/react-dom node_modules/react-addons-test-utils node_modules/react-test-renderer
npm uninstall --no-save react react-dom react-addons-test-utils react-test-renderer enzyme-adapter-react-16
rm -rf node_modules/.bin/npm node_modules/.bin/npm.cmd node_modules/react node_modules/react-dom node_modules/react-addons-test-utils node_modules/react-test-renderer node_modules/enzyme-adapter-react-16
npm prune

npm install

# Conditionally install dependencies per https://github.com/airbnb/enzyme#installation
if [ "${REACT_VERSION:0:2}" = "0." ]; then
npm install --no-save react@$REACT_VERSION react-dom@$REACT_VERSION react-addons-test-utils@$REACT_VERSION
else
npm install --no-save react@$REACT_VERSION react-dom@$REACT_VERSION react-test-renderer@$REACT_VERSION
if [ "${REACT_VERSION_NORMALIZED}" = "13" ]; then
npm install --no-save react@$REACT_VERSION enzyme-adapter-react-$REACT_VERSION_NORMALIZED
elif [ "${REACT_VERSION_NORMALIZED}" = "14" ]; then
npm install --no-save react@$REACT_VERSION react-dom@$REACT_VERSION react-addons-test-utils@$REACT_VERSION enzyme-adapter-react-$REACT_VERSION_NORMALIZED
elif [ "${REACT_VERSION_NORMALIZED}" = "15" ]; then
npm install --no-save react@$REACT_VERSION react-dom@$REACT_VERSION react-test-renderer@$REACT_VERSION enzyme-adapter-react-$REACT_VERSION_NORMALIZED
else # React 16+
npm install --no-save react@$REACT_VERSION react-dom@$REACT_VERSION enzyme-adapter-react-$REACT_VERSION_NORMALIZED
fi

npm ls --depth=0
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"codecov": "^2.3.0",
"create-react-class": "^15.6.0",
"dirty-chai": "^2.0.0",
"enzyme": "^2.8.2",
"enzyme": "^3.1.0",
"enzyme-adapter-react-16": "^1.0.1",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.3.0",
Expand All @@ -42,7 +43,6 @@
"lodash.uniqueid": "^4.0.1",
"publish-please": "^2.3.1",
"react": "*",
"react-addons-test-utils": "*",
"react-dom": "*",
"react-test-renderer": "*",
"rimraf": "^2.6.1",
Expand All @@ -55,6 +55,7 @@
"jest": {
"coverageDirectory": "./coverage/",
"collectCoverage": true,
"setupTestFrameworkScriptFile": "<rootDir>/test-setup.js",
"testMatch": [
"**/src/*.spec.js?(x)"
]
Expand Down
10 changes: 5 additions & 5 deletions src/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Component extension', () => {
});

it('runs on mount with "this" context of component', () => {
expect(callbackWill.firstCall).to.have.been.calledOn(component.getNode());
expect(callbackWill.firstCall).to.have.been.calledOn(component.instance());
});

it('runs on mount before render()', () => {
Expand All @@ -80,7 +80,7 @@ describe('Component extension', () => {

it('runs on props update with "this" context of component', () => {
component.setProps(getUniqueProps());
expect(callbackWill.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackWill.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on props update before render()', () => {
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('Component extension', () => {
});

it('runs on mount with "this" context of component', () => {
expect(callbackDid.firstCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.firstCall).to.have.been.calledOn(component.instance());
});

it('runs after render()', () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('Component extension', () => {

it('runs on props update with "this" context of component', () => {
component.setProps(getUniqueProps());
expect(callbackDid.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on state update', () => {
Expand All @@ -166,7 +166,7 @@ describe('Component extension', () => {

it('runs on state update with "this" context of component', () => {
component.setState(getUniqueState());
expect(callbackDid.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on props update before render()', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/pureComponent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ descriptor('PureComponent extension', () => {
});

it('runs on mount with "this" context of component', () => {
expect(callbackWill.firstCall).to.have.been.calledOn(component.getNode());
expect(callbackWill.firstCall).to.have.been.calledOn(component.instance());
});

it('runs on mount before render()', () => {
Expand All @@ -83,7 +83,7 @@ descriptor('PureComponent extension', () => {

it('runs on props update with "this" context of component', () => {
component.setProps(getUniqueProps());
expect(callbackWill.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackWill.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on props update before render()', () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ descriptor('PureComponent extension', () => {
});

it('runs on mount with "this" context of component', () => {
expect(callbackDid.firstCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.firstCall).to.have.been.calledOn(component.instance());
});

it('runs after render()', () => {
Expand All @@ -137,7 +137,7 @@ descriptor('PureComponent extension', () => {

it('runs on props update with "this" context of component', () => {
component.setProps(getUniqueProps());
expect(callbackDid.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on state update', () => {
Expand All @@ -159,7 +159,7 @@ descriptor('PureComponent extension', () => {

it('runs on state update with "this" context of component', () => {
component.setState(getUniqueState());
expect(callbackDid.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on props update before render()', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/withEvents.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('withEvents extension', () => {
});

it('runs on mount with "this" context of component', () => {
expect(callbackWill.firstCall).to.have.been.calledOn(component.getNode());
expect(callbackWill.firstCall).to.have.been.calledOn(component.instance());
});

it('runs on mount before render()', () => {
Expand All @@ -76,7 +76,7 @@ describe('withEvents extension', () => {

it('runs on props update with "this" context of component', () => {
component.setProps(getUniqueProps());
expect(callbackWill.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackWill.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on props update before render()', () => {
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('withEvents extension', () => {
});

it('runs on mount with "this" context of component', () => {
expect(callbackDid.firstCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.firstCall).to.have.been.calledOn(component.instance());
});

it('runs after render()', () => {
Expand All @@ -130,7 +130,7 @@ describe('withEvents extension', () => {

it('runs on props update with "this" context of component', () => {
component.setProps(getUniqueProps());
expect(callbackDid.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on state update', () => {
Expand All @@ -152,7 +152,7 @@ describe('withEvents extension', () => {

it('runs on state update with "this" context of component', () => {
component.setState(getUniqueState());
expect(callbackDid.secondCall).to.have.been.calledOn(component.getNode());
expect(callbackDid.secondCall).to.have.been.calledOn(component.instance());
});

it('runs on props update before render()', () => {
Expand Down
11 changes: 11 additions & 0 deletions test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable global-require, import/no-extraneous-dependencies, import/no-unresolved */
const configure = require('enzyme').configure;
const reactVersion = require('react').version;

const [majorReactVersion, minorReactVersion] = reactVersion.split('.');
const adapterVersion = (majorReactVersion !== '0') ? majorReactVersion : minorReactVersion;

// eslint-disable-next-line import/no-dynamic-require
const Adapter = require(`enzyme-adapter-react-${adapterVersion}`);

configure({ adapter: new Adapter() });