diff --git a/.travis.yml b/.travis.yml index 67a7f9b..be9e7c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,14 @@ language: node_js node_js: - "node" - - "8" - - "7" - "6" - - "4" env: - - REACT_VERSION=0.13 - - REACT_VERSION=0.14 - - REACT_VERSION=15 - - REACT_VERSION=16 -before_script: - - ./install-dependencies.sh || echo "ignoring errors during setup" + - REACT=0.13 + - REACT=0.14 + - REACT=15 + - REACT=16 script: - npm run travisci +cache: + directories: + - node_modules diff --git a/README.md b/README.md index 05c78c2..302a280 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # react-component-update +[![npm package](https://badge.fury.io/js/react-component-update.svg)](https://badge.fury.io/js/react-component-update) +![node version](https://img.shields.io/node/v/react-component-update.svg) [![Build Status](https://travis-ci.org/wimpyprogrammer/react-component-update.svg?branch=master)](https://travis-ci.org/wimpyprogrammer/react-component-update) [![codecov](https://codecov.io/gh/wimpyprogrammer/react-component-update/branch/master/graph/badge.svg)](https://codecov.io/gh/wimpyprogrammer/react-component-update) [![Known Vulnerabilities](https://snyk.io/test/github/wimpyprogrammer/react-component-update/badge.svg)](https://snyk.io/test/github/wimpyprogrammer/react-component-update) diff --git a/install-dependencies.sh b/install-dependencies.sh deleted file mode 100755 index c1c6841..0000000 --- a/install-dependencies.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -ev - -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 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 - -# 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 -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 2c7960a..6c68390 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,21 @@ { "name": "react-component-update", - "version": "1.1.1", + "version": "1.2.0", "description": "Extends the native React Component to streamline updates", "main": "lib/index.js", "files": [ "lib/**/!(*.spec).js" ], + "engines": { + "node": ">=6" + }, "scripts": { "clean": "rimraf lib", "build": "npm run clean && babel src --out-dir lib", + "install-react": "enzyme-adapter-react-install 16", "lint": "eslint ./", "test": "jest", - "travisci": "npm run lint && jest && codecov", + "travisci": "npm run install-react && npm run lint && npm run test && codecov", "publish-please": "publish-please", "prepublish": "publish-please guard" }, @@ -27,7 +31,7 @@ "homepage": "https://github.com/wimpyprogrammer/react-component-update#readme", "devDependencies": { "babel-cli": "^6.26.0", - "babel-jest": "^21.2.0", + "babel-jest": "^23.0.0", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", @@ -35,22 +39,23 @@ "codecov": "^3.0.0", "create-react-class": "^15.6.0", "dirty-chai": "^2.0.0", - "enzyme": "^3.1.0", + "enzyme": "^3.4.4", "enzyme-adapter-react-16": "^1.0.1", - "eslint": "^4.12.1", - "eslint-config-airbnb": "^16.1.0", - "eslint-plugin-import": "^2.3.0", - "eslint-plugin-jsx-a11y": "^6.0.2", - "eslint-plugin-react": "^7.1.0", - "jest": "^21.2.1", + "enzyme-adapter-react-helper": "^1.2.2", + "eslint": "^5.0.1", + "eslint-config-airbnb": "^17.1.0", + "eslint-plugin-import": "^2.13.0", + "eslint-plugin-jsx-a11y": "^6.1.0", + "eslint-plugin-react": "^7.11.0", + "jest": "^23.5.0", "lodash.uniqueid": "^4.0.1", - "publish-please": "^2.3.1", + "publish-please": "^3.2.0", "react": "*", "react-dom": "*", "react-test-renderer": "*", "rimraf": "^2.6.1", - "sinon": "^4.1.2", - "sinon-chai": "^2.13.0" + "sinon": "^6.0.1", + "sinon-chai": "^3.0.0" }, "peerDependencies": { "react": "*" diff --git a/src/component.spec.js b/src/component.spec.js index 04f38b0..55060ae 100644 --- a/src/component.spec.js +++ b/src/component.spec.js @@ -2,7 +2,7 @@ /* eslint-disable react/no-multi-comp */ import chai, { expect } from 'chai'; import dirtyChai from 'dirty-chai'; -import { mount } from 'enzyme'; +import { shallow } from 'enzyme'; import uniqueId from 'lodash.uniqueid'; import React from 'react'; import sinon from 'sinon'; @@ -41,7 +41,7 @@ describe('Component extension', () => { const callbackRender = sandbox.spy(TestComponent.prototype, 'render'); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); @@ -52,7 +52,7 @@ describe('Component extension', () => { }); it('runs on mount with first parameter of component props', () => { - expect(callbackWill.firstCall).to.have.been.calledWith(component.props()); + expect(callbackWill.firstCall).to.have.been.calledWith(component.instance().props); }); it('runs on mount with "this" context of component', () => { @@ -69,13 +69,13 @@ describe('Component extension', () => { }); it('runs on props update when no props change', () => { - component.setProps(component.props()); + component.setProps(component.instance().props); expect(callbackWill).to.have.been.calledTwice(); }); it('runs on props update with first parameter of component props', () => { component.setProps(getUniqueProps()); - expect(callbackWill.secondCall).to.have.been.calledWith(component.props()); + expect(callbackWill.secondCall).to.have.been.calledWith(component.instance().props); }); it('runs on props update with "this" context of component', () => { @@ -100,7 +100,7 @@ describe('Component extension', () => { }); it('runs on mount with first parameter of component props', () => { - expect(callbackDid.firstCall).to.have.been.calledWith(component.props()); + expect(callbackDid.firstCall).to.have.been.calledWith(component.instance().props); }); it('runs on mount with second parameter of component state', () => { @@ -121,12 +121,12 @@ describe('Component extension', () => { }); it('runs on props update when no props change', () => { - component.setProps(component.props()); + component.setProps(component.instance().props); expect(callbackDid).to.have.been.calledTwice(); }); it('runs on props update with first parameter of previous component props', () => { - const initialProps = component.props(); + const initialProps = component.instance().props; component.setProps(getUniqueProps()); expect(callbackDid.secondCall).to.have.been.calledWith(initialProps); }); @@ -153,7 +153,7 @@ describe('Component extension', () => { }); it('runs on state update with first parameter of previous component props', () => { - const initialProps = component.props(); + const initialProps = component.instance().props; component.setState(getUniqueState()); expect(callbackDid.secondCall).to.have.been.calledWith(initialProps); }); @@ -220,7 +220,7 @@ describe('Component extension with overrides calling super()', () => { const callbackDid = sandbox.spy(TestComponentWithSuper.prototype, 'componentDidMountOrUpdate'); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); @@ -303,10 +303,13 @@ describe('Component extension with overrides calling super()', () => { describe('Component extension with overrides not calling super()', () => { class TestComponentWithoutSuper extends Component { - componentWillMount() {} - componentDidMount() {} - componentWillReceiveProps() {} - componentDidUpdate() {} + componentWillMount() { } + + componentDidMount() { } + + componentWillReceiveProps() { } + + componentDidUpdate() { } render() { return null; @@ -317,7 +320,7 @@ describe('Component extension with overrides not calling super()', () => { const callbackDid = sandbox.spy(TestComponentWithoutSuper.prototype, 'componentDidMountOrUpdate'); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); diff --git a/src/pureComponent.spec.js b/src/pureComponent.spec.js index 5dfaaa9..c70a1e2 100644 --- a/src/pureComponent.spec.js +++ b/src/pureComponent.spec.js @@ -2,7 +2,7 @@ /* eslint-disable react/no-multi-comp */ import chai, { expect } from 'chai'; import dirtyChai from 'dirty-chai'; -import { mount } from 'enzyme'; +import { shallow } from 'enzyme'; import uniqueId from 'lodash.uniqueid'; import React from 'react'; import sinon from 'sinon'; @@ -44,7 +44,7 @@ descriptor('PureComponent extension', () => { const callbackRender = sandbox.spy(TestComponent.prototype, 'render'); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); @@ -55,7 +55,7 @@ descriptor('PureComponent extension', () => { }); it('runs on mount with first parameter of component props', () => { - expect(callbackWill.firstCall).to.have.been.calledWith(component.props()); + expect(callbackWill.firstCall).to.have.been.calledWith(component.instance().props); }); it('runs on mount with "this" context of component', () => { @@ -72,13 +72,13 @@ descriptor('PureComponent extension', () => { }); it('runs on props update when no props change', () => { - component.setProps(component.props()); + component.setProps(component.instance().props); expect(callbackWill).to.have.been.calledTwice(); }); it('runs on props update with first parameter of component props', () => { component.setProps(getUniqueProps()); - expect(callbackWill.secondCall).to.have.been.calledWith(component.props()); + expect(callbackWill.secondCall).to.have.been.calledWith(component.instance().props); }); it('runs on props update with "this" context of component', () => { @@ -103,7 +103,7 @@ descriptor('PureComponent extension', () => { }); it('runs on mount with first parameter of component props', () => { - expect(callbackDid.firstCall).to.have.been.calledWith(component.props()); + expect(callbackDid.firstCall).to.have.been.calledWith(component.instance().props); }); it('runs on mount with second parameter of component state', () => { @@ -124,7 +124,7 @@ descriptor('PureComponent extension', () => { }); it('runs on props update with first parameter of previous component props', () => { - const initialProps = component.props(); + const initialProps = component.instance().props; component.setProps(getUniqueProps()); expect(callbackDid.secondCall).to.have.been.calledWith(initialProps); }); @@ -146,7 +146,7 @@ descriptor('PureComponent extension', () => { }); it('runs on state update with first parameter of previous component props', () => { - const initialProps = component.props(); + const initialProps = component.instance().props; component.setState(getUniqueState()); expect(callbackDid.secondCall).to.have.been.calledWith(initialProps); }); @@ -215,7 +215,7 @@ descriptor('PureComponent extension with overrides calling super()', () => { const callbackDid = sandbox.spy(TestComponentWithSuper.prototype, 'componentDidMountOrUpdate'); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); @@ -300,10 +300,13 @@ descriptor('Component extension with overrides not calling super()', () => { const { PureComponent } = require('./'); // eslint-disable-line global-require class TestComponentWithoutSuper extends PureComponent { - componentWillMount() {} - componentDidMount() {} - componentWillReceiveProps() {} - componentDidUpdate() {} + componentWillMount() { } + + componentDidMount() { } + + componentWillReceiveProps() { } + + componentDidUpdate() { } render() { return null; @@ -314,7 +317,7 @@ descriptor('Component extension with overrides not calling super()', () => { const callbackDid = sandbox.spy(TestComponentWithoutSuper.prototype, 'componentDidMountOrUpdate'); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); diff --git a/src/withEvents.spec.js b/src/withEvents.spec.js index 1669e03..a655b1d 100644 --- a/src/withEvents.spec.js +++ b/src/withEvents.spec.js @@ -2,7 +2,7 @@ import chai, { expect } from 'chai'; import createReactClass from 'create-react-class'; import dirtyChai from 'dirty-chai'; -import { mount } from 'enzyme'; +import { shallow } from 'enzyme'; import uniqueId from 'lodash.uniqueid'; import React from 'react'; import sinon from 'sinon'; @@ -37,7 +37,7 @@ describe('withEvents extension', () => { const callbackRender = sandbox.spy(TestComponent.prototype, 'render'); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); @@ -48,7 +48,7 @@ describe('withEvents extension', () => { }); it('runs on mount with first parameter of component props', () => { - expect(callbackWill.firstCall).to.have.been.calledWith(component.props()); + expect(callbackWill.firstCall).to.have.been.calledWith(component.instance().props); }); it('runs on mount with "this" context of component', () => { @@ -65,13 +65,13 @@ describe('withEvents extension', () => { }); it('runs on props update when no props change', () => { - component.setProps(component.props()); + component.setProps(component.instance().props); expect(callbackWill).to.have.been.calledTwice(); }); it('runs on props update with first parameter of component props', () => { component.setProps(getUniqueProps()); - expect(callbackWill.secondCall).to.have.been.calledWith(component.props()); + expect(callbackWill.secondCall).to.have.been.calledWith(component.instance().props); }); it('runs on props update with "this" context of component', () => { @@ -96,7 +96,7 @@ describe('withEvents extension', () => { }); it('runs on mount with first parameter of component props', () => { - expect(callbackDid.firstCall).to.have.been.calledWith(component.props()); + expect(callbackDid.firstCall).to.have.been.calledWith(component.instance().props); }); it('runs on mount with second parameter of component state', () => { @@ -117,7 +117,7 @@ describe('withEvents extension', () => { }); it('runs on props update with first parameter of previous component props', () => { - const initialProps = component.props(); + const initialProps = component.instance().props; component.setProps(getUniqueProps()); expect(callbackDid.secondCall).to.have.been.calledWith(initialProps); }); @@ -139,7 +139,7 @@ describe('withEvents extension', () => { }); it('runs on state update with first parameter of previous component props', () => { - const initialProps = component.props(); + const initialProps = component.instance().props; component.setState(getUniqueState()); expect(callbackDid.secondCall).to.have.been.calledWith(initialProps); }); @@ -183,7 +183,7 @@ describe('withEvents extension with overrides', () => { })); beforeEach(() => { - component = mount(); + component = shallow(); }); afterEach(() => sandbox.reset()); diff --git a/test-setup.js b/test-setup.js index eea9bcb..185f503 100644 --- a/test-setup.js +++ b/test-setup.js @@ -1,11 +1,4 @@ -/* eslint-disable global-require, import/no-extraneous-dependencies, import/no-unresolved */ -const { configure } = require('enzyme'); -const reactVersion = require('react').version; +/* eslint-env mocha */ +import configure from 'enzyme-adapter-react-helper'; -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() }); +configure();