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 Request: Add line attribute to <testcase> element #228

Open
sayhiben opened this issue Oct 4, 2022 · 5 comments
Open

Feature Request: Add line attribute to <testcase> element #228

sayhiben opened this issue Oct 4, 2022 · 5 comments

Comments

@sayhiben
Copy link

sayhiben commented Oct 4, 2022

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:

image

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.

@palmerj3
Copy link
Collaborator

palmerj3 commented Oct 4, 2022

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

@palmerj3 palmerj3 closed this as completed Oct 4, 2022
@sayhiben
Copy link
Author

sayhiben commented Oct 4, 2022

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

@palmerj3
Copy link
Collaborator

palmerj3 commented Oct 4, 2022

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!

@sayhiben
Copy link
Author

sayhiben commented Oct 7, 2022

@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

@palmerj3 palmerj3 reopened this Oct 8, 2022
@azizur
Copy link

azizur commented Mar 16, 2023

@sayhiben Any update on that PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants