-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathtest.ts
88 lines (80 loc) · 2.17 KB
/
test.ts
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
79
80
81
82
83
84
85
86
87
88
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as glob from 'glob';
import * as path from 'path';
import * as webpack from 'webpack';
import { WebpackConfigOptions, WebpackTestOptions } from '../build-options';
import { getSourceMapDevTool, isPolyfillsEntry } from './utils';
export function getTestConfig(
wco: WebpackConfigOptions<WebpackTestOptions>,
): webpack.Configuration {
const {
buildOptions: { codeCoverage, codeCoverageExclude, main, sourceMap },
root,
sourceRoot,
} = wco;
const extraRules: webpack.RuleSetRule[] = [];
const extraPlugins: { apply(compiler: webpack.Compiler): void }[] = [];
if (codeCoverage) {
const exclude: (string | RegExp)[] = [
/\.(e2e|spec)\.tsx?$/,
/node_modules/,
];
if (codeCoverageExclude) {
for (const excludeGlob of codeCoverageExclude) {
glob
.sync(path.join(root, excludeGlob), { nodir: true })
.forEach((file) => exclude.push(path.normalize(file)));
}
}
extraRules.push({
test: /\.(jsx?|tsx?)$/,
loader: require.resolve('@jsdevtools/coverage-istanbul-loader'),
options: { esModules: true },
enforce: 'post',
exclude,
include: sourceRoot,
});
}
if (sourceMap.scripts || sourceMap.styles) {
extraPlugins.push(getSourceMapDevTool(
sourceMap.scripts,
sourceMap.styles,
false,
true,
));
}
return {
mode: 'development',
resolve: {
mainFields: ['es2015', 'browser', 'module', 'main'],
},
devtool: false,
entry: {
main: path.resolve(root, main),
},
module: {
rules: extraRules,
},
plugins: extraPlugins,
optimization: {
splitChunks: {
chunks: (chunk) => !isPolyfillsEntry(chunk.name),
cacheGroups: {
vendors: false,
defaultVendors: {
name: 'vendor',
chunks: (chunk) => chunk.name === 'main',
enforce: true,
test: /[\\/]node_modules[\\/]/,
},
},
},
},
};
}