@@ -10,6 +10,7 @@ const glob = require('glob');
1010const fs = require ( 'fs' ) ;
1111const events = require ( 'events' ) ;
1212const mocha = require ( 'mocha' ) ;
13+ const MochaJUnitReporter = require ( 'mocha-junit-reporter' ) ;
1314const url = require ( 'url' ) ;
1415const minimatch = require ( 'minimatch' ) ;
1516const playwright = require ( 'playwright' ) ;
@@ -37,30 +38,44 @@ if (argv.help) {
3738}
3839
3940const withReporter = ( function ( ) {
40- const reporterPath = path . join ( path . dirname ( require . resolve ( 'mocha' ) ) , 'lib' , 'reporters' , argv . reporter ) ;
41- let ctor ;
41+ if ( argv . tfs ) {
42+ {
43+ return ( browserType , runner ) => {
44+ new mocha . reporters . Spec ( runner ) ;
45+ new MochaJUnitReporter ( runner , {
46+ reporterOptions : {
47+ testsuitesTitle : `${ argv . tfs } ${ process . platform } ` ,
48+ mochaFile : process . env . BUILD_ARTIFACTSTAGINGDIRECTORY ? path . join ( process . env . BUILD_ARTIFACTSTAGINGDIRECTORY , `test-results/${ process . platform } -${ browserType } -${ argv . tfs . toLowerCase ( ) . replace ( / [ ^ \w ] / g, '-' ) } -results.xml` ) : undefined
49+ }
50+ } ) ;
51+ }
52+ }
53+ } else {
54+ const reporterPath = path . join ( path . dirname ( require . resolve ( 'mocha' ) ) , 'lib' , 'reporters' , argv . reporter ) ;
55+ let ctor ;
4256
43- try {
44- ctor = require ( reporterPath ) ;
45- } catch ( err ) {
4657 try {
47- ctor = require ( argv . reporter ) ;
58+ ctor = require ( reporterPath ) ;
4859 } catch ( err ) {
49- ctor = process . platform === 'win32' ? mocha . reporters . List : mocha . reporters . Spec ;
50- console . warn ( `could not load reporter: ${ argv . reporter } , using ${ ctor . name } ` ) ;
60+ try {
61+ ctor = require ( argv . reporter ) ;
62+ } catch ( err ) {
63+ ctor = process . platform === 'win32' ? mocha . reporters . List : mocha . reporters . Spec ;
64+ console . warn ( `could not load reporter: ${ argv . reporter } , using ${ ctor . name } ` ) ;
65+ }
5166 }
52- }
5367
54- function parseReporterOption ( value ) {
55- let r = / ^ ( [ ^ = ] + ) = ( .* ) $ / . exec ( value ) ;
56- return r ? { [ r [ 1 ] ] : r [ 2 ] } : { } ;
57- }
68+ function parseReporterOption ( value ) {
69+ let r = / ^ ( [ ^ = ] + ) = ( .* ) $ / . exec ( value ) ;
70+ return r ? { [ r [ 1 ] ] : r [ 2 ] } : { } ;
71+ }
5872
59- let reporterOptions = argv [ 'reporter-options' ] ;
60- reporterOptions = typeof reporterOptions === 'string' ? [ reporterOptions ] : reporterOptions ;
61- reporterOptions = reporterOptions . reduce ( ( r , o ) => Object . assign ( r , parseReporterOption ( o ) ) , { } ) ;
73+ let reporterOptions = argv [ 'reporter-options' ] ;
74+ reporterOptions = typeof reporterOptions === 'string' ? [ reporterOptions ] : reporterOptions ;
75+ reporterOptions = reporterOptions . reduce ( ( r , o ) => Object . assign ( r , parseReporterOption ( o ) ) , { } ) ;
6276
63- return ( runner ) => new ctor ( runner , { reporterOptions } )
77+ return ( _ , runner ) => new ctor ( runner , { reporterOptions } )
78+ }
6479} ) ( )
6580
6681const outdir = argv . build ? 'out-build' : 'out' ;
@@ -137,7 +152,7 @@ async function runTestsInBrowser(testModules, browserType) {
137152 console [ msg . type ( ) ] ( msg . text ( ) , await Promise . all ( msg . args ( ) . map ( async arg => await arg . jsonValue ( ) ) ) ) ;
138153 } ) ;
139154
140- withReporter ( new EchoRunner ( emitter , browserType . toUpperCase ( ) ) ) ;
155+ withReporter ( browserType , new EchoRunner ( emitter , browserType . toUpperCase ( ) ) ) ;
141156
142157 // collection failures for console printing
143158 const fails = [ ] ;
0 commit comments