From bb3a624b24d19f19e8ca5eb6d142de8ff17613aa Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Sat, 9 Jul 2016 23:30:05 -0400 Subject: [PATCH] Update for React v15.2.x --- .eslintignore | 3 --- .gitignore | 4 ++++ examples/PropTable.js | 12 ++++++------ examples/server.js | 16 ++++++++++------ package.json | 15 +++++++-------- src/Position.js | 1 + test/ModalSpec.js | 20 ++++++++++---------- test/PositionSpec.js | 13 ++++++++----- test/TransitionSpec.js | 5 ++++- test/helpers.js | 6 ++---- test/index.js | 36 ++++++++++++++++++++++++++++-------- 11 files changed, 80 insertions(+), 51 deletions(-) delete mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 6570342e83..0000000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -lib -node_modules -webpack \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7dcd213ff0..35c165ba07 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,7 @@ build/Release # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules + +# Build artifacts +/examples/static +/lib diff --git a/examples/PropTable.js b/examples/PropTable.js index c1a6d7cecd..123fb4e55d 100644 --- a/examples/PropTable.js +++ b/examples/PropTable.js @@ -121,9 +121,9 @@ const PropTable = React.createClass({ }, getType(prop) { - let type = prop.type || {}; - let name = this.getDisplayTypeName(type.name); - let doclets = prop.doclets || {}; + const type = prop.type || {}; + const name = this.getDisplayTypeName(type.name); + const doclets = prop.doclets || {}; switch (name) { case 'object': @@ -139,9 +139,9 @@ const PropTable = React.createClass({ return i === (list.length - 1) ? current : current.concat(' | '); }, []); case 'array': - let child = this.getType({ type: type.value }); - - return {'array<'}{ child }{'>'}; + return ( + {'array<'}{this.getType({ type: type.value })}{'>'} + ); case 'enum': return this.renderEnum(type); case 'custom': diff --git a/examples/server.js b/examples/server.js index 9936c66a6b..11d7e2155b 100644 --- a/examples/server.js +++ b/examples/server.js @@ -1,9 +1,9 @@ -let webpack = require('webpack'); -let WebpackDevServer = require('webpack-dev-server'); -let config = require('../webpack/examples.config'); +import webpack from 'webpack'; +import WebpackDevServer from 'webpack-dev-server'; -new WebpackDevServer(webpack(config), { +import config from '../webpack/examples.config'; +const server = new WebpackDevServer(webpack(config), { contentBase: 'examples', publicPath: '/static/', hot: true, @@ -12,10 +12,14 @@ new WebpackDevServer(webpack(config), { stats: { colors: true } -}).listen(3000, 'localhost', function (err) { +}); + +server.listen(3000, 'localhost', err => { + /* eslint-disable no-console */ if (err) { - console.log(err); + console.error(err); } console.log('Listening at localhost:3000'); + /* eslint-enable no-console */ }); diff --git a/package.json b/package.json index ae576ff072..253fcc8705 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,12 @@ "clean": "rimraf lib", "clean:examples": "rimraf examples/static", "build": "npm run clean && babel src --out-dir lib", - "build:examples": "npm run clean:examples && babel-node ./webpack/run-webpack --config docs.config.js", - "examples": "npm run clean:examples && babel-node ./examples/server.js", - "lint": "eslint src test", + "build:examples": "npm run clean:examples && webpack --config webpack/docs.config.js", + "examples": "npm run clean:examples && babel-node examples/server.js", + "lint": "eslint examples/*.js src test *.js", "test": "npm run lint && npm run testonly", "testonly": "karma start --single-run", "tdd": "karma start", - "coverage": "COVERAGE=true npm run testonly", "release": "release" }, "peerDependencies": { @@ -41,7 +40,7 @@ "@monastic.panic/component-playground": "^2.0.0", "babel": "^5.8.38", "babel-core": "^5.8.38", - "babel-eslint": "^6.1.0", + "babel-eslint": "^6.1.2", "babel-loader": "^5.4.0", "babel-plugin-object-assign": "^1.2.1", "chai": "^3.5.0", @@ -71,11 +70,11 @@ "mocha": "^2.5.3", "node-libs-browser": "^1.0.0", "raw-loader": "^0.5.1", - "react": "~15.1.0", - "react-addons-test-utils": "~15.1.0", + "react": "^15.2.1", + "react-addons-test-utils": "^15.2.1", "react-bootstrap": "^0.29.5", "react-component-metadata": "^2.1.1", - "react-dom": "~15.1.0", + "react-dom": "^15.2.1", "react-hot-loader": "^1.3.0", "release-script": "^1.0.2", "rimraf": "^2.5.3", diff --git a/src/Position.js b/src/Position.js index 77e1b1fe6d..b1094b7c6d 100644 --- a/src/Position.js +++ b/src/Position.js @@ -60,6 +60,7 @@ class Position extends React.Component { delete props.target; delete props.container; delete props.containerPadding; + delete props.shouldUpdatePosition; const child = React.Children.only(children); return cloneElement( diff --git a/test/ModalSpec.js b/test/ModalSpec.js index 392cbb7074..51bd062b02 100644 --- a/test/ModalSpec.js +++ b/test/ModalSpec.js @@ -1,13 +1,16 @@ +import jQuery from 'jquery'; import React from 'react'; -import ReactDOM from 'react-dom'; import ReactTestUtils from 'react-addons-test-utils'; -import Modal from '../src/Modal'; -import { render } from './helpers'; -import jquery from 'jquery'; +import ReactDOM from 'react-dom'; import simulant from 'simulant'; + +import Modal from '../src/Modal'; + import Transition from '../src/Transition'; -let $ = componentOrNode => jquery(ReactDOM.findDOMNode(componentOrNode)); +import { render, shouldWarn } from './helpers'; + +const $ = componentOrNode => jQuery(ReactDOM.findDOMNode(componentOrNode)); describe('Modal', function () { let mountPoint; @@ -362,18 +365,15 @@ describe('Modal', function () { }); it('Should warn if the modal content is not focusable', function () { - let Dialog = ()=> ({ render(){ return
; } }); + shouldWarn('The modal content node does not accept focus'); - sinon.stub(console, 'error'); + const Dialog = () =>
; render( , focusableContainer); - - expect(console.error).to.have.been.calledOnce; - console.error.restore(); }); }); diff --git a/test/PositionSpec.js b/test/PositionSpec.js index a0b955cc11..6a83f0cd9e 100644 --- a/test/PositionSpec.js +++ b/test/PositionSpec.js @@ -9,10 +9,13 @@ import overlayPositionUtils from '../src/utils/overlayPositionUtils'; import {render} from './helpers'; describe('Position', function () { + // Swallow extra props. + const Span = () => ; + it('Should output a child', function () { let instance = ReactTestUtils.renderIntoDocument( - Text + Text ); assert.equal(ReactDOM.findDOMNode(instance).nodeName, 'SPAN'); @@ -22,8 +25,8 @@ describe('Position', function () { expect(() => { ReactTestUtils.renderIntoDocument( - Text - Another Text + Text + Another Text ); }).to.throw(Error, /onlyChild must be passed a children with exactly one child/); @@ -61,7 +64,7 @@ describe('Position', function () { target={() => this.refs[this.state.target]} fakeProp={this.state.fakeProp} > -
+
); @@ -114,7 +117,7 @@ describe('Position', function () { shouldUpdatePosition fakeProp={this.state.fakeProp} > -
+
); diff --git a/test/TransitionSpec.js b/test/TransitionSpec.js index 18ba7a65de..72bbc445a6 100644 --- a/test/TransitionSpec.js +++ b/test/TransitionSpec.js @@ -246,13 +246,16 @@ describe('Transition', function () { } render() { + const { ...props } = this.props; + delete props.initialIn; + return (
diff --git a/test/helpers.js b/test/helpers.js index 4ae81330bb..6322c5cb38 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -1,10 +1,8 @@ -import ReactDOM from 'react-dom'; import { cloneElement } from 'react'; +import ReactDOM from 'react-dom'; export function shouldWarn(about) { - console.warn.called.should.be.true; - console.warn.calledWithMatch(about).should.be.true; - console.warn.reset(); + console.error.expected.push(about); } /** diff --git a/test/index.js b/test/index.js index d7f92dcb2f..1e73b552dd 100644 --- a/test/index.js +++ b/test/index.js @@ -1,4 +1,5 @@ import 'es5-shim'; + import chai from 'chai'; import sinonChai from 'sinon-chai'; @@ -8,17 +9,36 @@ chai.use(sinonChai); global.expect = chai.expect; global.assert = chai.assert; -beforeEach(function() { - sinon.stub(console, 'warn'); -}); +beforeEach(() => { + sinon.stub(console, 'error', msg => { + let expected = false; -afterEach(function() { - if (typeof console.warn.restore === 'function') { - assert(!console.warn.called, () => { - return `${console.warn.getCall(0).args[0]} \nIn '${this.currentTest.fullTitle()}'`; + console.error.expected.forEach(about => { + if (msg.indexOf(about) !== -1) { + console.error.warned[about] = true; + expected = true; + } }); - console.warn.restore(); + + if (expected) { + return; + } + + console.error.threw = true; + throw new Error(msg); + }); + + console.error.expected = []; + console.error.warned = Object.create(null); + console.error.threw = false; +}); + +afterEach(() => { + if (!console.error.threw && console.error.expected.length) { + expect(console.error.warned).to.have.keys(console.error.expected); } + + console.error.restore(); }); describe('Process environment for tests', function () {