-
-
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. |
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
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:
