@@ -127,6 +127,7 @@ namespace Harness.Parallel.Host {
127
127
let passingFiles = 0 ;
128
128
let failingFiles = 0 ;
129
129
let errorResults : ErrorInfo [ ] = [ ] ;
130
+ let passingResults : { name : string [ ] } [ ] = [ ] ;
130
131
let totalPassing = 0 ;
131
132
const startTime = Date . now ( ) ;
132
133
@@ -198,9 +199,11 @@ namespace Harness.Parallel.Host {
198
199
totalPassing += data . payload . passing ;
199
200
if ( data . payload . errors . length ) {
200
201
errorResults = errorResults . concat ( data . payload . errors ) ;
202
+ passingResults = passingResults . concat ( data . payload . passes ) ;
201
203
failingFiles ++ ;
202
204
}
203
205
else {
206
+ passingResults = passingResults . concat ( data . payload . passes ) ;
204
207
passingFiles ++ ;
205
208
}
206
209
newPerfData [ hashName ( data . payload . runner , data . payload . file ) ] = data . payload . duration ;
@@ -367,21 +370,55 @@ namespace Harness.Parallel.Host {
367
370
368
371
IO . writeFile ( perfdataFileName ( configOption ) , JSON . stringify ( newPerfData , null , 4 ) ) ; // tslint:disable-line:no-null-keyword
369
372
370
- process . exit ( errorResults . length ) ;
373
+ if ( Utils . getExecutionEnvironment ( ) !== Utils . ExecutionEnvironment . Browser && process . env . CI === "true" ) {
374
+ const xunitReport = new xunit ( { on : ts . noop , once : ts . noop } , { reporterOptions : { output : "./TEST-results.xml" } } ) ;
375
+ xunitReport . stats = reporter . stats ;
376
+ xunitReport . failures = reporter . failures ;
377
+ const rootAttrs : { [ index : string ] : any } = {
378
+ name : "Tests" ,
379
+ tests : stats . tests ,
380
+ failures : stats . failures ,
381
+ errors : stats . failures ,
382
+ skipped : stats . tests - stats . failures - stats . passes ,
383
+ timestamp : ( new Date ( ) ) . toUTCString ( ) ,
384
+ time : ( stats . duration / 1000 ) || 0
385
+ } ;
386
+ xunitReport . write ( `<?xml version="1.0" encoding="UTF-8"?>` + "\n" ) ;
387
+ xunitReport . write ( `<testsuite ${ Object . keys ( rootAttrs ) . map ( k => `${ k } ="${ escape ( "" + rootAttrs [ k ] ) } "` ) . join ( " " ) } >` ) ;
388
+ [ ...failures , ...ts . map ( passingResults , makeMochaTest ) ] . forEach ( t => {
389
+ xunitReport . test ( t ) ;
390
+ } ) ;
391
+ xunitReport . write ( "</testsuite>" ) ;
392
+ xunitReport . done ( failures , ( f : any [ ] ) => {
393
+ process . exit ( f . length ) ;
394
+ } ) ;
395
+ }
396
+ else {
397
+ process . exit ( failures . length ) ;
398
+ }
399
+
371
400
}
372
401
373
- function makeMochaTest ( test : ErrorInfo ) {
402
+ function makeMochaTest ( test : ErrorInfo | TestInfo ) {
374
403
return {
404
+ state : ( test as ErrorInfo ) . error ? "failed" : "passed" ,
405
+ parent : {
406
+ fullTitle : ( ) => {
407
+ return test . name . slice ( 0 , test . name . length - 1 ) . join ( " " ) ;
408
+ }
409
+ } ,
410
+ title : test . name [ test . name . length - 1 ] ,
375
411
fullTitle : ( ) => {
376
412
return test . name . join ( " " ) ;
377
413
} ,
378
414
titlePath : ( ) => {
379
415
return test . name ;
380
416
} ,
381
- err : {
382
- message : test . error ,
383
- stack : test . stack
384
- }
417
+ isPending : ( ) => false ,
418
+ err : ( test as ErrorInfo ) . error ? {
419
+ message : ( test as ErrorInfo ) . error ,
420
+ stack : ( test as ErrorInfo ) . stack
421
+ } : undefined
385
422
} ;
386
423
}
387
424
@@ -392,6 +429,7 @@ namespace Harness.Parallel.Host {
392
429
393
430
let mocha : any ;
394
431
let base : any ;
432
+ let xunit : any ;
395
433
let color : any ;
396
434
let cursor : any ;
397
435
let readline : any ;
@@ -434,6 +472,7 @@ namespace Harness.Parallel.Host {
434
472
function initializeProgressBarsDependencies ( ) {
435
473
mocha = require ( "mocha" ) ;
436
474
base = mocha . reporters . Base ;
475
+ xunit = mocha . reporters . xunit ;
437
476
color = base . color ;
438
477
cursor = base . cursor ;
439
478
readline = require ( "readline" ) ;
0 commit comments