Last active
August 29, 2015 13:57
-
-
Save whitfin/9452143 to your computer and use it in GitHub Desktop.
Simple way to include all tests in Mocha with simple handling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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