Skip to content
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

[Lens] Prepare Lens for jest-environment-jsdom migration #95327

Merged
merged 4 commits into from
Mar 26, 2021

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Mar 24, 2021

Summary

Fixes #95202

The message reported on the issue is really rewriting the original messages, which are referring to document.activeElement.

To reproduce the issue:

  • Enable the jest-environment-jsdom environment in the packages/kbn-test/jest-preset.js

To see the original issue bubble up add skip to the following tests but one (others will interfere):
https://github.com/elastic/kibana/blob/master/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx#L616

https://github.com/elastic/kibana/blob/master/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx#L107

https://github.com/elastic/kibana/blob/master/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx#L122

https://github.com/elastic/kibana/blob/master/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx#L143

https://github.com/elastic/kibana/blob/master/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx#L164

And something like this will show up:

 FAIL  x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx (7.915 s)
  ● ConfigPanel › focus behavior when adding or removing layers › should focus the added layer

    TypeError: Cannot read property 'getAttribute' of undefined

      175 |       });
      176 |       const focusedEl = document.activeElement;
    > 177 |       expect(focusedEl?.children[0].getAttribute('data-test-subj')).toEqual('lns-layerPanel-1');
          |                                     ^
      178 |     });
      179 |   });
      180 | });

      at Object.<anonymous> (x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx:177:37)

These specific tests were using the document.activeElement which in jsdom has a specific behaviour, as reported also on this Enzyme issue.

This PR implements the solution proposed here. Using directly document.body as suggested on the jsdom issue prints some very verbose performance warnings, so the container solution is the safest option.

Checklist

@dej611 dej611 added Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 Feature:Lens v7.13.0 labels Mar 24, 2021
@dej611 dej611 requested review from spalger, mbondyra and a team March 24, 2021 15:54
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@dej611 dej611 added release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed labels Mar 24, 2021
@dej611
Copy link
Contributor Author

dej611 commented Mar 24, 2021

Not sure why the type checker told me to remove the // @ts-expect-error before and now it wants them back 😓

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Code LGTM except for one typing nit

const component = mountWithIntl(<LayerPanels {...defaultProps} />);
const component = mountWithIntl(
<LayerPanels {...defaultProps} />,
// @ts-expect-error
Copy link
Contributor

Choose a reason for hiding this comment

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

Why expecting an error here? It seems like we can just extend the options type in packages/kbn-test/src/jest/utils/enzyme_helpers.tsx to take attachTo as well.

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

LGTM! If we can get rid of //@ts-expect-error with Joe's suggestion, let's do it, but otherwise approved!

@dej611 dej611 requested a review from a team as a code owner March 26, 2021 11:16
@dej611
Copy link
Contributor Author

dej611 commented Mar 26, 2021

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Mar 26, 2021

The changes in the helper triggered another review from elastic/kibana-operations. Sorry @spalger 😅 , but I hope that may be helpful for other teams as well.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@dej611 dej611 merged commit 3f58b18 into elastic:master Mar 26, 2021
@dej611 dej611 deleted the fix/95202 branch March 26, 2021 14:59
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Mar 26, 2021
* 🐛 Fix activeElement issue with Jest

* 🏷️ Fix type issue

* 👌 Removed expect-errors directives

Co-authored-by: Kibana Machine <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

7.x / #95530

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Mar 26, 2021
…5530)

* 🐛 Fix activeElement issue with Jest

* 🏷️ Fix type issue

* 👌 Removed expect-errors directives

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Marco Liberati <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[jest/lens] Switch to jest-environment-jsdom
7 participants