codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 222 forks source link

Karma doesn't execute Babel within Webpack3 module.exports as a function configuration #297

Closed nitinsurana closed 6 years ago

nitinsurana commented 6 years ago

Webpack version: 3.8.1

Webpack Karma version: 2.0.5

Karma version: 1.7.1

Please tell us about your environment: Windows 10

Browser: [Phantom XX | Chrome XX | Firefox XX | IE XX | Safari XX | Other XX] Chrome + Firefox + IE

Current behavior: Arrow functions are not transpiled.

Expected/desired behavior: Arrow functions should be transpiled using the babel-loader configuration in webpack.config.js

webpack.config.js

const path = require('path')
const buildCore = true

module.exports =
    // function (env) {
    // const buildCore = env && env.core || false
    // console.log("Building core : ", buildCore)
    // return
    {
        context: path.resolve('src'),
        entry: {
            app: buildCore ? './nn-core-main' : './nn-standard-main'
        },
        output: {
            path: path.resolve('dist'),
            filename: buildCore ? 'nn-core.js' : 'nn-standard.js',
            publicPath: '/dist/'
        },
        module: {
            loaders: [
                {
                    loader: "babel-loader",
                    include: [
                        path.resolve(__dirname, "src"),
                    ],
                    exclude: [
                        path.resolve(__dirname, "node_modules"),
                    ],
                    query: {
                        presets: ['es2015']
                    },
                    test: /\.jsx?$/
                },
            ]
        }
    }
// }

Above works like a charm with both webpack and karma start --auto-watch commands. But if the commented lines are uncommented accordingly, then the transpiling fails, resulting in error in IE11.

karma.conf.js

var webpackConfig = require('./webpack.config');
webpackConfig.entry = function(){return {}};

module.exports = function (config) {
    config.set({
        browsers: ['IE_no_addons', 'Chrome', 'Firefox'],
        customLaunchers: {
            IE_no_addons: {
                base: 'IE',
                flags: ['-extoff']
            }
        },
        files: [
            'src/util/zet.js',
            'src/util/zet.test.js',
            'src/util/serialization.js',
            'src/util/serialization.test.js'
        ],
        plugins: [
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-ie-launcher',
            'karma-mocha',
            'karma-chai',
            'karma-webpack'
        ],
        frameworks: ['mocha', 'chai'],
        port: 9876,
        colors: false,
        logLevel: config.LOG_DEBUG,
        autoWatch: false,
        preprocessors: {
            'src/util/zet.js': ['webpack'],
            'src/util/zet.test.js': ['webpack'],
            'src/util/serialization.js': ['webpack'],
            'src/util/serialization.test.js': ['webpack']
        },

        webpack: webpackConfig,
        webpackMiddleware: {
            noInfo: false
        },
        singleRun: false,
        concurrency: Infinity,
    });
};
nitinsurana commented 6 years ago

Possible duplicate of #243

nitinsurana commented 6 years ago

Fix is same as mentioned here