-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[React@18] Upgrade @testing-library/react
#198918
Conversation
…sting-library # Conflicts: # packages/kbn-test/src/jest/resolver.js
@@ -58,6 +58,10 @@ module.exports = (request, options) => { | |||
}); | |||
} | |||
|
|||
if (request === 'react-dom/client') { | |||
return Path.resolve(__dirname, 'mocks/react_dom_client_mock.ts'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're just mocking this with an {}
, this API from React@18 won't be used because we're forcing legacyRoot:true
. Just need to it help to resolve the modules. This mock can be removed with an upgrade to React@18
|
||
return { | ||
...actual, | ||
render: (ui, options) => actual.render(ui, { ...options, legacyRoot: true }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forcing legacyRoot:true
by default makes testing library to use legacy API ReactDOM.render api which is how we make it work with React@17.
The option is documented here https://testing-library.com/docs/react-testing-library/api/#legacyroot .
There is no global configuration for this option, so we have to do this mocking workaround to adjust the default.
Event after upgrade of the react packages to React@18 it would make sense to keep this option as it until we start upgrading to the Concurrent Mode. We will likely come of a gradual transition plan in parallel with the runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah same thing here as above, I feel at minimum we need a comment to track this.
@@ -403,10 +403,10 @@ describe('CheckAll', () => { | |||
|
|||
// simulate the wall clock advancing | |||
for (let i = 0; i < totalIndexNames + 1; i++) { | |||
await waitFor(() => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seem to rely on some very specific internal timings that apparently have changed. I found that adding another waitFor fixes the tests. Feel free to take a look and contribute to make it more robust
x-pack/plugins/cases/public/components/add_comment/index.test.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach seems good to me, nice find. My only request would be to track the removal of the mock so that bit of work isn't forgotten about. Likely in the overall React@18 issue.
Pinging @elastic/appex-sharedux (Team:SharedUX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR only, looks fine, but 2 asks and I'll approve.
|
||
return { | ||
...actual, | ||
render: (ui, options) => actual.render(ui, { ...options, legacyRoot: true }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah same thing here as above, I feel at minimum we need a comment to track this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response-ops
changes OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kubernetes_security
and session_view
changes look good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elastic/security-defend-workflows changes (that one line) look good! thank you for the upgrade! 🙌
@kapral18, thank you for pointing that out. I think I figured this one out and should be good now. Please take another look |
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for threat-hunting-explore
@elasticmachine merge upstream |
⏳ Build in-progress
History
cc @Dosant |
Starting backport for target branches: 8.x |
(cherry picked from commit c8227a2)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…#199592) # Backport This will backport the following commits from `main` to `8.x`: - [[React@18] Upgrade `@testing-library/react` (#198918)](#198918) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Anton Dosov","email":"anton.dosov@elastic.co"},"sourceCommit":{"committedDate":"2024-11-11T08:31:15Z","message":"[React@18] Upgrade `@testing-library/react` (#198918)","sha":"c8227a26941a76044a89d27662dae029644b3ea7","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:SharedUX","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services","React@18"],"title":"[React@18] Upgrade `@testing-library/react`","number":198918,"url":"https://github.com/elastic/kibana/pull/198918","mergeCommit":{"message":"[React@18] Upgrade `@testing-library/react` (#198918)","sha":"c8227a26941a76044a89d27662dae029644b3ea7"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198918","number":198918,"mergeCommit":{"message":"[React@18] Upgrade `@testing-library/react` (#198918)","sha":"c8227a26941a76044a89d27662dae029644b3ea7"}}]}] BACKPORT--> Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
Summary
Part of https://github.com/elastic/kibana-team/issues/1016#issuecomment-2454845292
As part of upgrade to React@18 we need to upgrade testing-library. The offical upgrade path is that for React@17 testing-library < 13 should be used. And for React@18, testing-library > 13
This path turns out to be very problematic for us because it requires to upgrade React together with the testing-library, but we want the React runtime upgrade PR to be very small to be able to revert easily. We were ready to consider approaches were we'd bring in React@18 for unit tests, but keep runtime running React@17 https://github.com/elastic/kibana-team/issues/1016#issuecomment-2454845292
Fortunatly, we found a way to run the latest testing-library version with React@17 using legacyRoot option on
render
In this PR we're running the latest testing-library but defaulting to legacy rendering. This is done by mocking
@testing-library/react
as this is not global configuration options and we don't want to update every test file. Moreover, when we upgrade our packages to React@18 (phase 1 of the upgrade) thislegacyRoot:true
in unit tests would logically fit nicely with our plans, as Kibana will be running in legacy mode and the tests will also be rendering in legacy mode. As we will work on phase 2 and transitioning on the new concurrent mode, we will come up with parallel transition plan for the unit tests.A pleasant surprise is that amount of places that have broken with this change is very small - a handfull of types and a couple of unit tests.
After this PR is merged, we can continue with properly addressing the largest breaking that is caused by testing-library, which for us are changes in
renderHook
API #195087 . With the upgraded testing-library we can make PRs to swap oldrenderHook
with newrenderHook
independently from React version upgrade.I've created an issue to track cleaning this up post upgrade #199100