Skip to content

Add jest-junit-compatible naming options to junit-reporter #10191

@neumaennl

Description

@neumaennl

Clear and concise description of the problem

As a developer using Vitest I want configure the JUnit reporter the same way I can configure jest-junit so that the generated JUnit XML file still looks the same after a migration from Jest to Vitest.

Vitest's built-in JUnit reporter names <testsuite> elements with the relative file path and names <testcase> elements with the full test hierarchy joined by >. This differs substantially from jest-junit, which offers rich template-based naming through suiteNameTemplate, classNameTemplate, titleTemplate, and ancestorSeparator. Migrating from jest to Vitest therefore produces noticeably different CI XML output.

Suggested solution

Four new opt-in options are added to the JUnitOptions interface. Defaults are unchanged so existing reports are not affected.

New options

Option Type Default Description
suiteNameTemplate string | function Template for <testsuite name>. Placeholders: {title}, {filename}, {filepath}, {basename}, {displayName}
titleTemplate string | function Template for <testcase name>. Same placeholders as classnameTemplate.
ancestorSeparator string " > " Separator for ancestor describe names when building {classname} and the default test title.
noStackTrace boolean false Omit stack trace text from <failure> bodies (message attribute is still written).

Alternative

No response

Additional context

No response

Validations

Related PR: #10189

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions