-
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
[Enterprise Search] Add Kea test helper for directly accessing listeners #89061
Conversation
6d7a19a
to
0827738
Compare
0827738
to
fadebf9
Compare
fadebf9
to
f18af00
Compare
@scottybollinger Sorry for the accidental assignment/ping, I originally shoved some extra organizational mocking stuff in this PR that touched WS files, but then realized I didn't need to / could work around it. Just FYI you don't have to import LogicMounter directly from |
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 seems like a better approach than getting these listeners ad-hoc in each logic file. Is it worth creating an issue in the main kea repo about this? This doesn't seem intuitive, and testing side effects for listeners is a valid use case, I'm surprised this is "the way" to do it.
@elasticmachine merge upstream |
Testing listeners has been the source of more than a few lost development hours. This simplifies them greatly by simply allowing us to test them as plain old functions. This should let us crank out tests much quicker. It's a slightly less realistic test overall because we're not invoking the listener as it would actually be invoked using Kea. However, I think it's a reasonable tradeoff. Thanks for doing this Constance! |
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
@scottybollinger going to merge this PR in as-is, I'm thinking I'll use a separate helper for the things we chatted about today (mock breakpoint, invoke action for test coverage) |
…ers (#89061) (#89223) * Add getListeners to Kea test helpers * Update TelemetryLogic to use new getListeners helper Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
Summary
Jason is a Kea guru by now and has started using breakpoints in listeners to help debounce calls.
Unfortunately, this adds some amount of async shenanigans to Jest unit tests when calling the listener via
SomeLogic.actions.someListener
.Accessing the listener fn directly (rather than the wrapped action) makes async testing about easier or possible to catch errors/await breakpoints in the first place. Thus: this
getListeners
helper 👂The actual implementation isn't too difficult (I originally just console logged the logic file until I got what I wanted, which was the listener fns), but pulling it out to a helper makes it little more reusable & readable.
Example usage:
Checklist