karma-jasminegulp-karma

karma config with browserify/babel


I have a karma conf that I try to make work with babel/browserify. It looks like this:

module.exports = function(config) {
config.set({
    browsers: ['Chrome'],
    frameworks: ['jasmine'],
    plugins: [
        'karma-jasmine',
        'karma-chrome-launcher',
        'karma-babel-preprocessor',
        'karma-browserify'
    ],
    preprocessors: {
        '../src/**/*.js': ['babel', 'browserify'],
        'unit/*.spec.js': ['babel', 'browserify']
    },
    files: [
        '../src/**/*.js',
        'unit/*.spec.js'
    ],
    babelPreprocessor: {
        options: {
            presets: ['es2015'],
            sourceMap: 'inline'
        },
        filename: function (file) {
            return file.originalPath.replace(/\.js$/, '.es5.js');
        },
        sourceFileName: function (file) {
            return file.originalPath;
        }
    }
});

};

Every time I run this configuration through gulp babel preprocessor returns the following error: ERROR [preprocessor.babel]: Cannot read property 'bundleFile' of undefined


Solution

  • Try adding 'browserify' to 'frameworks', like this: frameworks: ['browserify', 'jasmine']

    I had the same error, fixed by doing this. Here's my working karma config

    module.exports = function (config) {
        config.set({
            browsers: ['Chrome'],
            singleRun: true,
            frameworks: ['browserify', 'mocha'],
            reporters: ['dots'],
            files: ['./*test.js'],
            preprocessors: {
                '*.js': ['browserify']
            },
            logLevel: 'LOG_DEBUG',
            browserify: {
                debug: true,
                transform: [ ['babelify', {presets: ['es2015', "react"]} ] ]
            }
        });
    };