From 97ca004422555eaacdeb0628f87da74fcbbd56ea Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Tue, 10 Oct 2017 20:50:27 -0500 Subject: [PATCH 01/11] Allow latest React build to fail --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index a121ef3..0c5a36d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,9 @@ env: - REACT_VERSION=0.14 - REACT_VERSION=15 - REACT_VERSION=* +matrix: + allow_failures: + - env: 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' From 0b0bc85895e30bc7defa990c190bd677ccc6da4f Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Tue, 10 Oct 2017 21:26:36 -0500 Subject: [PATCH 02/11] Fix React 0.13 build dependencies --- install-dependencies.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install-dependencies.sh b/install-dependencies.sh index 873b2fe..1f2e6e5 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -13,7 +13,9 @@ npm prune npm install # Conditionally install dependencies per https://github.com/airbnb/enzyme#installation -if [ "${REACT_VERSION:0:2}" = "0." ]; then +if [ "${REACT_VERSION}" = "0.13" ]; then + npm install --no-save react@$REACT_VERSION +elif [ "${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 From c36f041df1aec271cbf21d18ecfc9662ad8a5ae2 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Thu, 23 Nov 2017 20:39:51 -0600 Subject: [PATCH 03/11] Require React 16 build to succeed. --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c5a36d..692a072 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,7 @@ env: - REACT_VERSION=0.13 - REACT_VERSION=0.14 - REACT_VERSION=15 - - REACT_VERSION=* -matrix: - allow_failures: - - env: REACT_VERSION=* + - REACT_VERSION=16 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' From 1228fecb80c05b1ba54c9dddfcfe9c5f50b47929 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Thu, 23 Nov 2017 21:29:11 -0600 Subject: [PATCH 04/11] Upgrade to Enzyme 3. Add React 16 adapter and test setup file. --- install-dependencies.sh | 19 ++++++++++++------- package.json | 4 +++- test-setup.js | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 test-setup.js diff --git a/install-dependencies.sh b/install-dependencies.sh index 1f2e6e5..4072f34 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -1,7 +1,12 @@ #!/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 @@ -13,12 +18,12 @@ npm prune npm install # Conditionally install dependencies per https://github.com/airbnb/enzyme#installation -if [ "${REACT_VERSION}" = "0.13" ]; then - npm install --no-save react@$REACT_VERSION -elif [ "${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 +else # React 15+ + npm install --no-save react@$REACT_VERSION react-dom@$REACT_VERSION react-test-renderer@$REACT_VERSION enzyme-adapter-react-$REACT_VERSION_NORMALIZED fi npm ls --depth=0 diff --git a/package.json b/package.json index 83e8c97..6b594c3 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", @@ -55,6 +56,7 @@ "jest": { "coverageDirectory": "./coverage/", "collectCoverage": true, + "setupTestFrameworkScriptFile": "/test-setup.js", "testMatch": [ "**/src/*.spec.js?(x)" ] diff --git a/test-setup.js b/test-setup.js new file mode 100644 index 0000000..1f7dcd3 --- /dev/null +++ b/test-setup.js @@ -0,0 +1,19 @@ +/* eslint-disable global-require, import/no-extraneous-dependencies, import/no-unresolved */ +const configure = require('enzyme').configure; + +let Adapter; + +[16, 15, 14, 13].forEach((adapterVersion) => { + if (Adapter) return; + + try { + // eslint-disable-next-line import/no-dynamic-require + Adapter = require(`enzyme-adapter-react-${adapterVersion}`); + // eslint-disable-next-line no-console + console.log(`Using enzyme adapter ${adapterVersion}`); + } catch (ex) { + // Ignore failure, try the next version + } +}); + +configure({ adapter: new Adapter() }); From 9efa334c655dfcb4102cbdb4416b7fe199804549 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Wed, 29 Nov 2017 23:27:53 -0600 Subject: [PATCH 05/11] Uninstall default Enzyme adapter during setup By default, enzyme-adapter-react-16 is installed per the devDependencies in the package.json. We should uninstall this so it isn't detected by test-setup.js which looks for available adapters. --- install-dependencies.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/install-dependencies.sh b/install-dependencies.sh index 4072f34..c164e66 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -11,12 +11,10 @@ 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_NORMALIZED}" = "13" ]; then npm install --no-save react@$REACT_VERSION enzyme-adapter-react-$REACT_VERSION_NORMALIZED From 53c0390f1832b4b9a96202c92be98fec67708285 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Wed, 29 Nov 2017 23:28:42 -0600 Subject: [PATCH 06/11] Remove console.log from test-setup.js The setup script runs before each test fixture, so these messages clutter the test output. --- test-setup.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test-setup.js b/test-setup.js index 1f7dcd3..33325fa 100644 --- a/test-setup.js +++ b/test-setup.js @@ -9,8 +9,6 @@ let Adapter; try { // eslint-disable-next-line import/no-dynamic-require Adapter = require(`enzyme-adapter-react-${adapterVersion}`); - // eslint-disable-next-line no-console - console.log(`Using enzyme adapter ${adapterVersion}`); } catch (ex) { // Ignore failure, try the next version } From 3a19e20a0add2191672924a57bb34504140f0911 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Wed, 29 Nov 2017 23:30:29 -0600 Subject: [PATCH 07/11] Replace .getNode() with .instance() Per the Enzyme v2.x to Enzyme v3.x upgrade instructions at https://github.com/airbnb/enzyme/blob/master/docs/guides/migration-from-2-to-3.md. --- src/component.spec.js | 10 +++++----- src/pureComponent.spec.js | 10 +++++----- src/withEvents.spec.js | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) 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()', () => { From 3e4ab00f732e4f401a9b99bc922854c36c293a4c Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Fri, 1 Dec 2017 19:32:16 -0600 Subject: [PATCH 08/11] Scope test utilities to the appropriate React versions Uninstall react-addons-test-utils from default devDependencies. Don't install react-test-renderer for React 16. --- install-dependencies.sh | 4 +++- package.json | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/install-dependencies.sh b/install-dependencies.sh index c164e66..c1c6841 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -20,8 +20,10 @@ 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 -else # React 15+ +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 6b594c3..950444f 100644 --- a/package.json +++ b/package.json @@ -43,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", From 925cce19fa822ed3a791c2f16c0c05c1710a5fb7 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Fri, 1 Dec 2017 22:11:59 -0600 Subject: [PATCH 09/11] Base Enzyme adapter on current React version Fix an issue where the default adapter (v16) is used for React v15 builds in TravisCI. --- test-setup.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/test-setup.js b/test-setup.js index 33325fa..cf91e3a 100644 --- a/test-setup.js +++ b/test-setup.js @@ -1,17 +1,11 @@ /* eslint-disable global-require, import/no-extraneous-dependencies, import/no-unresolved */ const configure = require('enzyme').configure; +const reactVersion = require('react').version; -let Adapter; +const [majorReactVersion, minorReactVersion] = reactVersion.split('.'); +const adapterVersion = (majorReactVersion !== '0') ? majorReactVersion : minorReactVersion; -[16, 15, 14, 13].forEach((adapterVersion) => { - if (Adapter) return; - - try { - // eslint-disable-next-line import/no-dynamic-require - Adapter = require(`enzyme-adapter-react-${adapterVersion}`); - } catch (ex) { - // Ignore failure, try the next version - } -}); +// eslint-disable-next-line import/no-dynamic-require +const Adapter = require(`enzyme-adapter-react-${adapterVersion}`); configure({ adapter: new Adapter() }); From 6fa75a60c75a5ce149ee7a14e339b011a0a69fc2 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Fri, 1 Dec 2017 22:12:51 -0600 Subject: [PATCH 10/11] Remove custom npm version Fix Node v9.2.0 failures in TravisCI. --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 692a072..67a7f9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,11 +10,6 @@ env: - REACT_VERSION=0.14 - REACT_VERSION=15 - REACT_VERSION=16 -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;' before_script: - ./install-dependencies.sh || echo "ignoring errors during setup" script: From 30a75918ce18c6e0fc470563c181237f8a4a45b5 Mon Sep 17 00:00:00 2001 From: Drew Keller Date: Fri, 1 Dec 2017 23:05:17 -0600 Subject: [PATCH 11/11] Bump minor version to 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 950444f..864f4a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-component-update", - "version": "1.0.1", + "version": "1.1.0", "description": "Extends the native React Component to streamline updates", "main": "lib/index.js", "scripts": {