public
Last active

gruntjs Mocha task

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
* grunt
* https://github.com/cowboy/grunt
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Copyright (c) 2012 John K. Paul @johnkpaul
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
 
module.exports = function(grunt) {
 
// Nodejs libs.
var path = require('path');
 
// External libs.
var Mocha = require('mocha');
 
grunt.registerMultiTask('mocha', 'Run unit tests with mocha.', function() {
var filepaths = grunt.file.expandFiles(this.file.src);
grunt.file.clearRequireCache(filepaths);
var paths = filepaths.map(resolveFilepaths);
 
var options = {};
if(grunt.config.get('growl')){
options.growl = true;
}
 
var mocha_instance = new Mocha(options);
paths.map(mocha_instance.addFile.bind(mocha_instance));
mocha_instance.run(this.async());
});
 
function resolveFilepaths(filepath) {
return path.resolve(filepath);
}
 
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.