Skip to content

Commit

Permalink
fix: Guard against process not being defined (#68)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
swissspidy committed Jan 18, 2023
1 parent 651cbc4 commit b589fbd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 PTL_SKIP_AUTO_CLEANUP env variable to 'true'.
if (!process.env.PTL_SKIP_AUTO_CLEANUP) {
if (typeof process === "undefined" || !process.env.PTL_SKIP_AUTO_CLEANUP) {
if (typeof afterEach === 'function') {
afterEach(async () => {
await cleanup()
Expand Down

0 comments on commit b589fbd

Please sign in to comment.