$ cnpm 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:
npm install grunt-jasmine-node-coverage --save-dev
Then add these lines to your project's Gruntfile.js configuration file:
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.
Type: object
Default: see below
Jasmine specific configuration. Use empty object,
{} to use the defaults that are shown below.
{
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:
{
spec_dir: 'spec',
spec_files: ['**/*[sS]pec/.js'],
helpers: [],
reporters: {
teamcity: true
}
}
Example of using junitXml reporter:
{
spec_dir: 'spec',
spec_files: ['**/*[sS]pec/.js'],
helpers: [],
reporters: {
junitXml: {
savePath: "reports",
consolidateAll: true
}
}
}
Type: object
Default: see below
Istanbul specific configuration. Use empty object,
{} to use the defaults that are shown below.
{
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:
excludes list will automatically include '**/node_modules/**' internally.thresholds values greater than 0 will cause the task to fail if the specified threshold is not met.watermarks 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 list will allow different types of istanbul report to be set.Type: string
Default: process.cwd()
See http://nodejs.org/api/process.html#process_process_cwd
Type: boolean
Default: false
Exit on failure by skipping any asynchronous tasks pending.
Type: boolean
Default: false
If set to true, will log all uncaught exceptions.
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, and
grunt-jasmine-node-coverage versions.
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.
// 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
// 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 of version 2.5.2, which is not the latest (2.5.3)v2.0.0 (2017-09-20)
v3.3.0. Older style configuration needs to be updated, see migration guide for more details.v0.10v1.2.0 (2017-04-30)
0.4 all the time, hence lowering the dependency requirement #60v1.1.1 (2016-08-29)
v0.4.5 and using data.src instead of fileSrc for compatibility #59v1.1.0 (2016-08-23)
v0.10.0 support back by using var instead of const and let, #55v1.0.0 (2016-07-23)
4.2.0 (LTS), removed testing against 0.10jasmine-node to jasmine-npm #35 #48includeAllSources istanbul coverage option #45 #50v0.5.0 (2016-05-03)
lcov outputv0.4.1 (2015-02-27)
v0.4.0 (2015-02-19)
v0.3.2 (2015-02-04)
v0.3.1 (2014-11-21)
v0.3.0 (2014-11-09)
v0.2.0 (2014-11-03)
v0.1.11 (2014-05-15)
grunt.renametask use casev0.1.10 (2014-04-07)
v0.1.9 (2014-04-02)
jasmine_node.options.isVerbose was not workingv0.1.8 (2014-03-03)
v0.1.7 (2013-12-13)
v0.1.6 (2013-07-26)
isVerbose option to verbosev0.1.5 (2013-07-15)
grunt-jasmine-nodeCopyright (c) 2013 "jribble" Jarrod Ribble & contributors. Based on grunt-jasmine-node.
Copyright (c) 2012 "s9tpepper" Omar Gonzalez & contributors. Licensed under the MIT license.
Copyright 2013 - present © cnpmjs.org | Home |