Skip to content
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

[Feature]: Expose more information in JSON results when there is a suite-level error #15001

Open
kylekthompson opened this issue Apr 3, 2024 · 2 comments

Comments

@kylekthompson
Copy link

πŸš€ 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.

Copy link

github-actions bot commented May 3, 2024

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.

@github-actions github-actions bot added the Stale label May 3, 2024
@kylekthompson
Copy link
Author

Bump

@github-actions github-actions bot removed the Stale label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant