karma-coverage icon indicating copy to clipboard operation
karma-coverage copied to clipboard

Karma coverage does not show any data when using webpack + ES6

Open gotofritz opened this issue 9 years ago • 19 comments

Hi

My config

module.exports = function(config) {
  config.set({
    browsers: ["ChromeCanary"],
    coverageReporter: {
      type: "html",
      dir : "./docs/js-coverage"
    },
    files: [{
        pattern: "test.bundle.js",
        watched: false
      }],
    frameworks: ["jasmine"],
    preprocessors: {
        "src/main/webapp/**/*.js": "coverage",
        "test.bundle.js": ["webpack"]
    },
    reporters: ["coverage", "dots"],
    singleRun: false,
    webpack: {
        module: {
            loaders: [{
                  test: /\.js/,
                  exclude: /node_modules/,
                  loader: "babel-loader?cacheDirectory&optional[]=runtime"
                }]
        },
        watch: true
    },
    webpackServer: {
        noInfo: true
    }
  });
};

test.bundle.js

var context = require.context("./src/main/webapp", true, /.+\.test\.js$/);
context.keys().forEach(context);

Tests run fine, HTML report is generated, but it contains no files in the list.

Thanks.

gotofritz avatar Sep 02 '15 10:09 gotofritz

+1

naomiaro avatar Nov 28 '15 04:11 naomiaro

I have the same problem. I thought I did something wrong, but whatever I try, it just comes up with zero files in the generated HTML. Is this a bug?

Edit: I fixed this by adding isparta preloaders to the webpack.module:

preLoaders: [
  { test: /\.js|jsx$/, exclude: /(src|node_modules)/, loaders: ['babel'] },
  { test: /\.js|jsx$/, include: /(src)/, loaders: ['isparta'] }
],

marcelpanse avatar Dec 15 '15 16:12 marcelpanse

+1

nlitwin avatar Feb 04 '16 20:02 nlitwin

+1

mrblackus avatar Feb 17 '16 15:02 mrblackus

+1

egoroof avatar Feb 23 '16 11:02 egoroof

+1

jingzhou123 avatar Feb 29 '16 05:02 jingzhou123

+1

djdawson3 avatar Jun 10 '16 00:06 djdawson3

+1

kaskazurek avatar Aug 30 '16 07:08 kaskazurek

+1

coot avatar Oct 14 '16 14:10 coot

+1

AlexandrAnash avatar Oct 18 '16 11:10 AlexandrAnash

+1

Clebiez avatar Jan 05 '17 09:01 Clebiez

+1

teone avatar Jan 09 '17 23:01 teone

Hi, I found an alternative. Use Isparta loader in your karma conf file.

preLoaders: [
   {
        test: /^((?!spec).)*\.js$/,
        include: path.resolve('src/'),
        loader: 'isparta'
   }
],

Don't forget to require karma-coverage and add it in preprocessors.

I hope it will help you.

Clebiez avatar Jan 11 '17 16:01 Clebiez

should work with angular-cli +1

raDiesle avatar May 11 '17 08:05 raDiesle

Same issue here +1

doomleika avatar Sep 06 '17 02:09 doomleika

+1

fbvilela avatar Nov 09 '17 04:11 fbvilela

To get this to work you need the sourcemaps from the es6 transpile to be read by the webpack sourcemap constructor and applied so that the sourcemap seen by the istanbul remapper refer back to the original sources. IMO that's a lot of work, better to just run the tests on the unbundled code for the purpose of coverage.

johnjbarton avatar Nov 09 '17 16:11 johnjbarton

coverage sourcemap not work. only index.js. image image

no filelists, can you help me?

songguangyu avatar Nov 26 '17 08:11 songguangyu

Was not able to get coverage information with webpack (2) and karma-coverage. Had to use both "istanbul-instrumenter-loader" as a webpack file loader for test run and "karma-coverage-istanbul-reporter" as coverage reporter and after couple of days of struggles it worked.

florin05 avatar Nov 30 '17 19:11 florin05