diff --git a/.travis.yml b/.travis.yml index a121ef3..67a7f9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 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 npm@4.5 ; 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 npm@1.3 && npm install -g npm@1.4.28 && 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: diff --git a/install-dependencies.sh b/install-dependencies.sh index 873b2fe..c1c6841 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -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 diff --git a/package.json b/package.json index 83e8c97..950444f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -55,6 +55,7 @@ "jest": { "coverageDirectory": "./coverage/", "collectCoverage": true, + "setupTestFrameworkScriptFile": "/test-setup.js", "testMatch": [ "**/src/*.spec.js?(x)" ] diff --git a/src/component.spec.js b/src/component.spec.js index 68e6b57..15e06bc 100644 --- a/src/component.spec.js +++ b/src/component.spec.js @@ -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()', () => { @@ -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()', () => { @@ -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()', () => { @@ -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', () => { @@ -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()', () => { diff --git a/src/pureComponent.spec.js b/src/pureComponent.spec.js index 820bb82..8550d21 100644 --- a/src/pureComponent.spec.js +++ b/src/pureComponent.spec.js @@ -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()', () => { @@ -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()', () => { @@ -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()', () => { @@ -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', () => { @@ -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()', () => { diff --git a/src/withEvents.spec.js b/src/withEvents.spec.js index b1aa483..1669e03 100644 --- a/src/withEvents.spec.js +++ b/src/withEvents.spec.js @@ -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()', () => { @@ -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()', () => { @@ -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()', () => { @@ -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', () => { @@ -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()', () => { diff --git a/test-setup.js b/test-setup.js new file mode 100644 index 0000000..cf91e3a --- /dev/null +++ b/test-setup.js @@ -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() });