Skip to content

Commit 2494fbf

Browse files
authoredFeb 5, 2024
fix(reporters): testsuite name should include project root in Junit output (#5116)
1 parent ae73f27 commit 2494fbf

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed
 

‎packages/vitest/src/node/reporters/junit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class JUnitReporter implements Reporter {
268268
await this.writeElement('testsuites', stats, async () => {
269269
for (const file of transformed) {
270270
await this.writeElement('testsuite', {
271-
name: file.name,
271+
name: relative(this.ctx.config.root, file.filepath),
272272
timestamp: (new Date()).toISOString(),
273273
hostname: hostname(),
274274
tests: file.tasks.length,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { describe, test } from "vitest";
2+
3+
describe('space 1', () => {
4+
test('base', () => {})
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { describe, test } from "vitest";
2+
3+
describe('space 2', () => {
4+
test('base', () => {})
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineWorkspace } from "vitest/config";
2+
3+
export default defineWorkspace(['space-1', 'space-2'])

‎test/reporters/tests/junit.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,13 @@ test('emits <failure> when beforeAll/afterAll failed', async () => {
5959
stdout = stdout.replaceAll(/(timestamp|hostname|time)=".*?"/g, '$1="..."')
6060
expect(stdout).toMatchSnapshot()
6161
})
62+
63+
test('write testsuite name relative to root config', async () => {
64+
let { stdout } = await runVitest({ reporters: 'junit', root: './fixtures/better-testsuite-name' })
65+
stdout = stdout.replaceAll(/(timestamp|hostname|time)=".*?"/g, '$1="..."')
66+
67+
const space1 = '<testsuite name="space-1/test/base.test.ts" timestamp="..." hostname="..." tests="1" failures="0" errors="0" skipped="0" time="...">'
68+
const space2 = '<testsuite name="space-2/test/base.test.ts" timestamp="..." hostname="..." tests="1" failures="0" errors="0" skipped="0" time="...">'
69+
expect(stdout).toContain(space1)
70+
expect(stdout).toContain(space2)
71+
})

0 commit comments

Comments
 (0)
Please sign in to comment.