Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29129

How to add coverage report to karma with new babel-plugin-__coverage__

I just found out about the new babel plugin called babel-plugin-coverage. I've tried it but without success.

The problem I have is that no coverage data is written to disk (not even the directory is created).

So, my first question: Given the following babel configuration which is placed inside .babelrc

{
    "env": {
       "test": {
           "plugins": [ "__coverage__" ]
      }
   }
}

How do I target/define this test environment in my karma.config ?

Is it also valid to write at the top of karma.conf.js the following:

require("babel-plugin-__coverage__");

Now, here is a snippet of my karma.conf.js

require("babel-plugin-__coverage__");
module.exports = function (config) {
    config.set({
        basePath: '../app/',
        frameworks: ['browserify', 'jasmine-jquery', 'jasmine'],
        files: [ .... ],
        preprocessors: {
           ....
           '../test/unit/app.js': ['browserify'],
           'components/common/module.js': ['browserify'],
           'components/services/module.js': ['browserify'],
           '../test/unit/components/**/*.spec.js': ['browserify'],
           'components/**/*.spec.js': ['browserify'],
           'components/**/*.fixtures.js': ['browserify']
        },
        browserify : {
           transform : ['babelify', 'stringify'],
           debug: true,
           paths: [ ... ]
        },
        reporters: [
            'progress',
            'coverage'
        ],

       coverageReporter: {
           type: 'html',
           dir: '../target/coverage'
       },
       ...

Any help would be appreciated ?

Upvotes: 0

Views: 138

Answers (1)

WayneC
WayneC

Reputation: 5740

To set the environment to test add

process.env.NODE_ENV = 'test';

to the top of karma.conf.js

you don't need the require("babel-plugin-__coverage__") call

Upvotes: 1

Related Questions