feat(junit-reporter): add jest-junit-compatible naming options#10189
feat(junit-reporter): add jest-junit-compatible naming options#10189sheremet-va merged 7 commits intovitest-dev:mainfrom
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Adds opt-in, jest-junit-compatible naming controls to Vitest’s built-in JUnit reporter so users can template <testsuite> / <testcase> naming and optionally omit stack traces, while keeping defaults unchanged.
Changes:
- Added
suiteNameTemplate,titleTemplate,ancestorSeparator, andnoStackTraceoptions to the JUnit reporter. - Extended
classnameTemplateto support additional placeholders (e.g.{classname},{title},{suitename},{basename},{displayName}). - Added new fixtures + tests and updated docs to cover the new templating behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/cli/test/reporters/junit.test.ts | Adds coverage for suite/testcase templating, separator behavior, basename handling, and stack-trace omission. |
| test/cli/fixtures/reporters/junit-options/sample.test.ts | New fixture to exercise top-level vs nested describe naming behavior. |
| packages/vitest/src/node/reporters/junit.ts | Implements new templating options, placeholder variables, and noStackTrace behavior. |
| docs/guide/reporters.md | Documents new JUnit reporter options and available placeholders with examples. |
|
According to copilot, none of the failing changes are caused by my changes: https://github.com/copilot/share/4a06511c-41a4-8cf0-a953-a64a2457605e |
1ad53a6 to
ff150ed
Compare
ff150ed to
e75b09a
Compare
| @@ -0,0 +1,19 @@ | |||
| import { describe, expect, it } from 'vitest' | |||
There was a problem hiding this comment.
I don't think this file is supposed to be in this directory. cli was renamed to e2e
There was a problem hiding this comment.
I'm fixing it right now.
9863d1c to
570727c
Compare
| /** | ||
| * Omit stack traces from test failure reports. | ||
| * @default false | ||
| */ | ||
| noStackTrace?: boolean |
There was a problem hiding this comment.
I would actually prefer naming this without negation:
| /** | |
| * Omit stack traces from test failure reports. | |
| * @default false | |
| */ | |
| noStackTrace?: boolean | |
| /** | |
| * Include stack traces from test failure reports. | |
| * @default true | |
| */ | |
| stackTrace?: boolean |
There was a problem hiding this comment.
Sure, I can do that tomorrow.
Agent-Logs-Url: https://github.com/neumaennl/vitest/sessions/e2943b00-8b3b-4733-854d-07b3b2366f66 Co-authored-by: neumaennl <7926739+neumaennl@users.noreply.github.com>
Agent-Logs-Url: https://github.com/neumaennl/vitest/sessions/e2943b00-8b3b-4733-854d-07b3b2366f66 Co-authored-by: neumaennl <7926739+neumaennl@users.noreply.github.com>
…ocs wording Agent-Logs-Url: https://github.com/neumaennl/vitest/sessions/a7cecfc9-6b7a-4178-9f6b-810d04207d7b Co-authored-by: neumaennl <7926739+neumaennl@users.noreply.github.com>
…n in templates Agent-Logs-Url: https://github.com/neumaennl/vitest/sessions/f01d6aee-fd1d-417f-8a79-fd312a35e48a Co-authored-by: neumaennl <7926739+neumaennl@users.noreply.github.com>
…ar; fix docs grammar Agent-Logs-Url: https://github.com/neumaennl/vitest/sessions/d25e62ee-1d1e-45fd-8dc0-c7daf255346b Co-authored-by: neumaennl <7926739+neumaennl@users.noreply.github.com>
39ad3de to
eb41a34
Compare
|
Oh, seems like tests are failing |
…verted the default so the behavior stays the same Co-authored-by: Copilot <copilot@github.com>
eb41a34 to
582f2d8
Compare
I wasn't ready. Now it should be fine. The one failing check is a flaky playwright test running into a timeout that shouldn't be caused by my changes. |
Problem
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 throughsuiteNameTemplate,classNameTemplate,titleTemplate, andancestorSeparator. Migrating from jest to Vitest therefore produces noticeably different CI XML output.Solution
Four new opt-in options are added to the
JUnitOptionsinterface. Defaults are unchanged so existing reports are not affected.New options
suiteNameTemplatestring | function<testsuite name>. Placeholders:{title},{filename},{filepath},{basename},{displayName}titleTemplatestring | function<testcase name>. Same placeholders asclassnameTemplate.ancestorSeparatorstring" > "{classname}and the default test title.noStackTracebooleanfalse<failure>bodies (message attribute is still written).Extended
classnameTemplateThe existing
classnameTemplateoption gains five new placeholders:{classname},{title},{suitename},{basename},{displayName}.New template variable:
{classname}{classname}is the chain of ancestordescribeblock names joined byancestorSeparator(e.g."outer > inner"). Combined with{title}this reproduces jest-junit's default"{classname} {title}"style.New template variable:
{basename}{basename}is the bare file name without any directory component (e.g.foo.test.ts). This corresponds to jest-junit's{filename}. Vitest keeps{filename}as the relative path from the project root for backward compatibility.Example – jest-junit-compatible output
Compatibility
undefined/falseby default.{filename}inclassnameTemplatecontinues to resolve to the relative path (not basename), preserving backward compatibility for existing users.Tests
11 new tests added to
test/cli/test/reporters/junit.test.ts. All 24 JUnit reporter tests pass.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.Fixes #10191