forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarma.js
43 lines (36 loc) · 1.59 KB
/
karma.js
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
const path = require('path');
const getWebpackTestConfig = require('../addon/ng2/models/webpack-build-test').getWebpackTestConfig;
const init = (config) => {
// load Angular CLI config
if (!config.angularCliConfig) throw new Error('Missing \'angularCliConfig\' entry in Karma config');
const angularCliConfig = require(path.join(config.basePath, config.angularCliConfig));
const appConfig = angularCliConfig.apps[0];
// add webpack config
config.webpack = getWebpackTestConfig(config.basePath, appConfig);
config.webpackMiddleware = {
noInfo: true, // Hide webpack output because its noisy.
stats: { // Also prevent chunk and module display output, cleaner look. Only emit errors.
assets: false,
colors: true,
version: false,
hash: false,
timings: false,
chunks: false,
chunkModules: false
}
};
// replace the angular-cli preprocessor with webpack+sourcemap
Object.keys(config.preprocessors)
.filter((file) => config.preprocessors[file].indexOf('angular-cli') !== -1)
.map((file) => config.preprocessors[file])
.map((arr) => arr.splice(arr.indexOf('angular-cli'), 1, 'webpack', 'sourcemap'));
}
init.$inject = ['config']
// dummy preprocessor, just to keep karma from showing a warning
const preprocessor = () => (content, file, done) => done(null, content);
preprocessor.$inject = []
// also export karma-webpack and karma-sourcemap-loader
module.exports = Object.assign({
'framework:angular-cli': ['factory', init],
'preprocessor:angular-cli': ['factory', preprocessor]
}, require('karma-webpack'), require('karma-sourcemap-loader'));