Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karma coverage fails to show correct results #190

Closed
jotaoncode opened this issue Oct 30, 2015 · 3 comments
Closed

Karma coverage fails to show correct results #190

jotaoncode opened this issue Oct 30, 2015 · 3 comments

Comments

@jotaoncode
Copy link

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.

I also created this ticket http://stackoverflow.com/questions/33422910/karma-coverage-fails-to-show-correct-results

Thank you very much for your help.

@jotaoncode
Copy link
Author

After doing some research I used this package to make a transformation for istanbul with browserify:

https://github.com/devongovett/browserify-istanbul

Now it is working as expected:

@bgjehu
Copy link

bgjehu commented Jun 21, 2016

Would you mind share how exactly you use browserify-istanbul to fix the problem, I think I have the same problem too.

@jotaoncode
Copy link
Author

jotaoncode commented Jun 21, 2016

@FullstackPug it is being a while since the last time I worked on this, you can find working solution here:
https://github.com/jotaoncode/web-istanbul-browserify

Here is the transformation in this case with istanbul-browserify

    // using browserify-istanbul as suggested by
    // https://github.com/karma-runner/karma-coverage/issues/16
    browserify: {
      debug: true,
      transform: [
        'babelify',
        istanbul({
          ignore: ['**/node_modules/**', '**/test/**']
        })
      ]
    },

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants