import * as path from 'path' ; import * as Mocha from 'mocha' ; import * as glob from 'glob' ; export function run ( ) { const mocha = new Mocha ( { ui : 'tdd' , timeout : 100000 , reporter : 'mocha-jenkins-reporter' , color : true } ) ; const testsRoot = path . resolve ( __dirname , '..' ) ; return new Promise ( ( 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 ) ; } } ) ; } ) ; }