Created
February 18, 2014 00:33
-
-
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
This file contains hidden or 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 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