Karma-coverage在JS文件中检查测试覆盖率,而不是Angular 2中的TS文件

Karma-coverage checks test coverage in JS files instead of TS in Angular 2

本文关键字:文件 Angular TS 中的 覆盖率 JS 检查 测试覆盖 测试 Karma-coverage      更新时间:2023-09-26

我通过Istanbul检查TypeScript文件中的测试覆盖率。我需要通过业力覆盖来设置测试阈值。Istanbul的报告不匹配karma-coverage报告(我使用Angular-cli),因为karma-coverage检查的是JavaScript文件中的测试覆盖率,而不是TypeScript。我使用了其他插件,如karma-threshold-reporter,istanbul-threshold-checker,但结果是一样的。我该如何解决?

报告生成typeScript文件

报告生成JS文件

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', 'angular-cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-remap-istanbul'),
      require('karma-coverage'),
      require('angular-cli/plugins/karma')
    ],
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['angular-cli']
    },
    remapIstanbulReporter: {
      reports: {
        html: 'coverage',
        lcovonly: './coverage/coverage.lcov'
      }
    },
    coverageReporter: {
      dir: 'coverage/',
      reporters: [
        {type: 'text-summary'},
        {type: 'html'}
      ],
      check: {
        global: {
          statements: 70,
          branches: 70,
          functions: 70,
          lines: 50
        }
      }
    },
    angularCli: {
      config: './angular-cli.json',
      environment: 'dev'
    },
    reporters: ['progress', 'karma-remap-istanbul', 'coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

plugin: ['karma-remap-istanbul', 'karma-istanbul-threshold'],
  coverageReporter: {
        type: 'in-memory',
    },
    remapCoverageReporter: {
        'text-summary': null,
        json: './coverage/coverage-final.json',
        html: './coverage/html-ts'
    },
    istanbulThresholdReporter: {
        src: './coverage/coverage-final.json',
        reporters: ['text'], 
        thresholds: {
            global: {
                statements: 90,
                branches: 90,
                lines: 90,
                functions: 90,
            }
        },
    },