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

add mutation observer polyfill for jest test env #20996

Merged
merged 8 commits into from
Jul 30, 2018

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Jul 19, 2018

EUI 3.1.0 updates the EuiPopover component to use MutationObservser. Any jest tests that uses this component and render with mount will fail because jsdom does not implement MutationObservser.

This PR sets up a MutationObserver polyfill for the jest runtime environment. A polyfill is not needed for the browser since MutationObservser is implemented in IE 11 and has had support in Firefox, Chrome, and Safari for a long time.

bluebird does not play nice with the MutationObserver polyfill.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

// https://github.com/aurelia/pal-nodejs/blob/master/src/polyfills/mutation-observer.ts

/*
The MIT License (MIT)
Copy link
Contributor

Choose a reason for hiding this comment

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

We are going to need a mutation observer polyfill for the browser too no? Is there a reason we need one for jest specifically? Why not use one from npm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A polyfill is not needed for the browser since MutationObservser is implemented in IE 11 and has had support in Firefox, Chrome, and Safari for a long time.

We need a polyfill for jest tests because jsdom does not implement MutationObservser and therefore any tests that render a component using MutationObservser will fail to render.

I was using the MutationObservser polyfill that EUI is using. I will see if an npm version exists that we can use.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

*/

// bluebird < 3.5.0 does not work with MutationObserver polyfill
// when MutationObserver exists, bluebird avoids using node's builtin async schedulers
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you link to docs or something for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no docs to link to. @chandlerprall found this while digging around in their code base

* under the License.
*/

// bluebird < 3.5.0 does not work with MutationObserver polyfill
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, the update that works alongside MutationObserver's polyfill happened in v3.3.5; I don't think that's vital information but wanted to call it out anyway.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese merged commit 588bf14 into elastic:master Jul 30, 2018
nreese added a commit to nreese/kibana that referenced this pull request Jul 30, 2018
* add mutation observer polyfill for jest test env

* use polyfill from npm

* set bluebird scheduler

* use correct version in comment about bluebird
nreese added a commit that referenced this pull request Jul 30, 2018
* add mutation observer polyfill for jest test env

* use polyfill from npm

* set bluebird scheduler

* use correct version in comment about bluebird
snide pushed a commit to snide/kibana that referenced this pull request Oct 4, 2018
* add mutation observer polyfill for jest test env

* use polyfill from npm

* set bluebird scheduler

* use correct version in comment about bluebird
snide added a commit that referenced this pull request Oct 5, 2018
…23801)

* eui 3.0.7

* add mutation observer polyfill for jest test env (#20996)

* add mutation observer polyfill for jest test env

* use polyfill from npm

* set bluebird scheduler

* use correct version in comment about bluebird

* update tests for mutation obs

* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants