Skip to content

[Enterprise Search] Small test helper for expected async errors#88422

Merged
cee-chen merged 2 commits intoelastic:masterfrom
cee-chen:expected-async-errors
Jan 15, 2021
Merged

[Enterprise Search] Small test helper for expected async errors#88422
cee-chen merged 2 commits intoelastic:masterfrom
cee-chen:expected-async-errors

Conversation

@cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Jan 15, 2021

Summary

Follow up to this conversation we had here: #88250 (comment)

Byron made an excellent point that the try/catch boilerplate around expected errors isn't super intuitive and is confusing at first glance (especially the comment, probably). I thought it would help us to DRY out a very small helper which serves a few purposes:

  • Handles silencing expected errors so we don't see them in test results
  • Prevents us from writing expect()s within catch, which as we've already discussed previously can lead to false positive test results
  • Optionally returns the thrown error to assert on (we're not doing so currently in any tests, but I think it'll potentially be helpful in the future!)

Let me know what y'all think! Just IMO, 50+ deleted lines is worth 💪

Checklist

@cee-chen cee-chen added release_note:skip Skip the PR/issue when compiling release notes v7.12.0 labels Jan 15, 2021
@cee-chen cee-chen requested review from a team, JasonStoltz and byronhulcher January 15, 2021 01:02
@cee-chen
Copy link
Contributor Author

Requesting a review from @scottybollinger since I'm touching WS tests

export { rerender } from './enzyme_rerender.mock';
// Note: shallow_useeffect must be imported directly as a file

export { expectedAsyncError } from './expected_async_error';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just btw, I know I'm getting a little loosey-goosey here with what should go into the __mocks__ folder, especially since this is definitely strictly a test helper and not a mock 😅 I'm definitely happy to revisit at some point if we just want a generic test helper folder, or if we want to split this up later at some point

Copy link
Member

Choose a reason for hiding this comment

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

I'm not concerned about it.

@cee-chen
Copy link
Contributor Author

FYI: I have 2 more Jest test related PRs coming after this. 1 that simplifies importing/mocking logic action/values from other logic files, and 1 final general cleanup PR. HOTYB!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

* you may not use this file except in compliance with the Elastic License.
*/

export const expectedAsyncError = async (promise: Promise<unknown>) => {
Copy link
Member

Choose a reason for hiding this comment

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

I like this a lot. I was imagining it'd have to be something more complex, but this is laser focused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome! We can definitely extend it in the future if we need to is my thought, but maybe we won't have to.

Copy link
Contributor

@scottybollinger scottybollinger left a comment

Choose a reason for hiding this comment

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

LGTM!

@cee-chen
Copy link
Contributor Author

Thanks y'all! Another PR coming here shortly 🎉

@cee-chen cee-chen merged commit d2de5d0 into elastic:master Jan 15, 2021
@cee-chen cee-chen deleted the expected-async-errors branch January 15, 2021 17:26
cee-chen pushed a commit that referenced this pull request Jan 15, 2021
…) (#88492)

* Add small helper to reduce boilerplate on async tests expected to throw

- Also hopefully a bit more descriptive on what's happening

* Update all test files using the previous try/catch do nothing blocks to use new helper
# Conflicts:
#	x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts
scottybollinger added a commit to scottybollinger/kibana that referenced this pull request Jan 15, 2021
scottybollinger added a commit that referenced this pull request Jan 18, 2021
* Initial copy/paste of component tree

Only does linting changes and lodash import

* Replace withRouter HOC with hooks

Use useLocation and no longer pass around history, using the KibanaLogic navigateToUrl method instead

* Migrate LicenseCallout component

* Update paths

Also change name of component to OauthApplication as the default import was named that before

* Remove conditional and passed in flash messages

This is no longer needed with the Kibana syntax. Flash messages are set globally and only render when present.

* Replace removed ConfirmModal

In Kibana, we use the Eui components directly

* Use internal tools for determining license

* Fix a bunch of type issues

* Remove telemetry settings section

We no longer control telemetry in Workplace Search. It is handled by Kibana itself

* Add SettingsSubNav component

* Add route and update nav

* Remove legacy AppView and sidenav

* Clear flash messages globally

* Remove global name change method call

The global org name is not used anywhere outside of this section so we no longer need to update the global organization object as it is re-fetched when this section is entered.

Previously, we displayed the org name in the sidebar but that has been removed in Kibana

* Refactor saveUpdatedConfig

We recently split out the logic from SourceLogic to the new AddSourceLogic and in settings, we were calling the saveSourceConfig method from the SourceLogic (now in AddSourceLogic) file and passing a callback that set the flash messages from that component’s state.

Now, we set the flash messages globally and no longer need to have a saveUpdatedConfig method in the logic file, but can call it directly in the component and the flash messages will be set globally.

* Update logic file to use global flash messages

* Update server routes

* Replace Rails http with kibana http

* Fix subnav

* Update routes to use consistent syntax

We use this method across both Enterprise Search products in Kibana

* Shorten nav item copy

This would be the only place in the sidebar with a nav item breaking to a second line.

* Fix some random typos

* Replace React Router Link with helper

* Add i18n

* Remove redundant clearing of flash messages

This happens automatically now in the global flash messages logic; route changes trigger clearing of messages

* Add unit tests for components

* Add tests for router

* Store oauthApplication in mock for reuse

* Add tests for SettingsLogic

* Fix typo

* Remove unncessary imports

Copied from this PR:
#88525

* Refactor to use new helpers when mocking

See #88494

* Update logic test to use error helper

See #88422

* Fix type issue

* Fix whitespace lint issue

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes v7.12.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants