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
Use babel-istanbul-plugin for source instrumentation. Don´t forget exclude
test files from instrumentation using exclude/include
rules
npm install karma-istanbuljs-reporter --save-dev
Add karma.conf.js
file to project.
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
reporters: [
{ type: 'text' }
]
},
...
});
}
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
dir: 'cover/', // changed default output dir from 'coverage/'
reporters: [
// reporters not supporting the `file` property
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' },
// reporters supporting the `file` property, use `subdir` to directly
// output them in the `dir` directory
{ 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' }
]
},
...
});
}
Supported reporters istanbul-reports
karma-istanbuljs-reporter
can fail tests if coverage falls below a threshold.
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
checkCoverage: true
},
...
});
}
{
lines: 90,
functions: 0,
statements: 0,
branches: 0
}
module.exports = function(config) {
config.set({
...
reporters: ['progress', 'istanbul'],
istanbulReporter: {
checkCoverage: {
lines: 95,
functions: 95,
statements: 95,
branches: 95
}
},
...
- bySabi Files <> @bySabi
- Josh Baldwin <> @joshbaldwin
- Documentation improvement
- Feel free to send any PR