简体   繁体   中英

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM