@@ -54,6 +54,20 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
54
54
progress : true ,
55
55
} , config . angularCli ) ;
56
56
57
+ if ( testConfig . sourcemaps ) {
58
+ config . reporters . unshift ( '@angular/cli' ) ;
59
+ // Code taken from https://github.com/tschaub/karma-source-map-support.
60
+ // We can't use it directly because we need to add it conditionally in this file, and karma
61
+ // frameworks cannot be added dynamically.
62
+ const smsPath = path . dirname ( require . resolve ( 'source-map-support' ) ) ;
63
+ const ksmsPath = path . dirname ( require . resolve ( 'karma-source-map-support' ) ) ;
64
+
65
+ addKarmaFiles ( config . files , [
66
+ { pattern : path . join ( smsPath , 'browser-source-map-support.js' ) , watched : false } ,
67
+ { pattern : path . join ( ksmsPath , 'client.js' ) , watched : false }
68
+ ] , true ) ;
69
+ }
70
+
57
71
// Add assets. This logic is mimics the one present in GlobCopyWebpackPlugin.
58
72
if ( appConfig . assets ) {
59
73
config . proxies = config . proxies || { } ;
@@ -227,9 +241,25 @@ function requestBlocker() {
227
241
} ;
228
242
}
229
243
230
- // Also export karma-webpack and karma-sourcemap-loader.
244
+ // Strip the server address and webpack scheme (webpack://) from error log.
245
+ const initSourcemapReporter : any = function ( baseReporterDecorator : any ) {
246
+ baseReporterDecorator ( this ) ;
247
+ const urlRegexp = / \( h t t p : \/ \/ l o c a l h o s t : \d + \/ _ k a r m a _ w e b p a c k _ \/ w e b p a c k : \/ / gi;
248
+
249
+ this . onSpecComplete = function ( _browser : any , result : any ) {
250
+ if ( ! result . success && result . log . length > 0 ) {
251
+ result . log . forEach ( ( log : string , idx : number ) => {
252
+ result . log [ idx ] = log . replace ( urlRegexp , '' ) ;
253
+ } ) ;
254
+ }
255
+ } ;
256
+ } ;
257
+
258
+ initSourcemapReporter . $inject = [ 'baseReporterDecorator' ] ;
259
+
231
260
module . exports = Object . assign ( {
232
261
'framework:@angular/cli' : [ 'factory' , init ] ,
233
262
'preprocessor:@angular/cli' : [ 'factory' , preprocessor ] ,
263
+ 'reporter:@angular/cli' : [ 'type' , initSourcemapReporter ] ,
234
264
'middleware:angularCliBlocker' : [ 'factory' , requestBlocker ]
235
265
} ) ;
0 commit comments