Files
galaxy/client/karma/webpack.config.unittest.js
T

54 lines
1.5 KiB
JavaScript

/**
* Unit tests should not require css or images, so replace all those things with
* the ignore-loader for speedier testing.
*/
const merge = require("webpack-merge");
const baseConfig = require("../webpack.config");
module.exports = (env, argv) => {
const wpConfig = baseConfig(env, argv);
wpConfig.mode = "development";
wpConfig.entry = () => ({});
// Don't need any assets for unit testing
let ignoreAssetLoaders = {
rules:[
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
loader: "ignore-loader"
},
{
test: /\.css$/,
loader: "ignore-loader"
},
{
test: /\.scss$/,
loader: "ignore-loader"
}
]
};
wpConfig.module = merge.smart(wpConfig.module, ignoreAssetLoaders);
// Using babel-plugin-rewire to handle dependency mocking since webpack 4
// exports immutable bindings for ES modules but we still need a way to
// overwrite dependencies during unit-testing.
//
// Additionally, set exclude for babel-loader to completely ignore *all*
// node-modules, without our exceptions to support IE as in parent webpack
// config.
wpConfig.module.rules = wpConfig.module.rules.map(rule => {
if (rule.loader == "babel-loader") {
rule.exclude = [/(node_modules\/)/]
rule.options.plugins.push("rewire");
}
return rule;
});
return wpConfig;
}