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

Disconnect MutationObserver synchronously in wait-for #801

Conversation

romain-trotard
Copy link
Contributor

@romain-trotard romain-trotard commented Nov 1, 2020

Here is a little PR after opening this issue #800
(my investigation is on it)

What:

My test are slow because of MutationObersion disconnections made at the end of my tests.

Why:

Currently observer.disconnect()is called in setImmediate, I guess the main thread is not available until the end of the test, so the check callback is called too much times.
This was done in this PR #102

How:

All my explanations are visible here: #800 (comment)

After making many test, I didn't see any problem to call both:

setImmediate(() => observer.disconnect());
observer.disconnect();

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests N/A
  • Typescript definitions updated N/A
  • [] Ready to be merged: I made a change on the husky config to be able to commit. Do not merge that like that!!

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 1, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a8dffff:

Sandbox Source
react-testing-library-examples Configuration

.huskyrc.js Outdated
@@ -1 +0,0 @@
module.exports = require('kcd-scripts/husky')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kentcdodds I removed this to be able to commit. I had an infinite loader that you can see in this little video. (I am using ubuntu 18)
infiniteLoading
Did you ever heard of any problem of this kind ?

Copy link
Member

Choose a reason for hiding this comment

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

git commit --no-verify avoids any pre-commit hooks. Any change to the pre-commit hook should be dealt with in a separate issue/pr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh thanks for the command, I totally forgot it exists ^^
I push directly the revert :)
(by the way I didn't expect to merge this change on master, it was only to be able to commit hoping someone will help me like you did ;) )
Otherwise do you have any idea why could the test run infinitely ? (in the hook)

Copy link
Member

Choose a reason for hiding this comment

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

No idea. I have husky disabled globally since it doesn't work well with my workflow (commit often, commit failing tests etc).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahaha no problem :)

@romain-trotard
Copy link
Contributor Author

The CI failed because of the new node v15, it is waiting for a response after the npx codecov@3 command:
image

src/wait-for.js Outdated
Comment on lines 99 to 100
// Call also the disconnect method on setImmediate for projects not using the MutationObersver implementation of jsdom.
// But using for example `@sheerun/mutationobserver-shim` which provokes infinite loop when being called immediately on `onDone` function
Copy link
Member

Choose a reason for hiding this comment

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

This looks fine to me. I'm only concerned about the implications of calling disconnect twice. I guess it's fine, but I'm not sure it's worthwhile having code that is only around to support a shim that nobody should be using (because they should be using a modern version of jsdom or a real browser environment). Anyone want to argue against just removing the next line?

Copy link
Member

@marcosvega91 marcosvega91 Nov 2, 2020

Choose a reason for hiding this comment

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

I have commented and on the issue and proposing two solutions:

Copy link
Contributor Author

@romain-trotard romain-trotard Nov 2, 2020

Choose a reason for hiding this comment

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

If nobody should use shim, it's good for me to remove it.
Thank you Kent and Marco, I'm gonna remove it asap

Does someone know what I should do for the breaking CI ? (if there is something I can do)

@kentcdodds
Copy link
Member

I'm fixing the build failure now: #802

@kentcdodds
Copy link
Member

I'm not sure why, but travis seems to be taking forever to run our builds. I'll look at this again tomorrow.

@codecov
Copy link

codecov bot commented Nov 3, 2020

Codecov Report

Merging #801 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #801   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          719       719           
  Branches       184       184           
=========================================
  Hits           719       719           
Impacted Files Coverage Δ
src/wait-for.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2cc8a11...a8dffff. Read the comment docs.

@kentcdodds kentcdodds merged commit 2cb8405 into testing-library:master Nov 3, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @romain-trotard for code

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @romain-trotard! 🎉

@testing-library-bot
Copy link

🎉 This PR is included in version 7.26.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants