Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma coverage fails to show correct results

I need some help regarding Karma with browserify coverage. I created a repo with the test I am running in here:

https://github.com/jotaoncode/web-istanbul

The results on my coverage are the following: Results of coverage

The test only runs over the function index. But as you can see the results are a 100% and marks only the first row of the file with a green color.

I have seen cases where istanbul shows correctly the coverage values, I have changed the test and the source but nothing.

I also have this karma configuration:

module.exports = function(config) {
  config.set({
    //logLevel: 'LOG_DEBUG',

    reporters: ['spec', 'coverage'],

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun : true,

    autoWatch : false,

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    port: 9876,

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: [
      'mocha',
      'browserify'
    ],

    files: [
      'src/**/*.js',
      'test/*.js'
    ],

    // list of files to exclude
    exclude: [],

    preprocessors: {
      'src/**/*.js': ['browserify', 'coverage'],
      'test/**/*.js': ['browserify']

    },

    coverageReporter: {
      reporters: [
        { type: 'html' },
        { type: 'text' },
        { type: 'lcovonly' }
      ],
      instrumenterOptions: {
        istanbul: {
          noCompact: true
        }
      },
      instrumenter: {
        'test/**/*.js': 'istanbul'
      },
      includeAllSources: true
    },


    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: [
      'PhantomJS2'
    ]

  });
};

If you ran the tests you will see that it actually works fine, but the coverage report is not correct.

like image 545
juan garcia Avatar asked Nov 09 '22 02:11

juan garcia


1 Answers

After doing some research I found this is solved as commented in this issue:

https://github.com/karma-runner/karma-coverage/issues/16

I used browserify-istanbul and now coverage report is working fine :)

enter image description here

like image 119
juan garcia Avatar answered Nov 14 '22 21:11

juan garcia