A fork from [Grunt-blanket-mocha](https://github.com/GruntBlanketMocha/grunt-blanket-mocha) for automatically generating coverage data and save to file.

## Supports

[Istanbul](https://github.com/gotwarlost/istanbul) or [JSCover](https://github.com/tntim96/JSCover) or [JScoverage](https://www.npmjs.com/package/jscoverage)

## Install

```bash
npm i --save-dev grunt-mip
```

## How to use

A base usage guideline can be found on [grunt-blanket-mocha](https://github.com/GruntBlanketMocha/grunt-blanket-mocha#readme)

## Example

**Step 1 . Install istanbul and grunt-mip and optional grunt-contrib-connect**

```bash
npm i -g istanbul
npm i -D grunt-mip
npm i -D grunt-contrib-connect
```

**Step 2. Instrument your js files**

```bash
istanbul instrument test/index.js > test/index.cov.js
istanbul instrument test/plugin.js > test/plugin.cov.js
```

**Step 3 . Config gruntfile**

```javascript
// 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)**


```bash
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](https://github.com/gotwarlost/istanbul) or [JSCover](https://github.com/tntim96/JSCover) or [JScoverage](https://www.npmjs.com/package/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 :

```bash
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

1. Fork, then clone the repo at git@github.com:your-username/grunt-mip.git

2. Push to your fork and submit a [pull request](https://github.com/zudd/grunt-mip/compare/)

3. Write a good commit message


Enjoy.