Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add enzyme-adapter-react-17 (no TODO tags) #2534

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

createthis
Copy link

@createthis createthis commented Aug 10, 2021

Same as #2430 with TODO_17 tags removed.

How working on this PR made me feel:
derpy_dog

@codecov
Copy link

codecov bot commented Aug 10, 2021

Codecov Report

Merging #2534 (46d0422) into master (8c55734) will decrease coverage by 0.48%.
The diff coverage is 92.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2534      +/-   ##
==========================================
- Coverage   96.31%   95.83%   -0.49%     
==========================================
  Files          49       53       +4     
  Lines        4207     4749     +542     
  Branches     1130     1304     +174     
==========================================
+ Hits         4052     4551     +499     
- Misses        155      198      +43     
Impacted Files Coverage Δ
packages/enzyme-adapter-utils/src/Utils.js 96.26% <ø> (ø)
...pter-react-17/src/findCurrentFiberUsingSlowPath.js 68.42% <68.42%> (ø)
...ges/enzyme-adapter-react-17/src/detectFiberTags.js 85.24% <85.24%> (ø)
...zyme-adapter-react-17/src/ReactSeventeenAdapter.js 96.11% <96.11%> (ø)
packages/enzyme-adapter-react-17/src/index.js 100.00% <100.00%> (ø)
...pter-react-helper/src/getAdapterForReactVersion.js 100.00% <100.00%> (ø)
packages/enzyme/src/ShallowWrapper.js 99.13% <100.00%> (+0.01%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c55734...46d0422. Read the comment docs.

expect(info).to.deep.equal(expectedInfo);
if (is('>= 17')) {
expect(info).to.have.property('componentStack');
expect(info.componentStack).to.match(/at Thrower (.+)\n/);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is necessary because the backtrace now includes local file paths in 17.x.

UNSAFE_componentWillReceiveProps() on setContext()
lifecycle methods disabled according to test.
instance.componentWillReceiveProps(props);
}
if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') { // eslint-disable-line new-cap
instance.UNSAFE_componentWillReceiveProps(props); // eslint-disable-line new-cap
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code corrects shallow()'s calling of componentWillReceiveProps() and UNSAFE_componentWillReceiveProps() under react 17.

@@ -1716,7 +1716,7 @@ describe('shallow', () => {

it('works without memoizing', () => {
const wrapper = shallow(<RendersApp />);
expect(wrapper.debug()).to.equal('<App />');
expect(wrapper.debug()).to.equal(is('>= 17') ? '<AppMemoized />' : '<App />');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be due to a change in how React.memo() operates in React 17. Prior to 17 it seemed to return a copy of the component. In 17 it seems to return a reference.

@@ -600,7 +600,11 @@ describe('Utils', () => {
Foo.displayName = 'CustomWrapper';

const MemoForwardFoo = React.memo(React.forwardRef(Foo));
expect(adapter.displayNameOfNode(<MemoForwardFoo />)).to.equal('Memo(ForwardRef(CustomWrapper))');
if (is('>= 17')) {
expect(adapter.displayNameOfNode(<MemoForwardFoo />)).to.equal('Memo([object Object])');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm writing this a day after I took the screenshot, so it is possible it is the wrong screenshot, but I think the object looks like this:
Screen Shot 2021-08-11 at 4 03 27 PM

return isMemo(type) ? type.type : type;
}

function transformSuspense(renderedEl, prerenderEl, { suspenseFallback }) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove this method and all associated code, it goes from 5 suspense related test failures to 16 suspense related test failures. This code is clearly doing something useful.

@@ -1179,9 +1183,9 @@ describeWithDOM('mount', () => {
const wrapper = mount(<SuspenseComponent />);
expect(wrapper.debug()).to.equal(`<SuspenseComponent>
<Suspense fallback={{...}}>
<div />
${is('>= 17') ? '<Suspense mode="visible" />' : `<div />
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regrettably, I don't know why <Suspense mode="visible" /> is appearing instead of the expected html. The <Suspense /> subsystem in the 17 adapter is a bit beyond the limits of my domain knowledge so I am a little lost. I did my best to restore these suspense tests as completely as I could given my limitations. The <Suspense /> subsystem is listed as experimental by React, so I'm not sure how important it is: https://reactjs.org/docs/concurrent-mode-suspense.html


In another terminal tab execute a specific test file for faster TDD test execution:
```bash
node_modules/.bin/mocha packages/enzyme-test-suite/build/ReactWrapper-spec.js
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorporated tips provided by https://github.com/ljharb back into documentation.

@createthis createthis marked this pull request as ready for review August 13, 2021 19:00
@leopucci

This comment has been minimized.

@luiscosio

This comment has been minimized.

@EricKwan2014

This comment has been minimized.

@ljharb

This comment has been minimized.

@shiraze
Copy link

shiraze commented Mar 31, 2022

Hi guys, is this the correct place to ask what support my team and I can give to get a React 17 adaptor over the line? We've considered React-Testing-Library but the overhead of converting tests is so much that it might make better sense for us to provide support here.

@ljharb
Copy link
Member

ljharb commented Mar 31, 2022

@shiraze yes, if you can provide people and time, i'd be happy to set up a call to get everyone on the same page so we can get things landed.

@shiraze
Copy link

shiraze commented Mar 31, 2022

@ljharb excellent. Let's set up a call

@ljharb
Copy link
Member

ljharb commented Mar 31, 2022

@shiraze please reach out on twitter DMs or at gmail

@mak12
Copy link

mak12 commented May 19, 2022

Any update on this?

@shiraze
Copy link

shiraze commented May 19, 2022

Unfortunately I wasn't able to provide people and time

@eps1lon eps1lon mentioned this pull request Aug 2, 2022
4 tasks
@ljharb ljharb force-pushed the master branch 3 times, most recently from 43eb75e to 39e6b1f Compare November 3, 2022 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants