Skip to content

Instantly share code, notes, and snippets.

@whitfin
Last active August 29, 2015 13:57
Show Gist options
  • Save whitfin/9452143 to your computer and use it in GitHub Desktop.
Save whitfin/9452143 to your computer and use it in GitHub Desktop.
Simple way to include all tests in Mocha with simple handling.
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