-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: stringify Errors properly with --json flag #15329
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
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
left a comment
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!
|
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. |
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:
