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