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

fix: guard against process and process.env not defined #1254

Closed
wants to merge 1 commit into from

Conversation

MatanBobi
Copy link
Member

@MatanBobi MatanBobi commented Nov 17, 2023

What: This PR guards against process being not defined in browser environments.

Why: It's breaking in browser environments.

How:

Checklist:

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

CC: @AviVahl

@@ -20,10 +20,10 @@ if (typeof process === 'undefined' || !process.env?.RTL_SKIP_AUTO_CLEANUP) {
teardown(() => {
cleanup()
})
} else if (!process.env.RTL_AFTEREACH_WARNING_LOGGED) {
} else if (process?.env && !process.env.RTL_AFTEREACH_WARNING_LOGGED) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If process.env is not defined, we'll not provide this functionality at all since we won't have a place to save the flag.

process.env.RTL_AFTEREACH_WARNING_LOGGED = true
console.warn(
`The current test runner does not support afterEach/teardown hooks. This means we won't be able to run automatic cleanup and you should be calling cleanup() manually.`,
`The current test runner does not support afterEach/teardown hooks or globals are not injected. This means we won't be able to run automatic cleanup and you should be calling cleanup() manually.`,
Copy link
Member Author

Choose a reason for hiding this comment

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

I've also updated this text because we received a couple of issues about it.

Copy link

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 e5dbeeb:

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

Copy link

codecov bot commented Nov 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d80319f) 100.00% compared to head (e5dbeeb) 100.00%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1254   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          192       192           
  Branches        40        40           
=========================================
  Hits           192       192           
Flag Coverage Δ
canary 100.00% <ø> (ø)
experimental 100.00% <ø> (ø)
latest 100.00% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MatanBobi MatanBobi closed this Nov 17, 2023
@MatanBobi
Copy link
Member Author

MatanBobi commented Nov 17, 2023

We will revert this change instead.

@MatanBobi MatanBobi deleted the fix/process-is-not-defined branch November 17, 2023 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant