karma-istanbuljs-reporter
a Karma plugin for generate code coverage using new, v1, Istanbul API
This reporter try to mimic behaviours and settings of nyc tool more than karma-coverage
Instrumentation
Use babel-istanbul-plugin for source instrumentation. Don´t forget exclude
test files from instrumentation using exclude/include
rules
Installation
npm
npm install karma-istanbuljs-reporter --save-dev
Usage
Add karma.conf.js
file to project.
Examples of karma.conf.js
Basic
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
reporters: [
{ type: 'text' }
]
},
...
});
}
Multiple reporters
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
dir: 'cover/',
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' },
{ type: 'cobertura', subdir: '.', file: 'cobertura.txt' },
{ type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' },
{ type: 'teamcity', subdir: '.', file: 'teamcity.txt' },
{ type: 'text', subdir: '.', file: 'text.txt' },
{ type: 'text-summary', subdir: '.', file: 'text-summary.txt' }
]
},
...
});
}
Checking coverage
karma-istanbuljs-reporter
can fail tests if coverage falls below a threshold.
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
checkCoverage: true
},
...
});
}
Default thresholds
{
lines: 90,
functions: 0,
statements: 0,
branches: 0
}
Checking coverage with custom thresholds
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
checkCoverage: {
lines: 95,
functions: 95,
statements: 95,
branches: 95
}
},
...
WIP: 'Include all sources' feature
issues#1
Example
Contributing
- Documentation improvement
- Feel free to send any PR
License
ISC