Open sayhiben opened 2 years ago
Hey thanks for submitting an issue!
Couple of issues with implementing this, unfortunately.
jest-junit follows the jenkins junit xsd and this field is not part of that. Hard for me to say what impact it would have adding a non-standard field to everyones junit as different CI and reporting systems vary but since inception jest-junit has followed that spec. Details here https://github.com/jest-community/jest-junit/blob/master/__tests__/lib/junit.xsd#L42
The other issue is that jest does not pass reporters line numbers for tests so I don't have the ability to even add this field simply using the information that jest passes to reporters. More details here: https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts
Thanks for the context!
Completely understood about the spec, though I'm curious if you'd consider making the attribute optional and default to off?
As for whether Jest passes the line number, I went digging and discovered that newer versions of Jest have a GHA reporter. I'll give that a try today to see if it can meet my needs. They use the frame information to extract the line number in that reporter - see here: https://github.com/facebook/jest/blob/3b0a975269a3b712d0235f67fbd072dd9cb867b2/packages/jest-reporters/src/GitHubActionsReporter.ts#L60
Ah that is interesting. Seems like it derives the line number from a stack trace so I suppose only failing test cases would contain a line number.
If you submit a PR making it an optional attribute I am happy to review!
@palmerj3 Would you mind re-opening this issue? I've created an internal ticket to open a PR for this feature and would like to use this issue to help track
@sayhiben Any update on that PR?
Firstly, thanks for the library; it's super useful.
My team uses GitHub Actions as our CI orchestration layer. We use the jUnit XML format for consistent reporting across different parts of our stack, which allows us to use a common reporting tool that annotates our builds and PRs: https://github.com/mikepenz/action-junit-report
This GitHub Marketplace Action supports the
line="1234"
attribute on<testcase>
elements in junit.xml files and uses it to show failures in context of the PR:Currently, jest-junit does not include the necessary attribute in the junit xml output, so the GHA action always annotates the failures at line 1.
Please consider the addition of the
line="1234"
attribute on<testcase>
elements, both for success and failures. Our Python test runner outputs the line number that refers to the first line of each test, regardless of outcome.