karma-coverage
Generate code coverage using Istanbul.
Installation
The easiest way is to install karma-coverage
as a devDependency
,
by running
npm install karma karma-coverage --save-dev
Configuration
For configuration details see docs/configuration.
Examples
Basic
module.exports = function(config) {
config.set({
files: [
'src/**/*.js',
'test/**/*.js'
],
reporters: ['progress', 'coverage'],
preprocessors: {
'src/**/*.js': ['coverage']
},
coverageReporter: {
type : 'html',
dir : 'coverage/'
}
});
};
CoffeeScript
For an example on how to use with CoffeeScript
see examples/coffee. For an example of how to use with
CoffeeScript and the RequireJS module loader, see
examples/coffee-requirejs (and also see
the useJSExtensionForCoffeeScript
option in
docs/configuration.md).
Advanced, multiple reporters
module.exports = function(config) {
config.set({
files: [
'src/**/*.js',
'test/**/*.js'
],
reporters: ['progress', 'coverage'],
preprocessors: {
'src/**/*.js': ['coverage']
},
coverageReporter: {
dir: 'build/reports/coverage',
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' },
]
}
});
};
FAQ
Don't minify instrumenter output
When using the istanbul instrumenter (default), you can disable code compaction by adding the following to your configuration.
module.exports = function(config) {
config.set({
coverageReporter: {
instrumenterOptions: {
istanbul: { noCompact: true }
}
}
});
};
For more information on Karma see the homepage.