Skip to content

fix(jest-circus): preserve Error.cause in JSON failureMessages (#15949)#15967

Open
xamgore wants to merge 3 commits intojestjs:mainfrom
xamgore:main
Open

fix(jest-circus): preserve Error.cause in JSON failureMessages (#15949)#15967
xamgore wants to merge 3 commits intojestjs:mainfrom
xamgore:main

Conversation

@xamgore
Copy link
Contributor

@xamgore xamgore commented Feb 22, 2026

Preserve Error.cause in JSON failureMessages for both jest-circus and jest-jasmine2.

Summary

Fixes #15949.

The CLI already showed error causes, but JSON results could drop them in assertionResults[*].failureMessages.

The gap was in runner-level serialization:

  • jest-circus built failure messages from error.stack / error.message
  • jest-jasmine2 reporter did the same for failedExpectations

Node stacks do not include the full cause chain, so nested causes were missing in JSON output.

This PR updates both runners to serialize causes recursively with a [cause]: ... marker, including:

  • nested Error causes
  • string causes
  • circular cause protection

Changes:

  • packages/jest-circus/src/utils.ts
  • packages/jest-jasmine2/src/reporter.ts

Tests:

  • e2e JSON assertion in e2e/__tests__/failures.test.ts checks both:
    • [cause]: Error: error during g
    • [cause]: here is the cause
  • added jasmine2 unit coverage in packages/jest-jasmine2/src/__tests__/reporter.test.ts

Test plan

Ran:

  • yarn eslint e2e/__tests__/failures.test.ts packages/jest-circus/src/utils.ts packages/jest-jasmine2/src/reporter.ts packages/jest-jasmine2/src/__tests__/reporter.test.ts
  • yarn jest e2e/__tests__/failures.test.ts -t "includes error causes in JSON failureMessages" --runInBand
  • JEST_JASMINE=1 yarn jest e2e/__tests__/failures.test.ts -t "includes error causes in JSON failureMessages" --runInBand
  • yarn jest packages/jest-circus/src/__tests__/utils.test.ts --runInBand
  • yarn jest packages/jest-jasmine2/src/__tests__/reporter.test.ts --runInBand

…s#15949)

Add recursive cause serialization to circus failureMessages and cover it in e2e JSON output assertions.
@netlify
Copy link

netlify bot commented Feb 22, 2026

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a6ec61c
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/69a9c77e74dba70008d11ce4
😎 Deploy Preview https://deploy-preview-15967--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.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 22, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 22, 2026

Open in StackBlitz

babel-jest

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

babel-plugin-jest-hoist

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

babel-preset-jest

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

create-jest

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

@jest/diff-sequences

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

expect

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

@jest/expect-utils

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

jest

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

jest-changed-files

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

jest-circus

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

jest-cli

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

jest-config

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

@jest/console

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

@jest/core

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

@jest/create-cache-key-function

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

jest-diff

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

jest-docblock

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

jest-each

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

@jest/environment

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

jest-environment-jsdom

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

@jest/environment-jsdom-abstract

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

jest-environment-node

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

@jest/expect

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

@jest/fake-timers

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

@jest/get-type

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

@jest/globals

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

jest-haste-map

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

jest-jasmine2

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

jest-leak-detector

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

jest-matcher-utils

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

jest-message-util

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

jest-mock

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

@jest/pattern

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

jest-phabricator

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

jest-regex-util

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

@jest/reporters

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

jest-resolve

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

jest-resolve-dependencies

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

jest-runner

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

jest-runtime

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

@jest/schemas

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

jest-snapshot

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

@jest/snapshot-utils

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

@jest/source-map

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

@jest/test-result

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

@jest/test-sequencer

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

@jest/transform

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

@jest/types

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

jest-util

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

jest-validate

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

jest-watcher

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

jest-worker

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

pretty-format

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

commit: d075c34

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.

[Bug]: Error.cause does not printed

1 participant