Skip to content

Conversation

@tkajtoch
Copy link
Member

Summary

This PR fixes all remaining unit tests, adds cross-version compatibility to useRenderToText() and fixes code style in a few files I missed that were merged before (sorry!!)

QA

  1. Checkout this branch
  2. Run rm -rf node_modules && yarn
  3. Run yarn lint
  4. Run yarn test-unit
  5. Run REACT_VERSION=17 yarn test-unit
  6. Confirm all of the above succeeded

@tkajtoch tkajtoch requested review from a team and cee-chen July 25, 2023 21:34
@tkajtoch tkajtoch self-assigned this Jul 25, 2023
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/

@tkajtoch tkajtoch force-pushed the feat/react-18-fix-compatibility-and-unit-tests branch from 3110b4c to cf26cf3 Compare July 26, 2023 09:17
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/

@cee-chen
Copy link
Contributor

@tkajtoch CI is still failing with a lint error it looks like:

02:28:31 /app/src/components/combo_box/combo_box.test.tsx
02:28:31   10:27  error  '/app/node_modules/@testing-library/react/dist/@testing-library/react.esm.js' imported multiple times  import/no-duplicates
02:28:31   13:21  error  '/app/node_modules/@testing-library/react/dist/@testing-library/react.esm.js' imported multiple times  import/no-duplicates

} else {
// eslint-disable-next-line @typescript-eslint/no-var-requires
renderHook = require('@testing-library/react-hooks').renderHook;
// eslint-disable-next-line @typescript-eslint/no-var-requires
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just // eslint-disable @typescript-eslint/no-var-requires the entire file instead of having 4 separate comments, please!

Also oof, it's unfortunate that this is necessary - I'm curious as to what on earth changed in React 18 that hooks render differently compared in 17 🤦

Copy link
Member Author

Choose a reason for hiding this comment

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

The change from import { render } from 'react-dom' to import { createRoot } from 'react-dom/client' caused all this :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks for clarifying!

Copy link
Member Author

Choose a reason for hiding this comment

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

I wondered why // eslint-disable @typescript-eslint/no-var-requires didn't work for me yesterday... you have to use /* */ for multi-line disables instead 🤦🏻‍♂️

It's fixed now!

cypressMount = require('@cypress/react').mount;
}

const mountCommand = (children: ReactNode): ReturnType<typeof mount> => {
Copy link
Member Author

Choose a reason for hiding this comment

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

@cee-chen I missed this when I was rebasing feature/react-18 a few days ago. The filename changed from mount.js to mount.tsx and I didn't catch your changes to reapply to the new file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, thanks for catching that!

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/

export const testOnReactVersion = (
versionOrVersions: ReactVersion | ReactVersion[]
): typeof test => {
return isReactVersion(versionOrVersions) ? test : test.skip;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a super elegant util 👏 I wish I knew why that specific EuiOverlayMask test was failing though. Is this an RTL-specific issue that they might fix on their end later, or do we need to rewrite our test?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's connected to how React 18 RTL and jest interact and I hope it can be fixed on their end, we'll see when upgrading to the latest jest. It might also be related to throwing an error during a react component update that throws out react internals.

I tried wrapping <EuiOverlayMask aria-hidden={true} /> in class component with componentDidCatch, rendering it differently, moving the throw statement outside useEffect and none seemed to help.

I created #6998 to track this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks so much for that info - that's super helpful!

Copy link
Contributor

Choose a reason for hiding this comment

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

These are seriously fantastic test conversions - thanks for preferring RTL queries over snapshots as always!

@tkajtoch tkajtoch force-pushed the feat/react-18-fix-compatibility-and-unit-tests branch from caba775 to 3974d37 Compare July 26, 2023 16:31
@tkajtoch tkajtoch force-pushed the feat/react-18-fix-compatibility-and-unit-tests branch from 3974d37 to 71dc3e2 Compare July 26, 2023 16:49
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

1 similar comment
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

1 similar comment
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/

@cee-chen
Copy link
Contributor

1 last test failure on CI!!

10:33:39 FAIL src/components/inline_edit/inline_edit_form.test.tsx
10:33:39   ● Test suite failed to run
10:33:39 
10:33:39     Call retries were exceeded
10:33:39 
10:33:39       at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)
10:33:39 
10:33:39 
10:33:39 Test Suites: 1 failed, 1 skipped, 392 passed, 393 of 394 total

act(() => getByTestSubject('dataGridKeyboardShortcutsButton').click());
rerender(<>{result.current.keyboardShortcuts}</>);
renderHookAct(() =>
getByTestSubject('dataGridKeyboardShortcutsButton').click()
Copy link
Contributor

Choose a reason for hiding this comment

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

So, unfortunately this test is no longer working/outputting the expected DOM element - the snapshot is missing the portal content.

Can you try using fireEvent.click here instead of .click()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catch, thank you!

});

afterAll(() => {
consoleErrorOverride.mockRestore();
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fantastic, thanks so much for making this change!

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/

@cee-chen
Copy link
Contributor

jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994_buildkite/

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

🎉 Hopefully Jenkins doesn't lose its mind this time and CI finally passes green!

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @tkajtoch

@tkajtoch
Copy link
Member Author

jenkins test this please

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6994/

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.

4 participants