diff --git a/packages/vitest/src/node/reporters/junit.ts b/packages/vitest/src/node/reporters/junit.ts index e15e22ea2155..a82ef7da117c 100644 --- a/packages/vitest/src/node/reporters/junit.ts +++ b/packages/vitest/src/node/reporters/junit.ts @@ -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, diff --git a/test/reporters/fixtures/better-testsuite-name/space-1/test/base.test.ts b/test/reporters/fixtures/better-testsuite-name/space-1/test/base.test.ts new file mode 100644 index 000000000000..7120043e3f7a --- /dev/null +++ b/test/reporters/fixtures/better-testsuite-name/space-1/test/base.test.ts @@ -0,0 +1,5 @@ +import { describe, test } from "vitest"; + +describe('space 1', () => { + test('base', () => {}) +}) diff --git a/test/reporters/fixtures/better-testsuite-name/space-2/test/base.test.ts b/test/reporters/fixtures/better-testsuite-name/space-2/test/base.test.ts new file mode 100644 index 000000000000..b722b79f14b3 --- /dev/null +++ b/test/reporters/fixtures/better-testsuite-name/space-2/test/base.test.ts @@ -0,0 +1,5 @@ +import { describe, test } from "vitest"; + +describe('space 2', () => { + test('base', () => {}) +}) diff --git a/test/reporters/fixtures/better-testsuite-name/vitest.config.ts b/test/reporters/fixtures/better-testsuite-name/vitest.config.ts new file mode 100644 index 000000000000..abed6b2116e1 --- /dev/null +++ b/test/reporters/fixtures/better-testsuite-name/vitest.config.ts @@ -0,0 +1,3 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({}) diff --git a/test/reporters/fixtures/better-testsuite-name/vitest.workspace.ts b/test/reporters/fixtures/better-testsuite-name/vitest.workspace.ts new file mode 100644 index 000000000000..5e8b04b6ba80 --- /dev/null +++ b/test/reporters/fixtures/better-testsuite-name/vitest.workspace.ts @@ -0,0 +1,3 @@ +import { defineWorkspace } from "vitest/config"; + +export default defineWorkspace(['space-1', 'space-2']) diff --git a/test/reporters/tests/junit.test.ts b/test/reporters/tests/junit.test.ts index cb8c6ce18ec9..0c721a5fc8f0 100644 --- a/test/reporters/tests/junit.test.ts +++ b/test/reporters/tests/junit.test.ts @@ -59,3 +59,13 @@ test('emits 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 = '' + const space2 = '' + expect(stdout).toContain(space1) + expect(stdout).toContain(space2) +})