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

@eps1lon eps1lon force-pushed the fix/vitest-globalthis branch from 40d8f04 to 3354c19 Compare May 17, 2022 18:49
@eps1lon eps1lon force-pushed the fix/vitest-globalthis branch from 3354c19 to 4df5d4d Compare May 17, 2022 18:51
@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

CrispyBaguette pushed a commit to CrispyBaguette/wasm-palette-converter that referenced this pull request Nov 8, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@testing-library/react](https://github.com/testing-library/react-testing-library) | dependencies | minor | [`13.2.0` -> `13.4.0`](https://renovatebot.com/diffs/npm/@testing-library%2freact/13.2.0/13.4.0) |

---

### Release Notes

<details>
<summary>testing-library/react-testing-library (@&#8203;testing-library/react)</summary>

### [`v13.4.0`](https://github.com/testing-library/react-testing-library/releases/tag/v13.4.0)

[Compare Source](testing-library/react-testing-library@v13.3.0...v13.4.0)

##### Features

-   **renderHook:** allow passing of all render options to renderHook ([#&#8203;1118](testing-library/react-testing-library#1118)) ([27a9584](testing-library/react-testing-library@27a9584))

### [`v13.3.0`](https://github.com/testing-library/react-testing-library/releases/tag/v13.3.0)

[Compare Source](testing-library/react-testing-library@v13.2.0...v13.3.0)

##### Features

-   Use `globalThis` if available ([#&#8203;1070](testing-library/react-testing-library#1070)) ([c80809a](testing-library/react-testing-library@c80809a))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xNDIuNSIsInVwZGF0ZWRJblZlciI6IjM4LjE0Mi41IiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->

Reviewed-on: https://gitea.bruyant.xyz/alexandre/PaletteSwitcher/pulls/46
Co-authored-by: Renovate <[email protected]>
Co-committed-by: Renovate <[email protected]>
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