@@ -15,6 +15,16 @@ export interface JUnitOptions {
1515 outputFile ?: string
1616 classname ?: string
1717 suiteName ?: string
18+ /**
19+ * Write <system-out> and <system-err> for console output
20+ * @default true
21+ */
22+ includeConsoleOutput ?: boolean
23+ /**
24+ * Add <testcase file="..."> attribute (validated on CIRCLE CI and GitLab CI)
25+ * @default false
26+ */
27+ addFileAttribute ?: boolean
1828}
1929
2030function flattenTasks ( task : Task , baseName = '' ) : Task [ ] {
@@ -88,7 +98,8 @@ export class JUnitReporter implements Reporter {
8898 private options : JUnitOptions
8999
90100 constructor ( options : JUnitOptions ) {
91- this . options = options
101+ this . options = { ...options }
102+ this . options . includeConsoleOutput ??= true
92103 }
93104
94105 async onInit ( ctx : Vitest ) : Promise < void > {
@@ -160,11 +171,14 @@ export class JUnitReporter implements Reporter {
160171 await this . writeElement ( 'testcase' , {
161172 // TODO: v2.0.0 Remove env variable in favor of custom reporter options, e.g. "reporters: [['json', { classname: 'something' }]]"
162173 classname : this . options . classname ?? process . env . VITEST_JUNIT_CLASSNAME ?? filename ,
174+ file : this . options . addFileAttribute ? filename : undefined ,
163175 name : task . name ,
164176 time : getDuration ( task ) ,
165177 } , async ( ) => {
166- await this . writeLogs ( task , 'out' )
167- await this . writeLogs ( task , 'err' )
178+ if ( this . options . includeConsoleOutput ) {
179+ await this . writeLogs ( task , 'out' )
180+ await this . writeLogs ( task , 'err' )
181+ }
168182
169183 if ( task . mode === 'skip' || task . mode === 'todo' )
170184 await this . logger . log ( '<skipped/>' )
@@ -259,8 +273,9 @@ export class JUnitReporter implements Reporter {
259273
260274 await this . writeElement ( 'testsuites' , stats , async ( ) => {
261275 for ( const file of transformed ) {
276+ const filename = relative ( this . ctx . config . root , file . filepath )
262277 await this . writeElement ( 'testsuite' , {
263- name : relative ( this . ctx . config . root , file . filepath ) ,
278+ name : filename ,
264279 timestamp : ( new Date ( ) ) . toISOString ( ) ,
265280 hostname : hostname ( ) ,
266281 tests : file . tasks . length ,
@@ -269,7 +284,7 @@ export class JUnitReporter implements Reporter {
269284 skipped : file . stats . skipped ,
270285 time : getDuration ( file ) ,
271286 } , async ( ) => {
272- await this . writeTasks ( file . tasks , file . name )
287+ await this . writeTasks ( file . tasks , filename )
273288 } )
274289 }
275290 } )
0 commit comments