5

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.

user990423
  • 1,397
  • 2
  • 12
  • 32
juan garcia
  • 1,326
  • 2
  • 23
  • 56
  • Are you minifying before you run coverage? Those results look like you're running against something other than the code. It could be that source maps aren't getting all the way through. – ssube Oct 29 '15 at 19:24
  • @ssube No I am not minifying the code, regarding source maps you are right they where active as I have browserify { debug: true } in the karma config file probably it was creating source maps. I removed and it keep on working the same way, without showing the coverage on source code. – juan garcia Oct 29 '15 at 19:49

1 Answers1

1

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

juan garcia
  • 1,326
  • 2
  • 23
  • 56