简体   繁体   English

因果报应报告混淆

[英]karma-coverage report confuse

I am trying to use karma to test my file array.js, this file is only 36 lines, BUT, the coverage report shows "Lines ...."(see the png I upload), what's the meaning of the values, why it not match my test code? 我正在尝试使用业力测试我的文件array.js,该文件只有36行,但是覆盖率报告显示“ Lines ....”(请参阅​​我上传的png),这些值的含义是什么,为什么它与我的测试代码不匹配? Is the reason I use es6? 是我使用es6的原因吗? How can I get the correct report? 如何获得正确的报告?

The karma-config, 业力配置

const webpackConfig = {
  devtool: 'inline-source-map',
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /(node_modules|vendor)/,
        loader: 'babel-loader'
      }
    ]
  }
};

module.exports = function (config) {
  config.set({
    basePath: '../',
    plugins: [
      'karma-webpack',
      'karma-mocha',
      'karma-phantomjs-launcher',
      'karma-verbose-reporter',
      'karma-coverage'
    ],
    webpack: webpackConfig,
    webpackServer: {
      noInfo: true
    },
    frameworks: ['mocha'],
    files: [
      'test/**/*.js',
      'src/**/*.js'
    ],
    preprocessors: {
      'test/**/*.js': ['webpack'],
      'src/**/*.js': ['webpack', 'coverage']
    },
    reporters: ['verbose', 'coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    concurrency: Infinity,
    coverageReporter: {
      includeAllSources: true,
      dir: 'coverage/',
      reporters: [
        {type: "html", subdir: "html"},
        {type: 'text-summary'}
      ]
    }
  });
};

在此处输入图片说明

在此处输入图片说明

Karma executes all the files under your testing scope from your projects. 业力会从您的项目中执行您测试范围内的所有文件。 The report you are getting is for all the files in your project. 您得到的报告是针对项目中所有文件的。 Following is the explanation of each values: 以下是每个值的说明:

Statements : Has each statement in the program been executed? 语句 :程序中的每个语句是否都已执行?

Branches : Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? 分支 :是否已执行每个控制结构(例如if和case语句中)的每个分支(也称为DD路径)? For example, given an if statement, have both the true and false branches been executed? 例如,给定一个if语句,是否同时执行了true和false分支? Another way of saying this is, has every edge in the program been executed? 换句话说,程序中的每个边都执行了吗?

Functions : Has each function (or subroutine) in the program been called? 函数 :程序中的每个函数(或子例程)是否都已被调用?

Lines : has each executable line in the source file been executed? :源文件中的每个可执行行是否都已执行?

Detailed description: https://en.wikipedia.org/wiki/Code_coverage 详细说明: https : //en.wikipedia.org/wiki/Code_coverage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM