-
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] fix outstanding easy unit tests #206917
[React@18] fix outstanding easy unit tests #206917
Conversation
* Without those styles in DOM the custom snapshot serializer is not able to replace the emotion class names. | ||
* This workaround ensures a fake emotion style tag is present in the DOM before rendering the component with enzyme making the snapshot serializer work. | ||
*/ | ||
function mockEnsureEmotionStyleTag() { |
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.
I described the problem in the comment, but here is the thread with investigation for even more context https://elastic.slack.com/archives/C7QC1JV6F/p1736790569444059
The problem is that snapshot serialization didn't work with React@18 and import {render} from 'enzyme'
.
- class="euiText emotion-euiText-m"
+ class="euiText css-1py2xv4-euiText-m"
Longer term we should get rid of enzyme. I plan to start this conversation post react@18 work
@@ -80,6 +80,8 @@ console.error = (...args) => { | |||
* Tracking issue to clean this up https://github.com/elastic/kibana/issues/199100 | |||
*/ | |||
if (REACT_VERSION.startsWith('18.')) { | |||
console.warn('Running with React@18 and muting the legacy ReactDOM.render warning'); | |||
if (!process.env.CI) { |
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.
just wanted to reduce noise on ci
const componentErrors = consoleErrorSpy.mock.calls.filter( | ||
(c) => | ||
!c[0]?.startsWith?.( | ||
'Warning: ReactDOM.render' |
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.
Fixing [job] [logs] Jest Tests #3 / Filter Group Component Filter Changed Banner should ignore url params if there is an error in using them
The problem is that when running React@18 in legacy mode there is an additional log message that warns about running in legacy mode. Since this is the only place that got broken because of it, I haven't come up with anything better then just adjusting in place :)
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 is so weird. Ideally we should not check the console log but this is a conversation for another day 🙂.
...gins/shared/lens/public/datasources/form_based/operations/definitions/ranges/ranges.test.tsx
Show resolved
Hide resolved
@@ -381,7 +381,7 @@ describe('action_type_form', () => { | |||
jest.useFakeTimers({ legacyFakeTimers: true }); | |||
wrapper.find('[data-test-subj="action-group-error-icon"]').first().simulate('mouseOver'); | |||
// Run the timers so the EuiTooltip will be visible | |||
jest.runAllTimers(); | |||
jest.runOnlyPendingTimers(); |
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.
expect(screen.getByTestId('infraUnLinkDashboardMenu')).toBeDisabled(); | ||
expect(screen.getByTestId('infraUnLinkDashboardMenu')).toHaveTextContent('Unlink dashboard'); | ||
|
||
describe('UnlinkDashboard', () => { |
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.
@eokoneyo fixed [job] [logs] Jest Tests #2 / Custom Dashboards Actions should render the unlink dashboard action when the user can unlink a dashboard
[job] [logs] Jest Tests #2 / Custom Dashboards Actions should render the unlink dashboard action when the user cannot unlink a dashboard
Added this in to fix the issue here, the mocked hook here requires another hook that would have required a mock, hence the need to mock this.
@@ -110,14 +110,14 @@ describe('<FilterByAssigneesPopover />', () => { | |||
const onUsersChangeMock = jest.fn(); | |||
const { getByTestId, getByText } = renderFilterByAssigneesPopover([], onUsersChangeMock); | |||
|
|||
getByTestId(FILTER_BY_ASSIGNEES_BUTTON).click(); | |||
fireEvent.click(getByTestId(FILTER_BY_ASSIGNEES_BUTTON)); |
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.
getByTestId(ASSIGNEES_ADD_BUTTON_TEST_ID).click(); | ||
getByText('User 1').click(); | ||
getByText('User 3').click(); | ||
fireEvent.click(getByTestId(ASSIGNEES_ADD_BUTTON_TEST_ID)); |
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.
@@ -21,7 +21,7 @@ describe('useOnExpandableFlyoutClose', () => { | |||
|
|||
window.removeEventListener = jest.fn().mockImplementationOnce((event, callback) => {}); | |||
|
|||
renderHook(() => useOnExpandableFlyoutClose({ callback: callbackFct })); | |||
const { unmount } = renderHook(() => useOnExpandableFlyoutClose({ callback: callbackFct })); |
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.
fix [job] [logs] Jest Tests #9 / useOnExpandableFlyoutClose should run the callback function and remove the event listener from the window
I just assume this test wasn't testing what was intended. It might be that removeEventListener was called on the initial render during effect re-rerun and that is what the assertion was cathing.
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.
kbn-test
changes lgtm
const componentErrors = consoleErrorSpy.mock.calls.filter( | ||
(c) => | ||
!c[0]?.startsWith?.( | ||
'Warning: ReactDOM.render' |
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 is so weird. Ideally we should not check the console log but this is a conversation for another day 🙂.
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
@elasticmachine merge upstream |
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/12828554923 |
💚 Build Succeeded
Metrics [docs]
History
|
## Summary Extracted remaining easy backward-compatible unit test fixes that fail with React@18 from elastic#206411 The idea is that the tests should pass for both React@17 and React@18 (cherry picked from commit 3ca02b3)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
# Backport This will backport the following commits from `main` to `8.x`: - [[React@18] fix outstanding easy unit tests (#206917)](#206917) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Anton Dosov","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-17T11:55:08Z","message":"[React@18] fix outstanding easy unit tests (#206917)\n\n## Summary\r\n\r\nExtracted remaining easy backward-compatible unit test fixes that fail\r\nwith React@18 from https://github.com/elastic/kibana/pull/206411\r\n\r\nThe idea is that the tests should pass for both React@17 and React@18","sha":"3ca02b324051adfa54965cfc3985abdc2a93b8a3","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:SharedUX","backport:prev-minor","React@18"],"title":"[React@18] fix outstanding easy unit tests","number":206917,"url":"https://github.com/elastic/kibana/pull/206917","mergeCommit":{"message":"[React@18] fix outstanding easy unit tests (#206917)\n\n## Summary\r\n\r\nExtracted remaining easy backward-compatible unit test fixes that fail\r\nwith React@18 from https://github.com/elastic/kibana/pull/206411\r\n\r\nThe idea is that the tests should pass for both React@17 and React@18","sha":"3ca02b324051adfa54965cfc3985abdc2a93b8a3"}},"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/206917","number":206917,"mergeCommit":{"message":"[React@18] fix outstanding easy unit tests (#206917)\n\n## Summary\r\n\r\nExtracted remaining easy backward-compatible unit test fixes that fail\r\nwith React@18 from https://github.com/elastic/kibana/pull/206411\r\n\r\nThe idea is that the tests should pass for both React@17 and React@18","sha":"3ca02b324051adfa54965cfc3985abdc2a93b8a3"}}]}] BACKPORT--> Co-authored-by: Anton Dosov <[email protected]>
## Summary Extracted remaining easy backward-compatible unit test fixes that fail with React@18 from elastic#206411 The idea is that the tests should pass for both React@17 and React@18
Summary
Extracted remaining easy backward-compatible unit test fixes that fail with React@18 from #206411
The idea is that the tests should pass for both React@17 and React@18 (legacy mode):
To run with react@18:
REACT_18=true yarn test:jest src/platform/plugins/private/kibana_overview/public/components/overview/overview.test.tsx
Also to run the app with React@18 please use this pr #196673 or from main: