使用Karma

时间:2019-03-01 04:54:14

标签: angular karma-jasmine

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

1 个答案:

答案 0 :(得分:0)

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