Mohammad Ashfaq
Mohammad Ashfaq

Reputation: 147

Exclude *.component.ts files from test coverage using Karma

app_component_Coverage

I want to exclude all the component.ts files from my test coverage and cover only service.ts files in any level of subfolder. I have tried number of options commented out in the below code snippet but none worked for me. Seeking help from experts to achieve my goal.

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

Upvotes: 2

Views: 3178

Answers (1)

Vova Bilyachat
Vova Bilyachat

Reputation: 19514

angular.json has section codeCoverageExclude where you can specify array of patterns to ignore

Upvotes: 2

Related Questions