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

Safe check for setImmediate and clearImmediate #916

Merged
merged 4 commits into from Mar 25, 2021

Conversation

renatoalencar
Copy link
Contributor

@renatoalencar renatoalencar commented Mar 25, 2021

What:

Avoid crashing when setImmediate and clearImmediate is not defined, which is now the case for JSDOM.

Why:

See #914

How:

Safe check suggested by @gaearon

Checklist:

  • Documentation added to the
    docs site
  • Tests
  • Typescript definitions updated
  • Ready to be merged

Jest is planning to sandbox setImmediate, and this would not work since
setImmediate and clearImmediate would
be undefined.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 25, 2021

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 014ed78:

Sandbox Source
react-testing-library-examples Configuration

@gaearon
Copy link

gaearon commented Mar 25, 2021

It would be good to check if this is enough to fix jestjs/jest#11222.

@renatoalencar
Copy link
Contributor Author

It would be good to check if this is enough to fix facebook/jest#11222.

That's great, I'm trying to find a reasonable way to add tests for this.

@gaearon
Copy link

gaearon commented Mar 25, 2021

Looks like jestjs/jest#11222 (comment) works!

@codecov
Copy link

codecov bot commented Mar 25, 2021

Codecov Report

Merging #916 (2781ebc) into master (c6acb0a) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 2781ebc differs from pull request most recent head 014ed78. Consider uploading reports for the commit 014ed78 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##            master      #916   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          944       948    +4     
  Branches       285       287    +2     
=========================================
+ Hits           944       948    +4     
Flag Coverage Δ
node-10.14.2 100.00% <100.00%> (ø)
node-12 100.00% <100.00%> (ø)
node-14 100.00% <100.00%> (ø)
node-15 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/helpers.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 c6acb0a...014ed78. Read the comment docs.

@renatoalencar
Copy link
Contributor Author

Looks like facebook/jest#11222 (comment) works!

That's awesome! It just finished testing it.

@renatoalencar renatoalencar changed the title Draft: Safe check for setImmediate and clearImmediate Safe check for setImmediate and clearImmediate Mar 25, 2021
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Haven't looked into the issue but this seems ok. Just some minor issues with the testing approach to consider.

src/__tests__/helpers.js Outdated Show resolved Hide resolved
src/__tests__/helpers.js Outdated Show resolved Hide resolved
src/__tests__/helpers.js Outdated Show resolved Hide resolved
Make sure that if the test breaks, it would not break
other tests either by properly restoring those
global variables in an afterEach call.
@renatoalencar

This comment has been minimized.

@eps1lon

This comment has been minimized.

@renatoalencar
Copy link
Contributor Author

This PR would close #914?

Yeah. I also tested temporarily deleting setImmediate from tests/setup-env.js to see if everything would still works and it looks like that's fine.

@eps1lon eps1lon linked an issue Mar 25, 2021 that may be closed by this pull request
kentcdodds
kentcdodds previously approved these changes Mar 25, 2021
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

LGTM 👍 And with the 👍👍 from several folks, I'd say we can merge this.

@kentcdodds
Copy link
Member

Hope you don't mind I added a little comment to explain why we have the extra check.

@kentcdodds kentcdodds merged commit 14788b6 into testing-library:master Mar 25, 2021
@kentcdodds
Copy link
Member

@all-contributors please add @renatoalencar for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @renatoalencar! 🎉

@renatoalencar
Copy link
Contributor Author

Hope you don't mind I added a little comment to explain why we have the extra check.

That's awesome, thanks.

@kentcdodds
Copy link
Member

@all-contributors please add @gaearon for bugs and review

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @gaearon! 🎉

@github-actions
Copy link

🎉 This PR is included in version 7.30.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gaearon
Copy link

gaearon commented Mar 25, 2021

thanks!

@renatoalencar renatoalencar deleted the fix-setimmediate branch March 29, 2021 12:41
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.

When running in Jest, code assumes setImmediate and clearImmediate
4 participants