karma coverage
v2.2.1
Menghasilkan cakupan kode menggunakan Istanbul.
Cara termudah adalah dengan menginstal karma-coverage
sebagai devDependency
, dengan berjalan
npm install karma karma-coverage --save-dev
Untuk detail konfigurasi, lihat dokumen/konfigurasi.
// 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/'
}
} ) ;
} ;
Sebagai contoh tentang cara menggunakan dengan kopi, lihat contoh/kopi. Untuk contoh cara menggunakan dengan CoffeeScript dan Module Loader Persetujuan, lihat Contoh/Coffee-Requirejs (dan juga lihat opsi useJSExtensionForCoffeeScript
di 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' } ,
]
}
} ) ;
} ;
Saat menggunakan Istanbul Instrumenter (default), Anda dapat menonaktifkan pemadatan kode dengan menambahkan yang berikut ke konfigurasi Anda.
// karma.conf.js
module . exports = function ( config ) {
config . set ( {
coverageReporter : {
instrumenterOptions : {
istanbul : { noCompact : true }
}
}
} ) ;
} ;
Untuk informasi lebih lanjut tentang Karma, lihat beranda.