0

My coverage report includes the imports like :

 node_modules\angular-mocks\             |    26.09 |    11.58 |     19.7 |    27.23 |                |
  angular-mocks.js                       |    26.09 |    11.58 |     19.7 |    27.23 |... 6,3107,3109 |
 node_modules\angular-resource\          |     7.77 |        0 |     3.13 |     8.11 |                |
  angular-resource.js                    |     6.81 |        0 |     3.13 |      7.1 |... 836,839,842 |
  index.js                               |      100 |      100 |      100 |      100 |                |
 node_modules\angular-scroll\            |     4.98 |     1.81 |        0 |     5.14 |                |
  angular-scroll.js                      |     4.09 |     1.81 |        0 |     4.22 |... 620,621,624 |
  index.js                               |      100 |      100 |      100 |      100 |                |
 node_modules\angular-ui-router\release\ |    11.21 |     0.41 |     0.35 |    12.77 |                |
  angular-ui-router.js                   |    11.21 |     0.41 |     0.35 |    12.77 |... 0,4602,4603 |
 node_modules\angular\                   |    17.58 |     5.43 |     13.7 |     17.9 |                |
  angular.js                             |    17.56 |     5.43 |     13.7 |    17.88 |... 30418,30423 |
  index.js                               |      100 |      100 |      100 |      100 |                |
 node_modules\webpack\buildin\           |      100 |       50 |       50 |      100 |                |
  module.js

My Karma Config is :

// jshint ignore: start
// jscs:disable

// Global karma config
'use strict';


// START_CONFIT_GENERATED_CONTENT
// We want to re-use the loaders from the dev.webpack.config
var webpackConfig = require('./../webpack/webpack.test.config.js');
var preprocessorList = ['webpack', 'sourcemap'];

var karmaConfig = {  
  plugins: [
    'karma-phantomjs-launcher',
    'karma-jasmine',
    'karma-junit-reporter',
    'karma-coverage',
    'karma-chrome-launcher',
    'karma-webpack',
    'karma-sourcemap-loader',
    'karma-threshold-reporter',
    'karma-htmlfile-reporter',
    'karma-babel-preprocessor'
  ],    
  files: [
    'node_modules/jquery/dist/jquery.js',
    'node_modules/phantomjs-polyfill/bind-polyfill.js',
    'config/testUnit/test.files.js'
  ],    
  preprocessors: {        
    'config/testUnit/test.files.js': preprocessorList,
    'src/**/!*spec.js': ['coverage'],
     'src/app/**/*.js': ['coverage'],
  },   
  reporters: ['progress', 'junit', 'coverage', 'threshold','html'],    
  coverageReporter: {
    dir: 'reports/coverage',
    includeAllSources:false,
    reporters: [
      { type: 'cobertura', subdir: 'cobertura' },
      { type: 'lcovonly', subdir: 'lcov' },
      { type: 'html', subdir: 'html' },
      { type: 'json', subdir: 'json' },
      { type: 'text' }
    ]
  },    
  junitReporter: {
    outputDir: 'reports/unit/',
    outputFile: 'test-results.xml'
  },
  htmlReporter: {
    outputFile: 'reports/unit/Test-Results.html'
  },     
  webpack: {
    // Load the source code using test.files.js
    entry: {},    
    module: {
      preLoaders: webpackConfig.module.preLoaders,
       postLoaders: [ { //delays coverage til after tests are run, fixing transpiled source coverage error
            test: /\.js$/,
            exclude: /(test|node_modules|bower_components)\//,
            loader: 'istanbul-instrumenter' } ],
      loaders: webpackConfig.module.loaders
    },
    plugins: webpackConfig.plugins.concat([new DefinePlugin({
      __karmaTestSpec: testFilesRegEx
    })]),
    resolve: webpackConfig.resolve,
    devtool: 'inline-source-map'      // Changed to allow the sourcemap loader to work: https://github.com/webpack/karma-webpack
  },    
  webpackServer: {
    noInfo: true
  },    
  singleRun: false,
  colors: true
};    
module.exports = karmaConfig;

I have tried exclude: /(test|node_modules|bower_components)// but it does not help.

How to exclude these files from the coverage report?

1 Answers1

0

We can exclude folder/file using '!' notation. Example

 preprocessors: {
    'framework/**/!(node_modules|test|bower_components)/*.js': 'coverage'     
 }

For details refer - https://karma-runner.github.io/0.12/config/configuration-file.html

khushboo29
  • 906
  • 6
  • 16