[Enterprise Search] Mocks/tests tech debt - avoid hungry mocking#101107
[Enterprise Search] Mocks/tests tech debt - avoid hungry mocking#101107cee-chen merged 9 commits intoelastic:masterfrom
Conversation
…elpers/ They're not technically mocks since nothing is being mocked, so we should move them into a test_helpers folder for specificity & organization
This was part of the initial feedback, that it was unclear why importing something for Kea in __mocks__/index.ts was mocking react router along for the ride. Separating this out makes things clearer and imports more explicit + add some handy new mock useX jest.fn()s helpers, so we're not doing `useParams() as jest.Mock` errywhere
- for organization NOTE: It can't be a plain kea/ folder because then Jest automatically mocks the `kea` module itself kea 🤦
|
Also want to add no rush on this PR at all - it's meant to be a minor tech debt / dev QOL enhancement only, so if you disagree that it's actually a dev experience improvement or just want to address features or bugs first, feel free to let this sit & percolate a bit. (It'll also cause a merge conflict with Jason's currently open Kea test PR (#100134) because I pulled out LogicMounter into its own file, so apologies for that and I'm happy to wait to merge after that lands 🙏) |
JasonStoltz
left a comment
There was a problem hiding this comment.
LGTM once this goes green.
x-pack/plugins/enterprise_search/public/applications/__mocks__/react_router/index.ts
Outdated
Show resolved
Hide resolved
- Caused by switch from any to unknown (changed back to any + added a .test_helper suffix exclusion for any)
- I checked all application folders but this one, whoops
- null not being type-able as a boolean - forgot to remove various useParam imports after adding mockUseParams + misc unused kea import, probably added while debugging kea mocks
scottybollinger
left a comment
There was a problem hiding this comment.
This is great Constance. Really grateful for all of these helpers and for taking the time to make them better! 🎉
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
💔 Backport failed
To backport manually run: |
* master: (54 commits) Implement "select all" rules feature (elastic#100554) [ML] Remove script fields from the Anomaly detection alerting rule executor (elastic#101607) [Security solutions][Endpoint] Update event filtering texts (elastic#101563) [Enterprise Search] Mocks/tests tech debt - avoid hungry mocking (elastic#101107) [FTR] Updates esArchive paths [FTR] Updates esArchive paths [Security Solution][Detection Engine] Adds runtime field tests (elastic#101664) Added APM PHP agent to the list of agent names (elastic#101062) [CI] Restore old version_info behavior when .git directory is present (elastic#101642) [Fleet] Add fleet server telemetry (elastic#101400) [APM] Syncs agent config settings to APM Fleet policies (elastic#100744) [esArchiver] drop support for --dir, use repo-relative paths instead (elastic#101345) Revert "[xpack/test] restore incremental: false in ts project" [Security Solution] Remove Host Isolation feature flag (elastic#101655) [xpack/test] restore incremental: false in ts project [DOCS] Adds link to video landing page (elastic#101413) [ML] Move Index Data Visualizer into separate plugin (Part 1) (elastic#100922) Improve security plugin return types (elastic#101492) [ts] migrate `x-pack/test` to composite ts project (elastic#101441) [App Search] Updated Search UI to new URL (elastic#101320) ...
…1107) (#101788) * Move enzyme & misc test helpers out of __mocks__/ and into new test_helpers/ They're not technically mocks since nothing is being mocked, so we should move them into a test_helpers folder for specificity & organization * Move React Router mocks into its own separate folder/import This was part of the initial feedback, that it was unclear why importing something for Kea in __mocks__/index.ts was mocking react router along for the ride. Separating this out makes things clearer and imports more explicit + add some handy new mock useX jest.fn()s helpers, so we're not doing `useParams() as jest.Mock` errywhere * Move Kea & logic mocks/helpers into kea_logic subfolder - for organization NOTE: It can't be a plain kea/ folder because then Jest automatically mocks the `kea` module itself kea 🤦 * Fix type failures - Caused by switch from any to unknown (changed back to any + added a .test_helper suffix exclusion for any) * Fix Enterprise Search tests/imports - I checked all application folders but this one, whoops * PR feedback: comment copy * Update tests/files added since PR open with new import locations * Fix misc react router typing - null not being type-able as a boolean - forgot to remove various useParam imports after adding mockUseParams + misc unused kea import, probably added while debugging kea mocks # Conflicts: # x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_overview.test.tsx # x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_overview_logic.test.ts
Summary
Don't be scared by the 270 changed files! The changes to look at are the ones in
public/applications/__mocks__- everything else is only an import update to account for the new mocks architecture/folder structure.Here's a quick screenshot of the changes:
Changes:
test_helpers(eaca116)__mocks__because they weren't mocks. They were test helpers, something Kibana provides for in its dev directories checks.react_router(ebb1d7a)import { someKeaMock } from '../../__mocks__';. Why would a Kea mock cause RR to get mocked? An excellent question, and it was because we were mocking/exporting everything wholesale out of__mocks__/index.ts, which this PR now removes the ambiguity of by only grouping certain logical exports together (e.g., Kea).kea_logic(ed7743b)kea.mock.ts(which I renamed tohooks.mock.ts, since it's essentially in charge of just the useActions/useValues mocks).__mocks__/kea/led to Jest auto-mocking all tests importing Kea, which we don't want, so I had to slightly more verbosely name the folderkea_logic🤦♀️ Hope that's cool with y'all.Checklist
This is a tech debt / test only PR. All unit tests should pass, nothing else should change at all