Skip to content

Instantly share code, notes, and snippets.

@hertzg
Last active August 29, 2015 14:10
Show Gist options
  • Save hertzg/d938b0747f0f9e5d8caf to your computer and use it in GitHub Desktop.
Save hertzg/d938b0747f0f9e5d8caf to your computer and use it in GitHub Desktop.
Mocha Runner
var fs = require('fs'),
Mocha = require("mocha"),
path = require('path');
// Our Mocha runner
var mocha = new Mocha({
ui:"bdd",
reporter:"spec",
timeout:60000,
slow:10000
});
// Files which need to be ignored
var avoided = [
"node_modules"
];
// Add the tests to the Mocha instance
(addFiles = function(dir){
fs.readdirSync(dir).filter(function(file){
if(!~avoided.indexOf(file)){
if(fs.statSync(dir + '/' + file).isDirectory()){
addFiles(dir + '/' + file);
}
return file.substr(-3) === '.js';
}
}).forEach(function(file){
mocha.addFile(dir + '/' + file);
});
})(path.join(process.cwd(), process.argv[2] || "."));
// Run the files in Mocha
mocha.run(function(failures){
process.exit(failures);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment