Search code examples
node.jsunit-testingwebstormecmascript-6karma-mocha

Webstorm 10 + Karma + ES6 - Unit testing


First let me start by mentioning that all my unit tests works perfectly using gulp.

I'm trying to run my unit tests via Webstorm (v10) the problem is that the the karam.conf.js is pointing to the compiled js files, and not to the original files... is there a way to tell Webstorm to compile the files first before it runs the tests?

here is my karam.conf.js: (please note that the pre-compiled files are at the same location but looks like *.spec.js)

module.exports = function (config) {
    'use strict';
    config.set({

        basePath: '',

        frameworks: ['mocha'],

        files: [
            'bundledTests/test/**/*.spec.bundle.js'
        ],

        // reporters configuration 
        reporters: ['mocha'],

        plugins: [
          'karma-mocha-reporter',
          'karma-mocha',
          'karma-phantomjs-launcher',
          'karma-chrome-launcher'
        ],

        //reporters: ['progress'],

        port: 9876,
        colors: true,
        autoWatch: true,
        singleRun: false,
        usePolling: true,
        atomic_save: false,

        // level of logging
        // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        logLevel: config.LOG_INFO,



        browsers: ["Chrome"] //'PhantomJS',

    });
};

Any help would be much appreciated!


Solution

  • Use karma-babel-preprocessor.

    Add preprocessors section into your karma.conf.js:

    preprocessors: {
      'src/**/*.js': ['babel'],
      'test/**/*.js': ['babel']
    },
    

    Mark paths which need to be processed before running in tests.