Skip to content

Instantly share code, notes, and snippets.

@xseignard
Created April 23, 2013 18:04
Show Gist options
  • Save xseignard/5445919 to your computer and use it in GitHub Desktop.
Save xseignard/5445919 to your computer and use it in GitHub Desktop.
grunt with mocha and istanbul : it feels like maven
module.exports = function(grunt) {
// set required env vars
(function() {
process.env.XUNIT_FILE = 'reports/xunit.xml';
process.env.ISTANBUL_REPORTERS = 'lcovonly';
}());
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta: {
reports: 'reports'
},
clean: ['<%= meta.reports %>'],
jshint: {
all: ['src/**/*.js', 'test/**/*.js', 'Gruntfile.js'],
options: {
jshintrc: '.jshintrc',
// TODO: soon, real soon! reporters: 'checkstyle'
}
},
simplemocha: {
options: {
reporter: 'mocha-istanbul'
},
all: { src: ['test/**/*.js'] }
},
instrument : {
files : 'src/**/*.js',
options : {
basePath : 'reports/'
}
},
shell: {
replaceSrc: {
command: 'mv src src-orig;mv reports/src src',
options: {
stdout: true
}
},
moveReport: {
command: 'mv lcov.info reports/locv.info',
options: {
stdout: true
}
},
resetSrc: {
command: 'rm -rf src;mv src-orig src',
options: {
stdout: true
}
}
}
});
// task loading
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-istanbul');
grunt.loadNpmTasks('grunt-shell');
// coverage
grunt.registerTask('coverage', ['clean', 'instrument', 'shell:replaceSrc', 'simplemocha', 'shell:moveReport', 'shell:resetSrc']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment