-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #876 from kentcdodds/pr/support-15.5
[Compat] support [email protected]
- Loading branch information
Showing
14 changed files
with
197 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,18 @@ | |
"test:watch": "mocha --recursive --watch test", | ||
"test:karma": "karma start", | ||
"test:env": "sh ./example-test.sh", | ||
"test:all": "npm run react:13 && npm run test:only && npm run react:14 && npm run test:only && npm run react:15 && npm run test:only", | ||
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils", | ||
"test:all": "npm run react:13 && npm run test:only && npm run react:14 && npm run test:only && npm run react:15.4 && npm run test:only && npm run react:15 && npm run test:only", | ||
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils node_modules/react-test-renderer", | ||
"react:13": "rimraf node_modules/.bin/npm && npm run react:clean && npm i [email protected] && npm install", | ||
"react:14": "rimraf node_modules/.bin/npm && npm run react:clean && npm i [email protected] [email protected] [email protected] && npm install", | ||
"react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15 && npm install", | ||
"react:15.4": "rimraf node_modules/.bin/npm && npm run react:clean && npm i [email protected] [email protected] [email protected] && npm install", | ||
"react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 create-react-class@15 react-test-renderer@^15.5.4 && npm install", | ||
"docs:clean": "rimraf _book", | ||
"docs:prepare": "gitbook install", | ||
"docs:build": "npm run docs:prepare && gitbook build", | ||
"docs:watch": "npm run docs:prepare && gitbook serve", | ||
"docs:publish": "npm run docs:clean && npm run docs:build && cd _book && git init && git commit --allow-empty -m 'update book' && git fetch [email protected]:airbnb/enzyme.git gh-pages && git checkout -b gh-pages && git add . && git commit -am 'update book' && git push [email protected]:airbnb/enzyme.git gh-pages --force", | ||
"travis": "babel-node ./node_modules/.bin/istanbul cover --report html _mocha -- test --recursive" | ||
"travis": "babel-node \"$(which istanbul)\" cover --report html _mocha -- test --recursive" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -60,6 +61,7 @@ | |
"object.assign": "^4.0.4", | ||
"object.entries": "^1.0.3", | ||
"object.values": "^1.0.3", | ||
"prop-types": "^15.5.4", | ||
"uuid": "^2.0.3" | ||
}, | ||
"devDependencies": { | ||
|
@@ -71,6 +73,7 @@ | |
"babel-register": "^6.24.1", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.13.0", | ||
"create-react-class": "^15.5.2", | ||
"enzyme-example-jest": "^0.1.0", | ||
"enzyme-example-karma": "^0.1.1", | ||
"enzyme-example-karma-webpack": "^0.1.4", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
*/ | ||
|
||
import objectAssign from 'object.assign'; | ||
import { REACT013 } from './version'; | ||
import { REACT013, REACT155 } from './version'; | ||
|
||
let TestUtils; | ||
let createShallowRenderer; | ||
|
@@ -18,6 +18,7 @@ let childrenToArray; | |
let renderWithOptions; | ||
let unmountComponentAtNode; | ||
let batchedUpdates; | ||
let shallowRendererFactory; | ||
|
||
const React = require('react'); | ||
|
||
|
@@ -95,12 +96,44 @@ if (REACT013) { | |
// to list this as a dependency in package.json and have 0.13 work properly. | ||
// As a result, right now this is basically an implicit dependency. | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
TestUtils = require('react-addons-test-utils'); | ||
if (REACT155) { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
TestUtils = require('react-dom/test-utils'); | ||
} else { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
TestUtils = require('react-addons-test-utils'); | ||
} | ||
} catch (e) { | ||
if (REACT155) { | ||
console.error( // eslint-disable-line no-console | ||
'[email protected]+ is an implicit dependency when using [email protected]+ with enzyme. ' + | ||
'Please add the appropriate version to your devDependencies. ' + | ||
'See https://github.com/airbnb/enzyme#installation', | ||
); | ||
} else { | ||
console.error( // eslint-disable-line no-console | ||
'react-addons-test-utils is an implicit dependency in order to support [email protected]. ' + | ||
'Please add the appropriate version to your devDependencies. ' + | ||
'See https://github.com/airbnb/enzyme#installation', | ||
); | ||
} | ||
throw e; | ||
} | ||
|
||
// Shallow renderer is accessible via the react-test-renderer package for React 15.5+. | ||
// This is a separate package though and may not be installed. | ||
try { | ||
if (REACT155) { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
shallowRendererFactory = require('react-test-renderer/shallow').createRenderer; | ||
} else { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
shallowRendererFactory = TestUtils.createRenderer; | ||
} | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
'react-addons-test-utils is an implicit dependency in order to support react@0.13-14. ' + | ||
'react-test-renderer is an implicit dependency in order to support react@15.5+. ' + | ||
'Please add the appropriate version to your devDependencies. ' + | ||
'See https://github.com/airbnb/enzyme#installation', | ||
); | ||
|
@@ -115,7 +148,7 @@ if (REACT013) { | |
// is essentially a replacement for `TestUtils.createRenderer` that doesn't use | ||
// shallow rendering when it's just a DOM element. | ||
createShallowRenderer = function createRendererCompatible() { | ||
const renderer = TestUtils.createRenderer(); | ||
const renderer = shallowRendererFactory(); | ||
const originalRender = renderer.render; | ||
const originalRenderOutput = renderer.getRenderOutput; | ||
let isDOM = false; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import React from 'react'; | ||
|
||
export const VERSION = React.version; | ||
|
||
const [major, minor] = VERSION.split('.'); | ||
|
||
export const REACT013 = VERSION.slice(0, 4) === '0.13'; | ||
export const REACT014 = VERSION.slice(0, 4) === '0.14'; | ||
export const REACT15 = VERSION.slice(0, 3) === '15.'; | ||
export const REACT15 = major === '15'; | ||
export const REACT155 = REACT15 && minor >= 5; |
Oops, something went wrong.