grunt-simple-nyc
Version:
A grunt wrapper for nyc
85 lines (65 loc) • 3.17 kB
Markdown
[](https://travis-ci.org/tandrewnichols/grunt-simple-nyc) [](https://npmjs.org/package/grunt-simple-nyc) [](https://npmjs.org/package/grunt-simple-nyc) [](https://codeclimate.com/github/tandrewnichols/grunt-simple-nyc/maintainability) [](https://codeclimate.com/github/tandrewnichols/grunt-simple-nyc/test_coverage) [](https://david-dm.org/tandrewnichols/grunt-simple-nyc)
# grunt-simple-nyc
A grunt wrapper for nyc
## Getting Started
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
```bash
npm install grunt-simple-nyc --save-dev
```
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
```javascript
grunt.loadNpmTasks('grunt-simple-nyc');
```
Alternatively, install [task-master](http://github.com/tandrewnichols/task-master) and let it manage this for you.
## The "nyc" task
### Overview
In your project's Gruntfile, add a section named `nyc` to the data object passed into `grunt.initConfig()`. This task is a [simple-cli](https://github.com/tandrewnichols/simple-cli) task, so it can be configured in accordance with the examples there. A simple example is:
```js
grunt.initConfig({
nyc: {
cover: {
options: {
cwd: 'server',
include: ['lib/**', 'routes/**'],
exclude: '*.test.*',
reporter: ['lcov', 'text-summary'],
reportDir: 'server/coverage'
all: true
},
cmd: false,
args: ['grunt', 'mocha:unit']
},
report: {
options: {
reporter: 'text-summary'
}
}
}
});
// grunt nyc:cover will run
// nyc --cwd server --include lib/** --include routes/** --exclude *.test.*
// --reporter--reporter--reporter--reporter lcov --reporter text-summary
// --report-dir server/coverage --all grunt mocha:unit
//
// whereas grunt nyc:report will run
// nyc report --reporter text-summary
```
If you need to pass arguments to the process that runs your tests (`grunt mocha:unit` in the example above), you need to add them to `args` _after_ the command name (alternatively, you can add them in `rawArgs`). E.g.
```js
grunt.initConfig({
cover: {
cmd: false,
args: ['grunt', 'mocha:unit', '--require', 'should']
}
});
// or
grunt.initConfig({
cover: {
cmd: false,
args: ['grunt', 'mocha:unit'],
rawArgs: ['--require', 'should']
}
});
```
## Contributing
Please see [the contribution guidelines](CONTRIBUTING.md).