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 module loader ดูตัวอย่าง/requirejs กาแฟ (และดูตัวเลือก useJSExtensionForCoffeeScript
ใน 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' } ,
]
}
} ) ;
} ;
เมื่อใช้ Istanbul Instrumenter (ค่าเริ่มต้น) คุณสามารถปิดใช้งานการบดอัดโค้ดโดยเพิ่มสิ่งต่อไปนี้ลงในการกำหนดค่าของคุณ
// karma.conf.js
module . exports = function ( config ) {
config . set ( {
coverageReporter : {
instrumenterOptions : {
istanbul : { noCompact : true }
}
}
} ) ;
} ;
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับกรรมดูหน้าแรก