Skip to content

Commit

Permalink
[enzyme-adapter-react-16] [new] add Profiler support for react v16.9+
Browse files Browse the repository at this point in the history
 - ConcurrentMode was removed, and createRoot added, in v16.9+ (facebook/react#15532)
  • Loading branch information
holsted authored and ljharb committed Sep 7, 2019
1 parent e78ab06 commit 370f614
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-16/src/detectFiberTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function detectFiberTags() {
const supportsContext = typeof React.createContext !== 'undefined';
const supportsForwardRef = typeof React.forwardRef !== 'undefined';
const supportsMemo = typeof React.memo !== 'undefined';
const supportsProfiler = typeof React.unstable_Profiler !== 'undefined';
const supportsProfiler = typeof React.unstable_Profiler !== 'undefined' || typeof React.Profiler !== 'undefined';
const supportsSuspense = typeof React.Suspense !== 'undefined';
const supportsLazy = typeof React.lazy !== 'undefined';

Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = function detectFiberTags() {
? getFiber(React.createElement(FwdRef)).tag
: -1,
Profiler: supportsProfiler
? getFiber(React.createElement(React.unstable_Profiler, { id: 'mock', onRender() {} })).tag
? getFiber(React.createElement((React.Profiler || React.unstable_Profiler), { id: 'mock', onRender() {} })).tag
: -1,
Suspense: supportsSuspense
? getFiber(React.createElement(React.Suspense, { fallback: false })).tag
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/test/Adapter-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ describe('Adapter', () => {
expect(getDisplayName(<Profiler />)).to.equal('Profiler');
});

itIf(is('>= 16.6'), 'supports ConcurrentMode', () => {
itIf((is('>= 16.6') && is('<16.9')), 'supports ConcurrentMode', () => {
expect(getDisplayName(<ConcurrentMode />)).to.equal('ConcurrentMode');
});

Expand Down
24 changes: 21 additions & 3 deletions packages/enzyme-test-suite/test/_helpers/react-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let Fragment;
let StrictMode;
let AsyncMode;
let ConcurrentMode;
let createRoot;
let Profiler;
let PureComponent;
let Suspense;
Expand Down Expand Up @@ -83,7 +84,9 @@ if (is('^16.3.0-0')) {
AsyncMode = null;
}

if (is('^16.4.0-0')) {
if (is('^16.9.0-0')) {
({ Profiler } = require('react'));
} else if (is('^16.4.0-0')) {
({
unstable_Profiler: Profiler,
} = require('react'));
Expand All @@ -93,18 +96,32 @@ if (is('^16.4.0-0')) {

if (is('^16.6.0-0')) {
({
unstable_ConcurrentMode: ConcurrentMode,
Suspense,
lazy,
memo,
} = require('react'));
} else {
ConcurrentMode = null;
Suspense = null;
lazy = null;
memo = null;
}

if (is('^16.6.0-0') && !is('^16.9.0-0')) {
({
unstable_ConcurrentMode: ConcurrentMode,
} = require('react'));
} else {
ConcurrentMode = null;
}

if (is('^16.9.0-0')) {
({
unstable_createRoot: createRoot,
} = require('react'));
} else {
createRoot = null;
}

if (is('^16.8.0-0')) {
({
useCallback,
Expand Down Expand Up @@ -145,6 +162,7 @@ export {
createPortal,
createContext,
createRef,
createRoot,
forwardRef,
Fragment,
StrictMode,
Expand Down

0 comments on commit 370f614

Please sign in to comment.