import * as glob from 'glob' ; import * as Mocha from 'mocha' ; import * as path from 'path' ; import { createReport } from '../coverage' ; export function run ( ) { const mochaOptions = { ui : 'tdd' , reporter : 'mocha-multi-reporters' , reporterOptions : { reporterEnabled : 'spec, xunit' , xunitReporterOptions : { output : path . resolve ( __dirname , '..' , '..' , 'alltests.xml' ) } } , color : true } ; const mocha = new Mocha ( mochaOptions ) ; const testsRoot = path . resolve ( __dirname , '..' ) ; return new Promise < void > ( ( c , e ) => { glob ( '**/**.test.js' , { cwd : testsRoot } , ( err , files ) => { if ( err ) { return e ( err ) ; } files . forEach ( f => mocha . addFile ( path . resolve ( testsRoot , f ) ) ) ; try { mocha . run ( failures => { if ( failures > 0 ) { e ( new Error ( `${ failures } tests failed.` ) ) ; } else { c ( ) ; } } ) ; } catch ( error ) { e ( error ) ; } } ) ; } ) . then ( ( ) => { if ( process . env [ 'GENERATE_COVERAGE' ] ) { createReport ( ) ; } } ) ; }