@@ -15,6 +15,16 @@ export interface JUnitOptions {
15
15
outputFile ?: string
16
16
classname ?: string
17
17
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
18
28
}
19
29
20
30
function flattenTasks ( task : Task , baseName = '' ) : Task [ ] {
@@ -88,7 +98,8 @@ export class JUnitReporter implements Reporter {
88
98
private options : JUnitOptions
89
99
90
100
constructor ( options : JUnitOptions ) {
91
- this . options = options
101
+ this . options = { ...options }
102
+ this . options . includeConsoleOutput ??= true
92
103
}
93
104
94
105
async onInit ( ctx : Vitest ) : Promise < void > {
@@ -160,11 +171,14 @@ export class JUnitReporter implements Reporter {
160
171
await this . writeElement ( 'testcase' , {
161
172
// TODO: v2.0.0 Remove env variable in favor of custom reporter options, e.g. "reporters: [['json', { classname: 'something' }]]"
162
173
classname : this . options . classname ?? process . env . VITEST_JUNIT_CLASSNAME ?? filename ,
174
+ file : this . options . addFileAttribute ? filename : undefined ,
163
175
name : task . name ,
164
176
time : getDuration ( task ) ,
165
177
} , 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
+ }
168
182
169
183
if ( task . mode === 'skip' || task . mode === 'todo' )
170
184
await this . logger . log ( '<skipped/>' )
@@ -259,8 +273,9 @@ export class JUnitReporter implements Reporter {
259
273
260
274
await this . writeElement ( 'testsuites' , stats , async ( ) => {
261
275
for ( const file of transformed ) {
276
+ const filename = relative ( this . ctx . config . root , file . filepath )
262
277
await this . writeElement ( 'testsuite' , {
263
- name : relative ( this . ctx . config . root , file . filepath ) ,
278
+ name : filename ,
264
279
timestamp : ( new Date ( ) ) . toISOString ( ) ,
265
280
hostname : hostname ( ) ,
266
281
tests : file . tasks . length ,
@@ -269,7 +284,7 @@ export class JUnitReporter implements Reporter {
269
284
skipped : file . stats . skipped ,
270
285
time : getDuration ( file ) ,
271
286
} , async ( ) => {
272
- await this . writeTasks ( file . tasks , file . name )
287
+ await this . writeTasks ( file . tasks , filename )
273
288
} )
274
289
}
275
290
} )
0 commit comments