【问题标题】:karma-coverage report confuse业力覆盖率报告混淆
【发布时间】:2017-12-19 11:23:30
【问题描述】:

我正在尝试使用 karma 来测试我的文件 array.js,这个文件只有 36 行,但是,覆盖率报告显示“Lines ....”(见我上传的 png),这是什么意思值,为什么它与我的测试代码不匹配?是我使用es6的原因吗? 我怎样才能得到正确的报告?

业力配置,

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'}
      ]
    }
  });
};

【问题讨论】:

    标签: javascript unit-testing karma-runner


    【解决方案1】:

    Karma 从您的项目中执行您测试范围内的所有文件。您获得的报告适用于您项目中的所有文件。以下是各个值的解释:

    语句:程序中的每条语句都执行了吗?

    分支:是否每个控制结构(例如 if 和 case 语句)的每个分支(也称为 DD 路径)都已执行?例如,给定一个 if 语句,是否同时执行了 true 和 false 分支?另一种说法是,程序中的每一条边都被执行了吗?

    函数:程序中的每个函数(或子程序)都被调用了吗?

    行数:源文件中的每个可执行行都被执行了吗?

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

    【讨论】:

      猜你喜欢
      • 2016-03-21
      • 2021-10-19
      • 2022-07-27
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      • 2015-05-22
      • 2016-12-21
      • 2015-10-06
      相关资源
      最近更新 更多