Skip to content

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

@blimmer

Description

@blimmer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions