forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
70 lines (60 loc) · 1.95 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
import * as path from 'path';
import * as glob from 'glob';
import * as webpack from 'webpack';
import { CliConfig } from '../config';
import { WebpackTestOptions } from '../webpack-test-config';
/**
* Enumerate loaders and their dependencies from this file to let the dependency validator
* know they are used.
*
* require('istanbul-instrumenter-loader')
*
*/
export function getTestConfig(testConfig: WebpackTestOptions) {
const configPath = CliConfig.configFilePath();
const projectRoot = path.dirname(configPath);
const appConfig = CliConfig.fromProject().config.apps[0];
const nodeModules = path.resolve(projectRoot, 'node_modules');
const extraRules: any[] = [];
const extraPlugins: any[] = [];
if (testConfig.codeCoverage && CliConfig.fromProject()) {
const codeCoverageExclude = CliConfig.fromProject().get('test.codeCoverage.exclude');
let exclude: (string | RegExp)[] = [
/\.(e2e|spec)\.ts$/,
/node_modules/
];
if (codeCoverageExclude) {
codeCoverageExclude.forEach((excludeGlob: string) => {
const excludeFiles = glob
.sync(path.join(projectRoot, excludeGlob), { nodir: true })
.map(file => path.normalize(file));
exclude.push(...excludeFiles);
});
}
extraRules.push({
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
enforce: 'post',
exclude
});
}
return {
devtool: testConfig.sourcemaps ? 'inline-source-map' : 'eval',
entry: {
main: path.resolve(projectRoot, appConfig.root, appConfig.test)
},
module: {
rules: [].concat(extraRules)
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
minChunks: Infinity,
name: 'inline'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['main'],
minChunks: (module: any) => module.resource && module.resource.startsWith(nodeModules)
})
].concat(extraPlugins)
};
}