Skip to content

Commit

Permalink
Merge branch 'master' into feat/Profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 5, 2019
2 parents 5b4a309 + 970779f commit 5203b0a
Show file tree
Hide file tree
Showing 23 changed files with 650 additions and 107 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"babel-register": "^6.26.0",
"chai": "^4.2.0",
"coveralls": "^2.13.3",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down Expand Up @@ -97,7 +97,7 @@
"prop-types": "^15.7.2",
"rimraf": "^2.6.3",
"safe-publish-latest": "^1.1.2",
"semver": "^5.6.0",
"semver": "^6.0.0",
"webpack": "^1.15.0"
},
"dependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-13/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-14/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"object.assign": "^4.1.0",
"object.values": "^1.1.0",
"prop-types": "^15.7.2",
"react-is": "^16.8.4"
"react-is": "^16.8.6"
},
"peerDependencies": {
"enzyme": "^3.0.0",
Expand All @@ -52,7 +52,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-15.4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"object.assign": "^4.1.0",
"object.values": "^1.1.0",
"prop-types": "^15.7.2",
"react-is": "^16.8.4"
"react-is": "^16.8.6"
},
"peerDependencies": {
"enzyme": "^3.0.0",
Expand All @@ -53,7 +53,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-15/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"object.assign": "^4.1.0",
"object.values": "^1.1.0",
"prop-types": "^15.7.2",
"react-is": "^16.8.4"
"react-is": "^16.8.6"
},
"peerDependencies": {
"enzyme": "^3.0.0",
Expand All @@ -52,7 +52,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-16.1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"enzyme-adapter-utils": "^1.10.1",
"object.assign": "^4.1.0",
"prop-types": "^15.7.2",
"react-is": "^16.8.4",
"react-is": "^16.8.6",
"react-reconciler": "^0.7.0",
"react-test-renderer": "~16.0.0-0 || ~16.1"
},
Expand All @@ -52,7 +52,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-16.2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"object.assign": "^4.1.0",
"object.values": "^1.1.0",
"prop-types": "^15.7.2",
"react-is": "^16.8.4",
"react-is": "^16.8.6",
"react-reconciler": "^0.7.0",
"react-test-renderer": "~16.2.0"
},
Expand All @@ -53,7 +53,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-16.3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"object.assign": "^4.1.0",
"object.values": "^1.1.0",
"prop-types": "^15.7.2",
"react-is": "^16.8.4",
"react-is": "^16.8.6",
"react-reconciler": "^0.7.0",
"react-test-renderer": "~16.3.0-0"
},
Expand All @@ -53,7 +53,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
67 changes: 60 additions & 7 deletions packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ import ShallowRenderer from 'react-test-renderer/shallow';
import TestUtils from 'react-dom/test-utils';
import checkPropTypes from 'prop-types/checkPropTypes';
import {
isElement,
isPortal,
isValidElementType,
AsyncMode,
Fragment,
ContextConsumer,
ContextProvider,
StrictMode,
Element,
ForwardRef,
Fragment,
isContextConsumer,
isContextProvider,
isElement,
isForwardRef,
isPortal,
isValidElementType,
Portal,
StrictMode,
} from 'react-is';
import { EnzymeAdapter } from 'enzyme';
import { typeOfNode } from 'enzyme/build/Utils';
Expand Down Expand Up @@ -239,6 +243,18 @@ function nodeToHostNode(_node) {
return mapper(node);
}

function getProviderDefaultValue(Provider) {
// React stores references to the Provider's defaultValue differently across versions.
if ('_defaultValue' in Provider._context) {
return Provider._context._defaultValue;
}
throw new Error('Enzyme Internal Error: can’t figure out how to get Provider’s default value');
}

function makeFakeElement(type) {
return { $$typeof: Element, type };
}

const eventOptions = { animation: true };

class ReactSixteenThreeAdapter extends EnzymeAdapter {
Expand Down Expand Up @@ -355,11 +371,30 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
render(el, context) {
render(el, context, {
providerValues = new Map(),
} = {}) {
cachedNode = el;
/* eslint consistent-return: 0 */
if (typeof el.type === 'string') {
isDOM = true;
} else if (isContextProvider(el)) {
providerValues.set(el.type, el.props.value);
const MockProvider = Object.assign(
props => props.children,
el.type,
);
return withSetStateAllowed(() => renderer.render({ ...el, type: MockProvider }));
} else if (isContextConsumer(el)) {
const Provider = adapter.getProviderFromConsumer(el.type);
const value = providerValues.has(Provider)
? providerValues.get(Provider)
: getProviderDefaultValue(Provider);
const MockConsumer = Object.assign(
props => props.children(value),
el.type,
);
return withSetStateAllowed(() => renderer.render({ ...el, type: MockConsumer }));
} else {
isDOM = false;
const { type: Component } = el;
Expand Down Expand Up @@ -537,7 +572,17 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter {
}

isCustomComponent(type) {
return !!type && (typeof type === 'function' || type.$$typeof === ForwardRef);
const fakeElement = makeFakeElement(type);
return !!type && (
typeof type === 'function'
|| isForwardRef(fakeElement)
|| isContextProvider(fakeElement)
|| isContextConsumer(fakeElement)
);
}

isContextConsumer(type) {
return !!type && isContextConsumer(makeFakeElement(type));
}

isCustomComponentElement(inst) {
Expand All @@ -547,6 +592,14 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter {
return this.isCustomComponent(inst.type);
}

getProviderFromConsumer(Consumer) {
const { Provider } = Consumer || {};
if (Provider) {
return Provider;
}
throw new Error('Enzyme Internal Error: can’t figure out how to get Provider from Consumer');
}

createElement(...args) {
return React.createElement(...args);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-16/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"object.assign": "^4.1.0",
"object.values": "^1.1.0",
"prop-types": "^15.7.2",
"react-is": "^16.8.4",
"react-is": "^16.8.6",
"react-test-renderer": "^16.0.0-0",
"semver": "^5.6.0"
},
Expand All @@ -53,7 +53,7 @@
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"enzyme": "^3.0.0",
"eslint": "^5.15.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
Loading

0 comments on commit 5203b0a

Please sign in to comment.