1
+ const path = require ( 'path' ) ;
2
+ const getWebpackTestConfig = require ( '../addon/ng2/models/webpack-build-test' ) . getWebpackTestConfig ;
3
+
4
+ const init = ( config ) => {
5
+
6
+ // load Angular CLI config
7
+ if ( ! config . angularCliConfig ) throw new Error ( 'Missing \'angularCliConfig\' entry in Karma config' ) ;
8
+ const angularCliConfig = require ( path . join ( config . basePath , config . angularCliConfig ) )
9
+
10
+ // add webpack config
11
+ config . webpack = getWebpackTestConfig ( config . basePath , angularCliConfig . defaults . sourceDir ) ;
12
+ config . webpackMiddleware = {
13
+ noInfo : true , // Hide webpack output because its noisy.
14
+ stats : { // Also prevent chunk and module display output, cleaner look. Only emit errors.
15
+ assets : false ,
16
+ colors : true ,
17
+ version : false ,
18
+ hash : false ,
19
+ timings : false ,
20
+ chunks : false ,
21
+ chunkModules : false
22
+ }
23
+ } ;
24
+
25
+ // replace the angular-cli preprocessor with webpack+sourcemap
26
+ Object . keys ( config . preprocessors )
27
+ . filter ( ( file ) => config . preprocessors [ file ] . indexOf ( 'angular-cli' ) !== - 1 )
28
+ . map ( ( file ) => config . preprocessors [ file ] )
29
+ . map ( ( arr ) => arr . splice ( arr . indexOf ( 'angular-cli' ) , 1 , 'webpack' , 'sourcemap' ) ) ;
30
+ }
31
+
32
+ init . $inject = [ 'config' ]
33
+
34
+ // dummy preprocessor, just to keep karma from showing a warning
35
+ const preprocessor = ( ) => ( content , file , done ) => done ( null , content ) ;
36
+ preprocessor . $inject = [ ]
37
+
38
+ // also export karma-webpack and karma-sourcemap-loader
39
+ module . exports = Object . assign ( {
40
+ 'framework:angular-cli' : [ 'factory' , init ] ,
41
+ 'preprocessor:angular-cli' : [ 'factory' , preprocessor ]
42
+ } , require ( 'karma-webpack' ) , require ( 'karma-sourcemap-loader' ) ) ;
0 commit comments