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

feat: Use globalThis if available #1070

Merged
merged 1 commit into from May 28, 2022

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented May 17, 2022

What:

Closes #1061

Why:

Test runners like vitest create environments where window does not reflect self. This is not an environment that exists outside of vitest. This was fixed in latest versions of vitest (see vitest-dev/vitest#1256).

But it's good to get in anyway to support older versions as well as other test environments that aren't configured properly but run in later versions of Node or browsers.

How:

Use globalThis if available.

Checklist:

  • [ ] Documentation added to the
    docs site
  • Tests
  • [ ] TypeScript definitions updated
  • Ready to be merged

@eps1lon eps1lon added the enhancement New feature or request label May 17, 2022
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 17, 2022

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 4df5d4d:

Sandbox Source
React Configuration
react-testing-library-examples Configuration

@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #1070 (4df5d4d) into main (f176285) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #1070   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          181       181           
  Branches        36        36           
=========================================
  Hits           181       181           
Flag Coverage Δ
experimental 100.00% <100.00%> (ø)
latest 100.00% <100.00%> (ø)
next 100.00% <100.00%> (ø)

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

Impacted Files Coverage Δ
src/act-compat.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 f176285...4df5d4d. Read the comment docs.

@eps1lon eps1lon marked this pull request as ready for review May 17, 2022 19:02
@nknapp
Copy link

nknapp commented May 27, 2022

I've been wondering if this should be covered by a test. This is always the hard part...

@eps1lon
Copy link
Member Author

eps1lon commented May 28, 2022

We didn't cover the other branches as well.

The specific bug can only be tested with older versions of vitest anyway.

@eps1lon eps1lon merged commit c80809a into testing-library:main May 28, 2022
@eps1lon eps1lon deleted the fix/vitest-globalthis branch May 28, 2022 08:18
@github-actions
Copy link

🎉 This PR is included in version 13.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ph-fritsche
Copy link
Member

I've been wondering if this should be covered by a test. This is always the hard part...

I've added a linting rule in user-event making sure that any global is accessed per globalThis.

(Because of issues with environments which shadow global variables in test. Resulting in constructors not being identical, thus errors in jsdom internals due to instanceof failing.)

See testing-library/user-event#931

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The current testing environment is not configured to support act(...) with vitest and React 18
3 participants