karma coverage
v2.2.1
使用伊斯坦布爾生成代碼覆蓋範圍。
最簡單的方法是通過運行來安裝karma-coverage
作為devDependency
npm install karma karma-coverage --save-dev
有關配置詳細信息,請參見文檔/配置。
// 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/'
}
} ) ;
} ;
有關如何與CoffeeScript一起使用的示例,請參見示例/咖啡。有關如何與CoffeeScript和requirejs模塊加載程序一起使用的示例,請參見示例/咖啡 - requirejs(另請參見Docs/Configuration.md中的useJSExtensionForCoffeeScript
選項)。
// 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' } ,
]
}
} ) ;
} ;
使用Istanbul儀器(默認)時,您可以通過將以下內容添加到配置中禁用代碼壓實。
// karma.conf.js
module . exports = function ( config ) {
config . set ( {
coverageReporter : {
instrumenterOptions : {
istanbul : { noCompact : true }
}
}
} ) ;
} ;
有關業力的更多信息,請參見主頁。