Skip to content

Instantly share code, notes, and snippets.

@bernos
Forked from johnkpaul/gist:2361303
Created June 16, 2012 04:44
Show Gist options
  • Save bernos/2939953 to your computer and use it in GitHub Desktop.
Save bernos/2939953 to your computer and use it in GitHub Desktop.
gruntjs Mocha task
module.exports = function(grunt) {
grunt.initConfig({
mocha : {
all : {
src : 'test/**/*.js', // path to test.js files
options : {
globals : ['piewpiew'],
ui : 'tdd',
reporter : 'spec'
}
}
}
});
grunt.registerTask('default', 'mocha');
grunt.loadTasks('tasks');
}
/*
* 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 = this.data.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);
}
};
@msaglietto
Copy link

thanks i was looking for something like this... it would be nice if you add it to grunt-contrib or a self npm package ...

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