The official docs seem to imply that you need to duplicate the webpack configuration---once when used outside of the tests, and again inside of karma.conf.
// Karma configuration
module.exports = function(config) {
config.set({
webpack: {
// same webpack config used externally
},
};
However, when I started to copy/paste the working webpack config, I started to get errors. For example, ES6 code wasn't transpiled (even though babel is configured). The commons chunk plugin wouldn't work as it gave an error. The karma.conf is shown below:
const webpack = require('webpack');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
files: [
'test.webpack.js' //just load this file
],
preprocessors: {
'test.webpack.js': [ 'webpack', 'sourcemap' ] //preprocess with webpack and our sourcemap loader
},
webpack: {
module: {
loaders: [
{
test: /\/js\/.+\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: ['es2015', 'react'],
plugins: [
'transform-es2015-destructuring',
'transform-object-rest-spread'
]
}
},
],
},
resolve: {
modulesDirectories: ['node_modules'],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
filename: "commons.js",
name: "commons"
}),
new webpack.ProvidePlugin({
'Promise': 'bluebird',
})
],
devtool: 'inline-source-map'
},
};