eui
eui copied to clipboard
Remove `@testing-library/react-hooks` as a peer dependency
I tried to remove @testing-library/react-hooks from Kibana since we're no longer using it https://github.com/elastic/kibana/pull/222350. This was replaced by renderHook from @testing-library/react.
But Kibana PR failed since it turned out that eui is using it as a peer dependecy, so @testing-library/react-hooks isn't installed with eui package.
Example error:
<head></head>
FAIL src/platform/plugins/shared/share/public/components/export_popover/export_popover.test.tsx
--
| ● Test suite failed to run
|
| Cannot find module '@testing-library/react-hooks/dom' from 'node_modules/@elastic/eui/test-env/test/rtl/render_hook.js'
|
| Require stack:
| node_modules/@elastic/eui/test-env/test/rtl/render_hook.js
| node_modules/@elastic/eui/test-env/test/rtl/index.js
| src/platform/plugins/shared/share/public/components/export_popover/export_popover.test.tsx
|
| 14 \| import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
| 15 \| import { i18nServiceMock } from '@kbn/core-i18n-browser-mocks';
| > 16 \| import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
| \| ^
| 17 \| import { toastsServiceMock } from '@kbn/core-notifications-browser-mocks/src/toasts_service.mock';
| 18 \| import { ExportMenu } from './export_popover';
| 19 \| import type { IShareContext } from '../context';
|
| at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
| at Object.<anonymous> (node_modules/@elastic/eui/test-env/test/rtl/render_hook.js:23:37)
| at Object.<anonymous> (node_modules/@elastic/eui/test-env/test/rtl/index.js:85:20)
| at Object.require (src/platform/plugins/shared/share/public/components/export_popover/export_popover.test.tsx:16:1)
I suggest EUI gets rid of this dependency in favor of renderHook from @testing-library/react as a peer dependency
Looking at the code,
https://github.com/elastic/eui/blob/0596135217f222aa3b4a677deee537fb57db731b/packages/eui/src/test/rtl/render_hook.ts#L18-L24
It looks like Kibana is falling back to a non-React 18 version because we haven't defined the EUI specific process variable for kibana test env. Maybe EUI can figure it out from the React package version?
Hi @Dosant let me look into this and get back to you.
We actually only use @testing-library/react-hooks as a devDependency, which makes this whole thing a bit confusing. Long story short, since this hook contains internal logic, it should likely be treated as internal-only. We don't export it directly, and all usages in Kibana import it from the "hidden" @elastic/eui/lib/test/rtl/render_hook file directly.
I believe this should be fixed by our test utils library that I worked on earlier this year. Let me circle back to this and see if we could quickly release it and replace Kibana usages to fix the issue you're seeing!