@@ -102,45 +102,33 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
102
102
webpackConfig . plugins . push ( new KarmaWebpackThrowError ( ) ) ;
103
103
}
104
104
105
+ // Use existing config if any.
105
106
config . webpack = Object . assign ( webpackConfig , config . webpack ) ;
106
107
config . webpackMiddleware = Object . assign ( webpackMiddlewareConfig , config . webpackMiddleware ) ;
107
108
108
- // Replace the @angular /cli preprocessor with webpack+sourcemap.
109
- Object . keys ( config . preprocessors )
110
- . filter ( ( file ) => config . preprocessors [ file ] . indexOf ( '@angular/cli' ) !== - 1 )
111
- . map ( ( file ) => config . preprocessors [ file ] )
112
- . map ( ( arr ) => arr . splice ( arr . indexOf ( '@angular/cli' ) , 1 , 'webpack' , 'sourcemap' ) ) ;
113
-
114
- config . customContextFile = `${ __dirname } /karma-context.html` ;
115
- config . customDebugFile = `${ __dirname } /karma-debug.html` ;
116
-
117
- config . files . forEach ( ( file : any ) => {
118
- if ( file . pattern === `./${ appConfig . root } /${ appConfig . test } ` ) {
119
- file . watched = false ;
120
- file . served = false ;
121
- file . included = false ;
109
+ // Remove the @angular /cli test file if present, for backwards compatibility.
110
+ const testFilePath = path . join ( appRoot , appConfig . test ) ;
111
+ config . files . forEach ( ( file : any , index : number ) => {
112
+ if ( path . normalize ( file . pattern ) === testFilePath ) {
113
+ config . files . splice ( index , 1 ) ;
122
114
}
123
115
} ) ;
124
116
117
+ // Our custom context and debug files list the webpack bundles directly instead of using
118
+ // the karma files array.
119
+ config . customContextFile = `${ __dirname } /karma-context.html` ;
120
+ config . customDebugFile = `${ __dirname } /karma-debug.html` ;
125
121
126
- // Add the blocker.
122
+ // Add the request blocker.
127
123
config . beforeMiddleware = config . beforeMiddleware || [ ] ;
128
124
config . beforeMiddleware . push ( 'angularCliBlocker' ) ;
129
125
130
- // code from karma-webpack
131
-
132
- // The webpack tier owns the watch behavior so we want to force it in the config
126
+ // The webpack tier owns the watch behavior so we want to force it in the config.
133
127
webpackConfig . watch = true ;
134
128
// Files need to be served from a custom path for Karma.
135
129
webpackConfig . output . path = '/_karma_webpack_/' ;
136
130
webpackConfig . output . publicPath = '/_karma_webpack_/' ;
137
131
138
-
139
- // webpackConfig.entry = Object.assign({}, {
140
- // scripts: [],
141
- // styles: []
142
- // }, webpackConfig.entry)
143
-
144
132
let compiler : any ;
145
133
try {
146
134
compiler = webpack ( webpackConfig ) ;
0 commit comments