-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathwebpack-test.config.js
More file actions
78 lines (73 loc) · 2.43 KB
/
webpack-test.config.js
File metadata and controls
78 lines (73 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var webpack = require('webpack');
var webpack_config = require('./webpack.base.config');
var path = require('path');
var test_case = process.env.GEOJS_TEST_CASE || 'tests/all.js';
var config = {
mode: 'development',
performance: { hints: false },
cache: {
type: 'filesystem',
cacheDirectory: path.resolve(__dirname, '_build', '.webpack-test-cache')
},
devtool: 'inline-source-map',
context: path.join(__dirname),
entry: {
'test-bundle': './' + test_case
},
output: {
path: path.resolve(__dirname, '_build', 'test-bundle'),
filename: '[name].js',
publicPath: '/test-bundle/'
},
module: {
rules: webpack_config.module.rules.map(function (rule, index) {
if (index === 0) {
// Add compact: false to the first rule's babel-loader options
var newRule = Object.assign({}, rule);
newRule.use = rule.use.map(function (u) {
if (typeof u === 'object' && u.loader === 'babel-loader') {
return Object.assign({}, u, {
options: Object.assign({}, u.options, { compact: false })
});
}
return u;
});
return newRule;
}
return rule;
})
},
resolve: webpack_config.resolve,
plugins: webpack_config.plugins.slice()
};
// This is needed as of nise 6.1.3
config.plugins.push(new webpack.ProvidePlugin({
process: 'process/browser'
}));
/* If coverage is requested, add istanbul instrumentation */
if (process.env.GEOJS_COVERAGE === 'true') {
// Add coverage-istanbul-loader to the first rule (src files)
config.module.rules[0] = Object.assign({}, config.module.rules[0]);
config.module.rules[0].use = config.module.rules[0].use.concat([{
loader: '@jsdevtools/coverage-istanbul-loader',
options: { esModules: true }
}]);
}
/* If webpack of a test fails, stop rather than run some tests */
class WarningsToErrorsWebpackPlugin {
apply(compiler) {
compiler.hooks.done.tap('WarningsToErrorsWebpackPlugin', function (stats) {
if (stats.compilation.warnings.length) {
stats.compilation.warnings.forEach(function (warning) {
console.log(warning.message || warning);
});
// Make the build fail
stats.compilation.errors = stats.compilation.errors.concat(
stats.compilation.warnings.map(function (w) { return new Error(w.message || w); })
);
}
});
}
}
config.plugins.push(new WarningsToErrorsWebpackPlugin());
module.exports = config;