Skip to content

Instantly share code, notes, and snippets.

@elbartostrikesagain
Created February 18, 2014 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbartostrikesagain/9062192 to your computer and use it in GitHub Desktop.
Save elbartostrikesagain/9062192 to your computer and use it in GitHub Desktop.
mocha add all files in a path or directory to run tests on
var Mocha = require('mocha'),
fs = require('fs'),
_ = require('underscore');
var mocha = new Mocha({reporter: 'spec', ui: 'bdd'});
mocha.addPath = function(dir){
fs.readdirSync(dir).filter(function(file){
var fileArray = file.split('.');
if(fileArray.length == 1){
mocha.addPath(dir + "/" + fileArray[0]);
}
else if(fileArray.length > 1 && _.last(fileArray) == "js"){
var filePath = dir + "/" + file;
mocha.addFile(filePath);
}
else{
console.log("Warning: " + file + " is not a .js file in test path");
}
});
}
function run_tests(cb) {
mocha.addPath("./test");
mocha.run(function(failures) {
cb(failures);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment