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: allow using test file's relative path in xunit reporter output #5289

Open
2 of 3 tasks
blimmer opened this issue Jan 30, 2025 · 2 comments · May be fixed by #5292
Open
2 of 3 tasks

🚀 Feature: allow using test file's relative path in xunit reporter output #5289

blimmer opened this issue Jan 30, 2025 · 2 comments · May be fixed by #5292
Labels
area: reporters involving a specific reporter status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal

Comments

@blimmer
Copy link

blimmer commented Jan 30, 2025

Feature Request Checklist

Overview

Today, the xunit reporter always fills the file attribute with the fully qualified path to the file.

> npx mocha --reporter=xunit
<testsuite name="Mocha Tests" tests="1" failures="0" errors="0" skipped="0" timestamp="Thu, 30 Jan 2025 00:11:09 GMT" time="0.001">
<testcase classname="add" name="should add two numbers" file="/private/tmp/test-mocha/test/add.test.js" time="0"/>
</testsuite>

In CircleCI, when a test fails, they provide a dedicated UI that reads junit-compatible xml files and shows failures in a user-friendly way:

Image

However, because the fully qualified path is provided, I have to delete the prefix (/home/circleci/project) to paste it into my editor to pull up the file.

With my jest test suites and the junit reporter, I can easily just click the "copy" icon because it's the relative path:

Image

Suggested Solution

We should introduce a new reporterOption for this feature. Perhaps it's called useRelativeFilePath and defaults to false to retain backward compatibility.

We could alternatively use a mode like filePathMode: 'relative' | 'absolute', defaulting to absolute.

Alternatives

For now, I'm just using sed to edit the file after it's produced. But it would be nice to remove this additional step.

Additional Info

No response

@blimmer blimmer added status: in triage a maintainer should (re-)triage (review) this issue type: feature enhancement proposal labels Jan 30, 2025
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Jan 30, 2025

👍 this strikes me as a very reasonable feature request. Absolute paths in CI output are irksome in a lot of contexts. The irritation of constantly having to remove the absolute prefix is definitely something I resonate with!

Accepting PRs as an opt-in reporter option. Thanks for filing!

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! area: reporters involving a specific reporter and removed status: in triage a maintainer should (re-)triage (review) this issue labels Jan 30, 2025
@blimmer
Copy link
Author

blimmer commented Jan 30, 2025

Thanks, in the meantime this is what I'm doing, in case it helps others:

- run:
    name: Make JUnit XML report contain relative paths # Work around https://github.com/mochajs/mocha/issues/5289
    command: |
      sed -i "s|file=\"$(pwd)/|file=\"|" ./junit-reports/mocha.xml

Folks can adapt this pattern pretty easily to other CI platforms too 😄

@Dinika Dinika linked a pull request Feb 5, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: reporters involving a specific reporter status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants