Grunt task for running jasmine using istanbul for code coverage reports. Based off of grunt-jasmine-node by Omar Gonzalez (s9tpepper).
npm install grunt-jasmine-node-coverage> Runs jasmine with Istanbul code coverage





A Grunt task to run your Jasmine
feature suite using jasmine-npm
and Istanbul for code coverage reports.
The minimum supported Node.js version is 4.2.0 (LTS), and while works also in 0.10.x, no quarantees are given.
Install this grunt plugin next to your project's Gruntfile.js with:
``sh`
npm install grunt-jasmine-node-coverage --save-dev
Then add these lines to your project's Gruntfile.js configuration file:
`javascript
grunt.initConfig({
jasmine_node: {
task_name: {
options: {
forceExit: true,
coverage: {
includeAllSources: true
},
jasmine: {
spec_dir: 'tests',
spec_files: [
'*/spec.js'
]
}
},
src: ['src/*/.js']
}
}
});
grunt.loadNpmTasks('grunt-jasmine-node-coverage');
grunt.registerTask('default', 'jasmine_node');
`
Grunt tasks should be configured by following
the multi task configuration
form, thus wrapping each configuration in an object inside the jasmine_node root object.
#### options.jasmine
Type: object
Default: see below
Jasmine specific configuration. Use empty object,
{} to use the defaults that are shown below.
`js`
{
spec_dir: 'spec',
spec_files: ['*/[sS]pec/.js'],
helpers: [],
reporters: {
spec: {}
}
}
See the jasmine docs for more information on the supported configuration.
The reporters property allows the following properties:
* spec: used to configure the Jasmine spec reporter.teamcity
* set it to true in order to use Jasmine Reporters - TeamCityReporter.junitXml
* set it to a object to use Jasmine Reporters - JUnitXmlReporter. See the jasmine-reporters
documentation for additional configuration options.
If teamcity reporter is set spec reporter will be disabled and teamcity reporter will be added to the coverage reporters as well.
Example of using teamcity reporter:
`js`
{
spec_dir: 'spec',
spec_files: ['*/[sS]pec/.js'],
helpers: [],
reporters: {
teamcity: true
}
}
Example of using junitXml reporter:
`js`
{
spec_dir: 'spec',
spec_files: ['*/[sS]pec/.js'],
helpers: [],
reporters: {
junitXml: {
savePath: "reports",
consolidateAll: true
}
}
}
#### options.coverage
Type: object
Default: see below
Istanbul specific configuration. Use empty object,
{} to use the defaults that are shown below.
`js`
{
reportFile: 'coverage.json',
relativize: true,
thresholds: {
statements: 0,
branches: 0,
lines: 0,
functions: 0
},
watermarks: {
statements: [50, 80],
lines: [50, 80],
functions: [50, 80],
branches: [50, 80],
},
includeAllSources: false,
reportDir: 'coverage',
report: [
'lcov',
'text-summary'
],
collect: [ // false to disable, paths are relative to 'reportDir'
'*coverage.json'
],
excludes: []
}
Notes:
* The excludes list will automatically include '/node_modules/' internally.thresholds
* Setting the values greater than 0 will cause the task to fail if the specified threshold is not met.watermarks
* The config changes the thresholds at which the reports are displayed in red, yellow and green. It does not affect the outcome of the task.report
* Setting the list will allow different types of istanbul report to be set.
#### options.projectRoot
Type: string
Default: process.cwd()
See http://nodejs.org/api/process.html#process_process_cwd
#### options.forceExit
Type: boolean
Default: false
Exit on failure by skipping any asynchronous tasks pending.
#### options.captureExceptions
Type: boolean
Default: false
If set to true, will log all uncaught exceptions.
#### options.isVerbose
Type: boolean
Default: false
When true, istanbul will print more information when running.
Help us to squash them by submitting an issue that describes how you encountered it;
please be as specific as possible including operating system, node, grunt, andgrunt-jasmine-node-coverage versions.
`sh`
npm --versions
The spec reporter configuration has changed for v2 of this plugin. The following is an example of the change in configuration that is needed. This is not an exhaustive list: refer to the jasmine-spec-reporter for a full reference of the configuration options.
`js
// v1
reporters: {
spec: {
colors: true,
displayStacktrace: 'summary',
displaySuccessfulSpec: true
}
}
// v2
reporters: {
spec: {
colors: {
enabled: true
},
summary: {
displayStacktrace: true
},
spec: {
displaySuccessful: true
}
}
}
`
If you are updating to v1.x, you'll need to update your Gruntfile.
The following example outlines the changes needed. It assumes the following folder structure:
``
app/
├── src/
│ ├── abacus.js
│ └── calculator.js
└── test/
├── helpers.js
└── specs/
├── abacus.spec.js
└── calculator.spec.js
`js
// v0.5.0 config
{
jasmine_node: {
task_name: {
options: {
match: '.',
matchAll: true,
specFolders: ['test'],
extensions: 'js',
specNameMatcher: 'spec',
useHelpers: true
}
}
}
}
// v1.0.0 config
{
jasmine_node: {
task_name: {
options: {
jasmine: {
spec_dir: 'test',
spec_files: [
'specs/*.spec.js'
],
helpers: [
'helpers.js'
]
}
}
}
}
}
`
Please note that the junit reporter is no longer available. If you are using this reporter and wish to update to v1, please open a new issue and we'll see if we can get it added back in. Even better, submit a PR :smile:
* v2.0.1 (2017-09-20)jasmine
- Looks like the compatibility between different dependencies requires to use of version 2.5.2, which is not the latest (2.5.3)v2.0.0
* (2017-09-20)v3.3.0
- Breaking changes alert! Ensure you read the migration guide before updating from previous versions
- Updated to jasmine-spec-reporter . Older style configuration needs to be updated, see migration guide for more details.v0.10
- Removed support for Node.js v1.2.0
* (2017-04-30)0.4
- Was compatible with Grunt all the time, hence lowering the dependency requirement #60v1.1.1
* (2016-08-29)v0.4.5
- Istanbul and using data.src instead of fileSrc for compatibility #59v1.1.0
* (2016-08-23)v0.10.0
- Add Node.js support back by using var instead of const and let, #55v1.0.0
- Teamcity reporter for Jasmine, #56
* (2016-07-23)4.2.0
- Breaking changes alert! Ensure you read the migration guide before updating from previous versions
- Minimum supported Node.js version is (LTS), removed testing against 0.10jasmine-node
- Migrated from to jasmine-npm #35 #48includeAllSources
- Support istanbul coverage option #45 #50v0.5.0
- Support thresholds for passing/failing build #25
- Removed junit reporter
* (2016-05-03)lcov
- Grunt.js version 1.0 support
- ESLint configuration migration to 2.0
- Remove bin path #29
- Update license property for todays requirements
- Do not always make outputv0.4.1
* (2015-02-27)v0.4.0
- Reports should be collected from where they were written #42
* (2015-02-19)v0.3.2
- Other Grunt tasks were not ran when this failed, #40
* (2015-02-04)v0.3.1
- Fixes for failure cases and documentation, #33, #36, #37 and #38
* (2014-11-21)v0.3.0
- Installation failed
- Should fix #30
* (2014-11-09)v0.2.0
- Grunt usage as multi task
- Fixes #12 and #18
* (2014-11-03)v0.1.11
- Better Grunt API usage
- Fixes #10, #13, #14, #16, #19 and #20
* (2014-05-15)grunt.renametask
- Task name fix for use casev0.1.10
* (2014-04-07)v0.1.9
- JSHint configuration and task exit fixes
* (2014-04-02)jasmine_node.options.isVerbose
- Configuration for was not workingv0.1.8
* (2014-03-03)v0.1.7
- Add captureExceptions support and quit on exception
* (2013-12-13)v0.1.6
- Istanbul update, threshold configuration and JUNit output
* (2013-07-26)isVerbose
- Change option to verbosev0.1.5
* (2013-07-15)grunt-jasmine-node`
- Initial coverage with Istanbul release, originally forked from
Copyright (c) 2013 "jribble" Jarrod Ribble & contributors.
Based on grunt-jasmine-node.
Copyright (c) 2012 "s9tpepper" Omar Gonzalez & contributors.
Licensed under the MIT license.
[jasmine-node]: https://github.com/mhevery/jasmine-node "Integration of Jasmine Spec framework with Node.js"