Add karma-coverage to ember test

291 views Asked by At

I have found this really great ember test sample:

https://github.com/toranb/ember-testing-example

Got it to run, but I can't get the karma-coverage to work and here is the error:

ERROR [coverage]: [TypeError: Cannot set property 'covered' of undefined] TypeError: Cannot set property 'covered' of undefined

I have only updated the karma.conf.js file as well as package.json

package.json

{
  "dependencies": {
    "bower": "*",
    "karma-ember-preprocessor": "*",
    "karma-qunit": "*",
    "karma": "0.10",
    "karma-coverage": "~0.1"
  },
  "scripts": {
    "postinstall": "bower install"
  }
}

karma.conf.js

module.exports = function(karma) {
    karma.set({
        basePath: 'js',

        files: [
          "vendor/jquery/jquery.min.js",
          "vendor/handlebars/handlebars.js",
          "vendor/ember/ember.js",
          "vendor/jquery-mockjax/jquery.mockjax.js",
          "app.js",
          "tests/*.js",
          "templates/*.handlebars"
        ],

        // coverage reporter generates the coverage
        reporters: ['progress', 'coverage'],

        //logLevel: karma.LOG_ERROR,
        logLevel: karma.LOG_DEBUG,
        browsers: ['PhantomJS'],
        singleRun: true,
        autoWatch: true,

        frameworks: ["qunit"],

        plugins: [
            'karma-qunit',
            'karma-coverage',
            'karma-chrome-launcher',
            'karma-ember-preprocessor',
            'karma-phantomjs-launcher'
        ],

        preprocessors: {
            "**/*.handlebars": ['ember','coverage']
        },

        // optionally, configure the reporter
        coverageReporter: {
            type : 'html',
            dir  : 'coverage/'
        }
    });
};

Please kindly let me know what I am missing. I suspect I don't have it configured properly and this line maybe the problem.

    preprocessors: {
        "**/*.handlebars": ['ember','coverage']
    },

Any help would be greatly appreciated.

1

There are 1 answers

0
Alocus On

preprocessors: {
        "**/*.handlebars": 'ember',
        "**/*.js": 'coverage'
    },

The above allow you to create coverage report from Karma.

Note: This kind of configuration will not work for latest ES6 module