[Feature]: Expose more information in JSON results when there is a suite-level error
🚀 Feature Proposal
Currently, when there are errors at the test suite (file) level the CLI prints something friendly and helpful like:
> jest --json --outputFile=tmp/jest.json --testLocationInResults --verbose
FAIL ./sum.test.js
● Test suite failed to run
Cannot find module 'foobar' from 'sum.js'
Require stack:
sum.js
sum.test.js
> 1 | require("foobar");
| ^
2 |
3 | function sum(a, b) {
4 | return a + b;
at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:487:11)
at Object.<anonymous> (sum.js:1:18)
at Object.<anonymous> (sum.test.js:1:29)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.167 s
Ran all test suites.
Test results written to: tmp/jest.json
This is quite helpful while debugging what went wrong in the test, but when looking at the JSON results, I only see:
{
"assertionResults": [],
"coverage": {},
"endTime": 1712151406453,
"message": " \u001b[1m● \u001b[22mTest suite failed to run\n\n Cannot find module 'foobar' from 'sum.js'\n\n Require stack:\n sum.js\n sum.test.js\n\n \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 1 |\u001b[39m require(\u001b[32m\"foobar\"\u001b[39m)\u001b[33m;\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 2 |\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 3 |\u001b[39m \u001b[36mfunction\u001b[39m sum(a\u001b[33m,\u001b[39m b) {\u001b[0m\n \u001b[0m \u001b[90m 4 |\u001b[39m \u001b[36mreturn\u001b[39m a \u001b[33m+\u001b[39m b\u001b[33m;\u001b[39m\u001b[0m\n\n \u001b[2mat Resolver._throwModNotFoundError (\u001b[22mnode_modules/jest-resolve/build/resolver.js\u001b[2m:487:11)\u001b[22m\n \u001b[2mat Object.<anonymous> (\u001b[22msum.js\u001b[2m:1:18)\u001b[22m\n \u001b[2mat Object.<anonymous> (\u001b[22m\u001b[0m\u001b[36msum.test.js\u001b[39m\u001b[0m\u001b[2m:1:29)\u001b[22m\n",
"name": "[REDACTED PATH TO TEST FILE]",
"startTime": 1712151406453,
"status": "failed",
"summary": ""
}
Is there any interest in exposing more of the helpful text/context from the CLI message in the JSON payload? I might be able to spare some time to do this if so (it doesn't seem like a massively large undertaking - I believe we'd just have to expose a little more info in formatTestResult).
Motivation
We wrote a library which consumes Jest JSON and summarizes the information in the JSON results into a friendly message to help ease some of the pain of scrolling through CI logs to figure out what went wrong. This, however, is important information we'd like to show which we currently have no access to.
Example
No response
Pitch
While it's likely possible to expose a custom reporter to do this, it'd be challenging to otherwise maintain a 1:1 API with the existing JSON report as it's not implemented as a reporter today. If it was, we could likely call the original and augment with additional information.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Bump
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.