-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat: stringify Errors properly with --json flag #15329
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ Deploy Preview for jestjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
SimenB
approved these changes
Jan 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
SimenB
changed the title
Stringify Errors properly with --json flag
feat: stringify Errors properly with --json flag
Jan 15, 2025
mohammednumaan
pushed a commit
to mohammednumaan/jest
that referenced
this pull request
Jan 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When running
jest
with the--json
flag, theError
s fromcollectHandles
injest-core/src/runJest.ts
is all passed into aJSON.stringify
, which turns them into an empty object.Users might expect or want the error message, name, and stack from the
--json
output possibly to collect data in the more structured JSON format — as opposed to plain stderr output — to help diagnose the source of the leaky handles.Changes
Originally, I just iterated over the
runResults.openHandles
inrunJest.ts:processResults
to grab the error message, name, and stack from theError
, but adding a test for that was kind of awkward.So I decided on adding a very basic
serializeToJSON
function that should replaceJSON.stringify
to handle stringifyingError
s as well as leaving room to stringify other objects in the future if needed.Test plan
serializeToJSON
JSON.stringify
for regular objectsJSON.stringify
by stringifyingError
s properlyFor a more e2e test, I added a temporary test to leak a handle, built the project, and ran the test: