grunt-mip v1.0.8
A fork from Grunt-blanket-mocha for automatically generating coverage data and save to file.
Supports
Istanbul or JSCover or JScoverage
Install
npm i --save-dev grunt-mip
How to use
A base usage guideline can be found on grunt-blanket-mocha
Example
Step 1 . Install istanbul and grunt-mip and optional grunt-contrib-connect
npm i -g istanbul
npm i -D grunt-mip
npm i -D grunt-contrib-connect
Step 2. Instrument your js files
istanbul instrument test/index.js > test/index.cov.js
istanbul instrument test/plugin.js > test/plugin.cov.js
Step 3 . Config gruntfile
// Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
mip: {
all: {
options: {
run: false,
urls: [
'http://localhost/test/'
],
timeout: 50000,
reporter: 'Dot'
}
}
},
connect: {
all: {
options: {
port: 80,
base: '.',
}
}
}
});
// Load plugins
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-mip');
// Task to run tests
grunt.registerTask('test', ['connect', 'mip']);
Step 4. Run your test(s) then convert coverage.json to html or lcov ( or something else)
grunt test && istanbul report --root coverage lcov
As you should notice, after running this task, a coverage
folder will be created in the root folder, contains a file named coverage.json
. This file contains coverage object generated by Istanbul or JSCover or JScoverage
You should used only one in mentioned 3 tools in a test case because you don't want to mix their responses :)
If you want to change coverage tool, please delete the coverage
folder before running a new test
NOTE : This tool is designed to merge new reponses from test to test, it means :
When you run a test on http://localhost/test.html the first time, its results is saved on coverage.json file
Then you run a new test on http://localhost/another-test.html, its results will be merged to the old results and saved to coverage.json
So if you don't intend to merge their results, you should delete or backup the coverage.json
file somewhere outside the coverage
folder
Contribute
grunt-mip is released under MIT license, feel free to contribute or provide a bug fix
Here is some simple steps
Fork, then clone the repo at git@github.com:your-username/grunt-mip.git
Push to your fork and submit a pull request
Write a good commit message
Enjoy.