使用Karma从测试覆盖中排除* .component.ts文件

问题描述 投票:0回答:1

app_component_Coverage

我想从测试覆盖范围中排除所有component.ts文件,并且只覆盖任何级别的子文件夹中的service.ts文件。我已尝试在下面的代码片段中注释掉了多个选项,但没有一个对我有用。寻求专家的帮助,以实现我的目标。

module.exports = function (config) {
  config.set({
    files: [
      // '**/*.service.ts'
    ],
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-coverage'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage/new-tts-ui'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'coverage'],
    preprocessors: {
      //'**/*.service.ts': ['coverage']
      //'**/*!(component).js' : ['coverage']  
     // '**/*.service.ts': ['coverage']
    },
    port: 9876,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true,
    //exclude: ['/**/*.component.ts','/**/*.component.js']
    //exclude: ['src/*/{*.js,!(src)/**/*.service.ts}']
    exclude: ['**/*.component.ts', '**/*.component.js']
  });
};
angular karma-jasmine
1个回答
0
投票

angular.json具有section codeCoverageExclude,您可以在其中指定要忽略的模式数组

© www.soinside.com 2019 - 2024. All rights reserved.