-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: Guard against process
not being defined
#911
Conversation
Webpack 5 doesn't shim Node's process object by default anymore. Only instances of process.env.NODE_ENV are replaced statically. This means that unguarded checks of process.env will crash in browser environments (such as Karma).
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 a7c2a78:
|
@@ -5,7 +5,7 @@ import {cleanup} from './pure' | |||
// this ensures that tests run in isolation from each other | |||
// if you don't like this then either import the `pure` module | |||
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'. | |||
if (!process.env.RTL_SKIP_AUTO_CLEANUP) { | |||
if (typeof process === "undefined" || !process.env?.RTL_SKIP_AUTO_CLEANUP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does your build setup support optional chaining? I hope that's fine 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be transpiled loosely.
Codecov Report
@@ Coverage Diff @@
## main #911 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 140 140
Branches 26 26
=========================================
Hits 140 140
Continue to review full report at Codecov.
|
process
not being defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@all-contributors Add @jhnns for code |
I've put up a pull request to add @jhnns! 🎉 |
🎉 This PR is included in version 11.2.7 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Not needed anymore with v11.2.7+ See testing-library/react-testing-library#911
Webpack 5 doesn't shim Node's `process` object by default anymore. Only instances of `process.env.NODE_ENV` are replaced statically. This means that unguarded checks of `process.env` will crash in browser environments (such as Karma). This is a port of testing-library/react-testing-library#911
Hi all 👋
What:
Fixes
when @testing-library/react is being used with webpack 5 and karma.
Why:
Webpack 5 doesn't shim Node's
process
object by default anymore. Only instances ofprocess.env.NODE_ENV
are replaced statically. This means that unguarded checks ofprocess.env
will crash in browser environments.How:
I was wondering if there should also be a check in
dont-cleanup-after-each.js
. I decided against it since this would need to define a globalprocess
object in order to define the env variable. After all, it's the app developer's responsibility to provide a globalprocess
object in this case.Checklist:
docs site N/A