Skip to content

Commit

Permalink
fix(reporters): testsuite name should include project root in Junit o…
Browse files Browse the repository at this point in the history
…utput (#5116)
  • Loading branch information
fenghan34 committed Feb 5, 2024
1 parent ae73f27 commit 2494fbf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/junit.ts
Expand Up @@ -268,7 +268,7 @@ export class JUnitReporter implements Reporter {
await this.writeElement('testsuites', stats, async () => {
for (const file of transformed) {
await this.writeElement('testsuite', {
name: file.name,
name: relative(this.ctx.config.root, file.filepath),
timestamp: (new Date()).toISOString(),
hostname: hostname(),
tests: file.tasks.length,
Expand Down
@@ -0,0 +1,5 @@
import { describe, test } from "vitest";

describe('space 1', () => {
test('base', () => {})
})
@@ -0,0 +1,5 @@
import { describe, test } from "vitest";

describe('space 2', () => {
test('base', () => {})
})
@@ -0,0 +1,3 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({})
@@ -0,0 +1,3 @@
import { defineWorkspace } from "vitest/config";

export default defineWorkspace(['space-1', 'space-2'])
10 changes: 10 additions & 0 deletions test/reporters/tests/junit.test.ts
Expand Up @@ -59,3 +59,13 @@ test('emits <failure> when beforeAll/afterAll failed', async () => {
stdout = stdout.replaceAll(/(timestamp|hostname|time)=".*?"/g, '$1="..."')
expect(stdout).toMatchSnapshot()
})

test('write testsuite name relative to root config', async () => {
let { stdout } = await runVitest({ reporters: 'junit', root: './fixtures/better-testsuite-name' })
stdout = stdout.replaceAll(/(timestamp|hostname|time)=".*?"/g, '$1="..."')

const space1 = '<testsuite name="space-1/test/base.test.ts" timestamp="..." hostname="..." tests="1" failures="0" errors="0" skipped="0" time="...">'
const space2 = '<testsuite name="space-2/test/base.test.ts" timestamp="..." hostname="..." tests="1" failures="0" errors="0" skipped="0" time="...">'
expect(stdout).toContain(space1)
expect(stdout).toContain(space2)
})

0 comments on commit 2494fbf

Please sign in to comment.