Repository navigation
feat: stringify Errors properly with --json flag - #15329
Merged
Merged
Conversation
β 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
enabled auto-merge (squash)
January 15, 2025 12:33
mohammednumaan
pushed a commit
to mohammednumaan/jest
that referenced
this pull request
Jan 17, 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. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
jestwith the--jsonflag, theErrors fromcollectHandlesinjest-core/src/runJest.tsis 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
--jsonoutput 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.openHandlesinrunJest.ts:processResultsto 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
serializeToJSONfunction that should replaceJSON.stringifyto handle stringifyingErrors as well as leaving room to stringify other objects in the future if needed.Test plan
serializeToJSONJSON.stringifyfor regular objectsJSON.stringifyby stringifyingErrors properlyFor a more e2e test, I added a temporary test to leak a handle, built the project, and ran the test:
