Skip to content

fix: guard process.memoryUsage call with typeof check for browser compatibility#9895

Open
ViniciusDev26 wants to merge 3 commits intovitest-dev:mainfrom
ViniciusDev26:fix/logHeapUsage-browser-mode
Open

fix: guard process.memoryUsage call with typeof check for browser compatibility#9895
ViniciusDev26 wants to merge 3 commits intovitest-dev:mainfrom
ViniciusDev26:fix/logHeapUsage-browser-mode

Conversation

@ViniciusDev26
Copy link
Copy Markdown

Fixes UnhandledRejection when logHeapUsage is true in browser environments where process is a polyfill without memoryUsage.

Description

Guard process.memoryUsage calls with a typeof check before invoking it, preventing an UnhandledRejection crash when logHeapUsage: true is set in environments where process is a polyfill without memoryUsage (e.g. browser mode).

Resolves #6500

The previous check (typeof process !== 'undefined') only verified that process existed, but not that memoryUsage was actually a
function. In browser environments, process is polyfilled but memoryUsage is not available, causing the call to throw. The fix changes
both guards in onAfterRunSuite and onAfterRunTask to typeof process?.memoryUsage === 'function'.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

…patibility

Fixes UnhandledRejection when logHeapUsage is true in browser environments where process is a polyfill without memoryUsage.
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 17, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 44f7f2b
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69b9cdce62311500084cc70e
😎 Deploy Preview https://deploy-preview-9895--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

In environments that don't support memoryUsage, we wanted to use performance.measureUserAgentSpecificMemory as mentioned in the comment: #6500 (comment)

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.

UnhandledRejection: process.memoryUsage

2 participants