Skip to content

Instantly share code, notes, and snippets.

@neilmanuell
Created May 1, 2013 08:58
Show Gist options
  • Save neilmanuell/5494389 to your computer and use it in GitHub Desktop.
Save neilmanuell/5494389 to your computer and use it in GitHub Desktop.
Mocha test runner for use with NodeJS.
var Mocha = require('mocha'),
path = require('path'),
fs = require('fs');
var mocha = new Mocha({
reporter: 'dot',
ui: 'bdd',
timeout: 999999
});
var testDir = './test/';
fs.readdir(testDir, function (err, files) {
if (err) {
console.log(err);
return;
}
files.forEach(function (file) {
if (path.extname(file) === '.js') {
console.log('adding test file: %s', file);
mocha.addFile(testDir + file);
}
});
var runner = mocha.run(function () {
console.log('finished');
});
runner.on('pass', function (test) {
console.log('... %s passed', test.title);
});
runner.on('fail', function (test) {
console.log('... %s failed', test.title);
});
});
@neilmanuell
Copy link
Author

taken unedited from @ronderksen (twitter) originally here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment