/// var glob = require('glob'); var _ = require('lodash'); var Mocha = require('mocha'); var sync = glob.sync; var defaultOptions = { slow: 2000, timeout: 10000, bail: true, ignoreLeaks: false, compilers: require('coffee-script/register'), recursive: true, asyncOnly: false }; class MochaInitializr { public files:any = []; public options:any = {}; public mocha:any; public close:any; public grepPattern:any = /.*/; constructor(options) { if(_.isEmpty(options)) { this.options = _.assign(defaultOptions, options); } this.close = MochaInitializr.onExit; return this; } public init() { this.mocha = new Mocha(this.options); this.files.forEach((filePath) => { this.mocha.addFile(filePath); }); return this; } public load(pattern) { var files = sync(pattern); this.files = this.files.concat(files); return this; } public onlyTest(pattern) { if(!this.mocha) { throw new Error('please initialize mocha first( call init() )'); } this.mocha.fgrep(pattern); return this; } public run(done) { var run = this.mocha.run(function(failures) { if(_.isFunction(done)) { done.call(this, run); } else { process.on('exit', function(){ process.exit(failures); }); } }); return run; } static onExit() { process.on('exit', function() { process.exit(1); }); return this; } } export = MochaInitializr;