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 #2564

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

Conversation

eps1lon
Copy link
Contributor

@eps1lon eps1lon commented Aug 2, 2022

Stacked on #2534 (Diff against #2534)

Compared to #2534:

  • less React 17 branching in tests (goal is 0 branching but branching for error stacks is probably fine)
  • some legacy code removed

TODO:
Open to discussing the remaining items @ljharb

  • callstack/componentstack
    Would need to discuss if we want to normalize them across React versions. For the initial release I would lean towards being ok with different stacks between 16 and 17 since that's also what developers experience.
  • hide internal Suspense fibers
  • Green CI
  • code coverage hygiene

Closes #2429
Closes #2534
Closes #2430

@eps1lon eps1lon force-pushed the feat/support-react17-sebbie branch from a7a7d75 to 165d692 Compare August 2, 2022 20:48
@codecov
Copy link

codecov bot commented Aug 2, 2022

Codecov Report

Base: 96.31% // Head: 95.99% // Decreases project coverage by -0.32% ⚠️

Coverage data is based on head (8649c0c) compared to base (538b0d8).
Patch coverage: 93.32% of modified lines in pull request are covered.

❗ Current head 8649c0c differs from pull request most recent head 8712dca. Consider uploading reports for the commit 8712dca to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2564      +/-   ##
==========================================
- Coverage   96.31%   95.99%   -0.33%     
==========================================
  Files          49       53       +4     
  Lines        4207     4716     +509     
  Branches     1130     1279     +149     
==========================================
+ Hits         4052     4527     +475     
- Misses        155      189      +34     
Impacted Files Coverage Δ
packages/enzyme-adapter-utils/src/Utils.js 96.26% <ø> (ø)
...pter-react-17/src/findCurrentFiberUsingSlowPath.js 68.42% <68.42%> (ø)
...zyme-adapter-react-17/src/ReactSeventeenAdapter.js 96.07% <96.07%> (ø)
...ges/enzyme-adapter-react-17/src/detectFiberTags.js 100.00% <100.00%> (ø)
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%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@eps1lon eps1lon force-pushed the feat/support-react17-sebbie branch from 165d692 to cc64090 Compare August 3, 2022 16:17
@eps1lon eps1lon marked this pull request as ready for review August 3, 2022 19:59
@ljharb
Copy link
Member

ljharb commented Aug 3, 2022

@eps1lon thanks! (but i wish you'd posted a branch link instead of opening a new PR - i now have three PRs to juggle (this, #2534, and #2430), which makes landing this update even harder)

@ljharb
Copy link
Member

ljharb commented Aug 3, 2022

Re your discussion point, as long as component stacks are correct within a React major/minor, there's no reason they need to stay the same as those change.

@eps1lon
Copy link
Contributor Author

eps1lon commented Aug 4, 2022

@eps1lon thanks! (but i wish you'd posted a branch link instead of opening a new PR - i now have three PRs to juggle (this, #2534, and #2430), which makes landing this update even harder)

What do you need to juggle and how would a branch help? The existing 2 are replaced by this one. If the forked component stack tests are fine, then this PR is ready to land

@ljharb
Copy link
Member

ljharb commented Aug 4, 2022

Every pull request has a permanent, eternal, undeleteable ref created on Github (that's not fetched by git by default, but can be opted into), so all three PRs must point to the same commit before landing any of them, or else any outliers will remain as orphaned refs for eternity.

@eps1lon
Copy link
Contributor Author

eps1lon commented Aug 4, 2022

Why are the other two PRs relevant here? They've been abandoned. The PR description clearly states that thus PR replaces them. How would I get CI to work without a PR?

Is there any change substance to discuss or do we want to spend more time on unrelated details? If I understood you correctly you have very limited time. But even if someone gives you a green PR that's not ok because?

@ljharb
Copy link
Member

ljharb commented Aug 4, 2022

@eps1lon the PR refs are part of the github repo, and no PRs are truly abandoned when a maintainer can update them directly. Either way, repo management concerns are never irrelevant/unrelated. On all my projects, I strenuously avoid having any abandoned PRs, and I repurpose every PR to ensure that all PR refs point to something useful.

This PR isn't quite green - coverage is failing - but it's great that tests are passing. When I have time to review it, I will certainly do so, and I appreciate the contribution.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Are createClass components no longer supported in React 17?

.gitignore Outdated
Comment on lines 52 to 54
# vim
**/*.swp
*.swp
Copy link
Member

Choose a reason for hiding this comment

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

gitignore stuff for a specific editor belongs in your global gitignore, instead of in every repo you touch; please revert this.

CONTRIBUTING.md Outdated

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
Member

Choose a reason for hiding this comment

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

Suggested change
node_modules/.bin/mocha packages/enzyme-test-suite/build/ReactWrapper-spec.js
npx mocha packages/enzyme-test-suite/build/ReactWrapper-spec.js

hardcoding node_modules should always be avoided.

&& instance
&& context
) {
if (lifecycles.componentWillReceivePropsOnShallowRerender) {
Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate on this lifecycle option?

Copy link
Contributor 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.

-- https://github.com/enzymejs/enzyme/pull/2534/files#r687066582

Comment on lines 871 to 880
// React stores references to the Provider on a Consumer differently across versions.
if (Consumer) {
let Provider;
if (Consumer._context) {
({ Provider } = Consumer._context);
}
if (Provider) {
return Provider;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

In React 17+, when is Consumer._context not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never. But there's a test specifically for passing something other than createContext so these guards are required. I'll remove the outdated comment.

@eps1lon
Copy link
Contributor Author

eps1lon commented Aug 9, 2022

Are createClass components no longer supported in React 17?

I'm not aware of any changes to createClass. How would I tell the tests to test for createClass support? I was under the impression that would be automatic just like with the other adapter tests

@ljharb
Copy link
Member

ljharb commented Aug 9, 2022

I think I diffed the 16 to 17 adapter files, and saw some code related to createClass removed.

In theory yes, the tests should be automatic, so if they're passing then maybe it's fine.

}

function isStateful(Component) {
return Component.prototype && Component.prototype.isReactComponent;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ljharb You're probably referring to this change compared to 16 regarding create-react-class changes?

Older versions of create-react-class might not pass this duck-typing check but then they would also not pass the same check in React 17 itself:

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for confirming :-)

@SwatiJadhav46
Copy link

@eps1lon Thanks for integrating this adapter. We are eagerly waiting for this to release, as it's a blocker for us in our project.

@eps1lon
Copy link
Contributor Author

eps1lon commented Aug 17, 2022

This PR isn't quite green - coverage is failing - but it's great that tests are passing.

@ljharb Is this something you want me to address? As far as I can tell this adapter has not less coverage than the 16 adapter. But since 16 adapter has less coverage than the average it's somewhat expected that coverage decreases. It looks to me that coverage target isn't really a target and more a check for changes (96.31% looks completely arbitrary to me).

@ljharb
Copy link
Member

ljharb commented Aug 17, 2022

@eps1lon nah definitely not a requirement - just something that'd be nice to improve, if possible, until i have the time to get to the PR. Coverage targets are just minimums; the ideal is always 100% :-)

@Prior99
Copy link

Prior99 commented Oct 27, 2022

@ljharb We're in dire need to have support for react 17 and 18 in enzyme. Is there anything we could help with to speed things up?

@ljharb ljharb force-pushed the master branch 3 times, most recently from 43eb75e to 39e6b1f Compare November 3, 2022 21:47
@mfv-brian

This comment was marked as spam.

@somenickname

This comment was marked as abuse.

@aks-
Copy link

aks- commented Feb 27, 2024

Hi! I worked on trying to get adapter 17 to completion and out. Can you please take a look @ljharb? Here is the link

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.

Support for React 17
9 participants