Skip to content

Commit 155521a

Browse files
Copilotsheremet-va
andauthored
fix: preserve reporter options from config when CLI reporters override them (#8794)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: sheremet-va <[email protected]>
1 parent abc046f commit 155521a

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

packages/vitest/src/node/config/resolveConfig.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,22 @@ export function resolveConfig(
623623
)
624624

625625
if (cliReporters.length) {
626+
// When CLI reporters are specified, preserve options from config file
627+
const configReportersMap = new Map<string, Record<string, unknown>>()
628+
629+
// Build a map of reporter names to their options from the config
630+
for (const reporter of resolved.reporters) {
631+
if (Array.isArray(reporter)) {
632+
const [reporterName, reporterOptions] = reporter
633+
if (typeof reporterName === 'string') {
634+
configReportersMap.set(reporterName, reporterOptions as Record<string, unknown>)
635+
}
636+
}
637+
}
638+
626639
resolved.reporters = Array.from(new Set(toArray(cliReporters)))
627640
.filter(Boolean)
628-
.map(reporter => [reporter, {}])
641+
.map(reporter => [reporter, configReportersMap.get(reporter) || {}])
629642
}
630643
}
631644

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test, expect } from 'vitest'
2+
3+
test('simple test', () => {
4+
expect(1 + 1).toBe(2)
5+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
reporters: [
6+
['junit', {
7+
suiteName: 'custom-suite-name',
8+
addFileAttribute: true,
9+
}],
10+
],
11+
},
12+
})

test/reporters/tests/junit.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,21 @@ test('many errors without warning', async () => {
156156
)
157157
expect(stderr).not.toContain('MaxListenersExceededWarning')
158158
})
159+
160+
test('CLI reporter option preserves config file options', async () => {
161+
const { stdout } = await runVitestCli(
162+
'run',
163+
'--reporter=junit',
164+
'--root',
165+
resolve(import.meta.dirname, '../fixtures/junit-cli-options'),
166+
)
167+
168+
const xml = stabilizeReport(stdout)
169+
170+
// Verify that suiteName from config is preserved
171+
expect(xml).not.toContain('<testsuites name="vitest tests"')
172+
expect(xml).toContain('<testsuites name="custom-suite-name"')
173+
174+
// Verify that addFileAttribute from config is preserved
175+
expect(xml).toContain('file="')
176+
})

0 commit comments

Comments
 (0)