@wangxingkang
2017-06-20T05:49:28.000000Z
字数 3334
阅读 5285
karma test
目录:
项目地址: karma-coverage
使用istanbul生成代码覆盖率
翻译不当之处请指出
npm i -D karma karma-coverageyarn add -D karma karma-coverageStringStringString | FunctioncoverageReporter.dir选项来生成完整的输出目录路径。默认情况下,输出目录设置为./config.dir/BROWSER_NAME/,这个选项允许你自定义第二部分。你可以传递一个字符串或一个函数将调用的浏览器名称作为唯一的参数进行传递。
coverageReporter: {dir: 'coverage',subdir: '.'// 将结果输出到'./coverage/'}
coverageReporter: {dir: 'coverage',subdir: 'report'// 将结果输出到'./coverage/report/'}
coverageReporter: {dir: 'coverage',subdir: function(browser) {return browser.toLowerCase().split(/[ /-]/)[0];}// 将结果输出到: './coverage/firefox/'}
Stringcobertura, lcovonly, teamcity, text 或者 text-summary中的一个, 你可能设置file指定输出的文件Objectstatements: 90意味着最小声明覆盖率为90%。statements: -10意味着不允许超过10个未覆盖的声明。 global适用于所有的文件, each基于每个文件。文件列表或模式可以通过exclude属性将执行文件排除在外。在each的基础上,每个文件的阈值可以通过overrides属性进行覆盖
coverageReporter: {check: {global: {statements: 50,branches: 50,functions: 50,lines: 50,excludes: ['foo/bar/**/*.js']},each: {statements: 50,branches: 50,functions: 50,lines: 50,excludes: ['other/directory/**/*.js'],overrides: {'baz/component/**/*.js': {statements: 98}}}}}
Object
coverageReporter: {watermarks: {statements: [ 50, 75 ],functions: [ 50, 75 ],branches: [ 50, 75 ],lines: [ 50, 75 ]}}
Boolean
coverageReporter: {type : 'text',dir : 'coverage/',file : 'coverage.txt',includeAllSources: true}
istanbul.Store
coverageReporter: {type : 'text',dir : 'coverage/',file : 'coverage.txt',sourceStore : require('istanbul').Store.create('fslookup')}
Array of Objects
coverageReporter: {reporters:[{type: 'html', dir:'coverage/'},{type: 'teamcity'},{type: 'text-summary'}],}
ObjectBoolean这是一个不同的reporter。它不是物理的将报告写入磁盘,而是会触发一个coverage_complete事件。这个事件只能通过karma使用公共API才能被捕获。
// karma.conf.jsmodule.exports = function(config) {config.set({files: ['src/**/*.js','test/**/'],reporters: ['progress', 'coverage'],preprocessors: {'src/**/*.js': ['coverage']},coverageReporter: {type: 'html',dir: 'coverage/'}})}
// karma.conf.jsmodule.exports = function(config) {config.set({files: ['src/**/*.js','test/**/*.js'],reporters: ['progress', 'coverage'],preprocessors: {'src/**/*.js': ['coverage']},coverageReporter: {// specify a common output directorydir: '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' },]}});};