@@ -127,6 +127,7 @@ namespace Harness.Parallel.Host {
127127 let passingFiles = 0 ;
128128 let failingFiles = 0 ;
129129 let errorResults : ErrorInfo [ ] = [ ] ;
130+ let passingResults : { name : string [ ] } [ ] = [ ] ;
130131 let totalPassing = 0 ;
131132 const startTime = Date . now ( ) ;
132133
@@ -198,9 +199,11 @@ namespace Harness.Parallel.Host {
198199 totalPassing += data . payload . passing ;
199200 if ( data . payload . errors . length ) {
200201 errorResults = errorResults . concat ( data . payload . errors ) ;
202+ passingResults = passingResults . concat ( data . payload . passes ) ;
201203 failingFiles ++ ;
202204 }
203205 else {
206+ passingResults = passingResults . concat ( data . payload . passes ) ;
204207 passingFiles ++ ;
205208 }
206209 newPerfData [ hashName ( data . payload . runner , data . payload . file ) ] = data . payload . duration ;
@@ -367,21 +370,55 @@ namespace Harness.Parallel.Host {
367370
368371 IO . writeFile ( perfdataFileName ( configOption ) , JSON . stringify ( newPerfData , null , 4 ) ) ; // tslint:disable-line:no-null-keyword
369372
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+
371400 }
372401
373- function makeMochaTest ( test : ErrorInfo ) {
402+ function makeMochaTest ( test : ErrorInfo | TestInfo ) {
374403 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 ] ,
375411 fullTitle : ( ) => {
376412 return test . name . join ( " " ) ;
377413 } ,
378414 titlePath : ( ) => {
379415 return test . name ;
380416 } ,
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
385422 } ;
386423 }
387424
@@ -392,6 +429,7 @@ namespace Harness.Parallel.Host {
392429
393430 let mocha : any ;
394431 let base : any ;
432+ let xunit : any ;
395433 let color : any ;
396434 let cursor : any ;
397435 let readline : any ;
@@ -434,6 +472,7 @@ namespace Harness.Parallel.Host {
434472 function initializeProgressBarsDependencies ( ) {
435473 mocha = require ( "mocha" ) ;
436474 base = mocha . reporters . Base ;
475+ xunit = mocha . reporters . xunit ;
437476 color = base . color ;
438477 cursor = base . cursor ;
439478 readline = require ( "readline" ) ;
0 commit comments