karma-runner / karma-coverage

A Karma plugin. Generate code coverage.
MIT License
770 stars 247 forks source link

Karma coverage empty with a simple sample #340

Open njleonzhang opened 7 years ago

njleonzhang commented 7 years ago

sample project: https://github.com/njleonzhang/karma-study/tree/master/karma-2

Here is the config file:

// Karma configuration

module.exports = function(config) {
  config.set({
    // plugins
    plugins: [
      'karma-phantomjs-launcher',
      'karma-coverage'
    ],

    // list of files / patterns to load in the browser
    files: [
      'src/index.js',
      'test/index.js'
    ],

    reporters: ['coverage'],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'src/index.js': ['coverage']
    },

    coverageReporter: {
      dir: './coverage',
      // includeAllSources: true,
      reporters: [
        { type: 'lcov', subdir: '.' },
        { type: 'text-summary' }
      ]
    },

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

result:

=============================== Coverage summary===============================
Statements   : 100% ( 0/0 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 0/0 )
================================================================================

version: "karma": "^1.7.1", "karma-coverage": "^1.1.1",

nimeshnikum commented 7 years ago

I am too facing the same problem.

richistron commented 6 years ago

same problem here

mxchange commented 6 years ago

Same problem here since webpack 4

njleonzhang commented 6 years ago

just add babel-plugin-istanbul to my project in this commit https://github.com/njleonzhang/vue-data-tables/commit/51aab5a53ef5b36d5d4385b73e47e196058d77ec, and the coverage works now.

vkiperman commented 6 years ago

I am also dealing with that.

pfzhengd commented 5 years ago

I am also dealing with that and I added babel-plugin-istanbul.

pfzhengd commented 5 years ago

I am also dealing with that and I added babel-plugin-istanbul. My problem is solved because the 'include' path in 'babel-loader' is incorrect.

JimLynchCodes commented 4 years ago

I am also having this issue. Would be great if the karma docs described how to actually add coverage reports... 😥

JimLynchCodes commented 4 years ago

bump! 🙃

johnjbarton commented 4 years ago

Try the debug logging, maybe that gives a hint.

JimLynchCodes commented 4 years ago

Thanks @johnjbarton!

Unfortunately, the debug logging didn't give me any hints. 😥

For anyone else frustrated by these issues, I have started another thread about it here: https://github.com/karma-runner/karma/issues/3445