karma coverage
v2.2.1
Genere la cobertura de código usando Estambul.
La forma más fácil es instalar karma-coverage
como una devDependency
, ejecutando
npm install karma karma-coverage --save-dev
Para obtener detalles de configuración, consulte Docios/Configuración.
// karma.conf.js
module . exports = function ( config ) {
config . set ( {
files : [
'src/**/*.js' ,
'test/**/*.js'
] ,
// coverage reporter generates the coverage
reporters : [ 'progress' , 'coverage' ] ,
preprocessors : {
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'src/**/*.js' : [ 'coverage' ]
} ,
// optionally, configure the reporter
coverageReporter : {
type : 'html' ,
dir : 'coverage/'
}
} ) ;
} ;
Para obtener un ejemplo sobre cómo usar con Coffeescript, consulte ejemplos/café. Para obtener un ejemplo de cómo usar con CoffeeScript y el cargador del módulo RequestJS, consulte Ejemplos/Coffee-Requirejs (y también vea la opción useJSExtensionForCoffeeScript
en Docs/Configuration.md).
// karma.conf.js
module . exports = function ( config ) {
config . set ( {
files : [
'src/**/*.js' ,
'test/**/*.js'
] ,
reporters : [ 'progress' , 'coverage' ] ,
preprocessors : {
'src/**/*.js' : [ 'coverage' ]
} ,
coverageReporter : {
// specify a common output directory
dir : 'build/reports/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' } ,
]
}
} ) ;
} ;
Al usar el Instrumento Istanbul (predeterminado), puede deshabilitar el código de compactación agregando lo siguiente a su configuración.
// karma.conf.js
module . exports = function ( config ) {
config . set ( {
coverageReporter : {
instrumenterOptions : {
istanbul : { noCompact : true }
}
}
} ) ;
} ;
Para obtener más información sobre el karma, consulte la página de inicio.