Skip to content

Conversation

@noomorph
Copy link
Contributor

@noomorph noomorph commented Jul 9, 2025

Summary

This PR fixes a regression where errors thrown from a custom environment’s teardown() method were masked by an internal error, rather than being reported to the user. This led to confusing error messages and made debugging custom environments difficult.

  • Ensures that isTornDown is always set in a finally block, even if environment.teardown() throws. This prevents double teardown and ensures the real error is surfaced.
  • Adds a real end-to-end (e2e) test that:
    • Uses a custom environment that throws in teardown()
    • Asserts that Jest reports the actual error, not an internal or misleading one
    • Prevents future regressions of this kind

Why

  • The regression was reported in #15730.
  • Without this fix, users see a confusing internal error (The "object" argument must be of type object. Received null) instead of the real cause.
  • The new e2e test ensures this scenario is covered in CI.

Test plan

  • The new e2e test fails on the old behavior and passes with this fix.
  • The test runs a trivial test file using a custom environment that throws in teardown(), and asserts that the error is reported as expected.
  • CI will now catch regressions of this kind.

@netlify
Copy link

netlify bot commented Jul 9, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cac64d4
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/686e126e938d1e00089a4dbc
😎 Deploy Preview https://deploy-preview-15731--jestjs.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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 9, 2025

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15731

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15731

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15731

create-jest

npm i https://pkg.pr.new/create-jest@15731

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15731

expect

npm i https://pkg.pr.new/expect@15731

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15731

jest

npm i https://pkg.pr.new/jest@15731

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15731

jest-circus

npm i https://pkg.pr.new/jest-circus@15731

jest-cli

npm i https://pkg.pr.new/jest-cli@15731

jest-config

npm i https://pkg.pr.new/jest-config@15731

@jest/console

npm i https://pkg.pr.new/@jest/console@15731

@jest/core

npm i https://pkg.pr.new/@jest/core@15731

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15731

jest-diff

npm i https://pkg.pr.new/jest-diff@15731

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15731

jest-each

npm i https://pkg.pr.new/jest-each@15731

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15731

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15731

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15731

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15731

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15731

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15731

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15731

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15731

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15731

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15731

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15731

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15731

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15731

jest-mock

npm i https://pkg.pr.new/jest-mock@15731

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15731

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15731

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15731

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15731

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15731

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15731

jest-runner

npm i https://pkg.pr.new/jest-runner@15731

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15731

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15731

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15731

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15731

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15731

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15731

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15731

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15731

@jest/types

npm i https://pkg.pr.new/@jest/types@15731

jest-util

npm i https://pkg.pr.new/jest-util@15731

jest-validate

npm i https://pkg.pr.new/jest-validate@15731

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15731

jest-worker

npm i https://pkg.pr.new/jest-worker@15731

pretty-format

npm i https://pkg.pr.new/pretty-format@15731

commit: cac64d4

@noomorph noomorph force-pushed the fix/teardown-concealed-error branch from ba5b2b1 to ec50f9c Compare July 9, 2025 06:54
@noomorph noomorph force-pushed the fix/teardown-concealed-error branch from ec50f9c to cac64d4 Compare July 9, 2025 06:55
@noomorph
Copy link
Contributor Author

noomorph commented Jul 9, 2025

Please note that the test coverage reduction report is erroneous. This case has been covered by E2E test I added.

Copy link
Member

@cpojer cpojer left a comment

Choose a reason for hiding this comment

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

Thank you!

@cpojer cpojer merged commit 37b1686 into jestjs:main Jul 9, 2025
74 of 76 checks passed
@noomorph noomorph deleted the fix/teardown-concealed-error branch July 9, 2025 15:16
@github-actions
Copy link

github-actions bot commented Aug 9, 2025

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Jest 30 environment teardown error handling regression

2 participants