@@ -8,6 +8,14 @@ import { Pattern } from './glob-copy-webpack-plugin';
8
8
import { WebpackTestConfig , WebpackTestOptions } from '../models/webpack-test-config' ;
9
9
import { KarmaWebpackThrowError } from './karma-webpack-throw-error' ;
10
10
11
+ /**
12
+ * Enumerate needed (but not require/imported) dependencies from this file
13
+ * to let the dependency validator know they are used.
14
+ *
15
+ * require('karma-source-map-support')
16
+ */
17
+
18
+
11
19
const getAppFromConfig = require ( '../utilities/app-utils' ) . getAppFromConfig ;
12
20
13
21
let blocked : any [ ] = [ ] ;
@@ -54,6 +62,22 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
54
62
progress : true ,
55
63
} , config . angularCli ) ;
56
64
65
+ if ( testConfig . sourcemaps ) {
66
+ // Add a reporter that fixes sourcemap urls.
67
+ config . reporters . unshift ( '@angular/cli' ) ;
68
+
69
+ // Code taken from https://github.com/tschaub/karma-source-map-support.
70
+ // We can't use it directly because we need to add it conditionally in this file, and karma
71
+ // frameworks cannot be added dynamically.
72
+ const smsPath = path . dirname ( require . resolve ( 'source-map-support' ) ) ;
73
+ const ksmsPath = path . dirname ( require . resolve ( 'karma-source-map-support' ) ) ;
74
+
75
+ addKarmaFiles ( config . files , [
76
+ { pattern : path . join ( smsPath , 'browser-source-map-support.js' ) , watched : false } ,
77
+ { pattern : path . join ( ksmsPath , 'client.js' ) , watched : false }
78
+ ] , true ) ;
79
+ }
80
+
57
81
// Add assets. This logic is mimics the one present in GlobCopyWebpackPlugin.
58
82
if ( appConfig . assets ) {
59
83
config . proxies = config . proxies || { } ;
@@ -227,9 +251,25 @@ function requestBlocker() {
227
251
} ;
228
252
}
229
253
230
- // Also export karma-webpack and karma-sourcemap-loader.
254
+ // Strip the server address and webpack scheme (webpack://) from error log.
255
+ const initSourcemapReporter : any = function ( baseReporterDecorator : any ) {
256
+ baseReporterDecorator ( this ) ;
257
+ 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;
258
+
259
+ this . onSpecComplete = function ( _browser : any , result : any ) {
260
+ if ( ! result . success && result . log . length > 0 ) {
261
+ result . log . forEach ( ( log : string , idx : number ) => {
262
+ result . log [ idx ] = log . replace ( urlRegexp , '' ) ;
263
+ } ) ;
264
+ }
265
+ } ;
266
+ } ;
267
+
268
+ initSourcemapReporter . $inject = [ 'baseReporterDecorator' ] ;
269
+
231
270
module . exports = Object . assign ( {
232
271
'framework:@angular/cli' : [ 'factory' , init ] ,
233
272
'preprocessor:@angular/cli' : [ 'factory' , preprocessor ] ,
273
+ 'reporter:@angular/cli' : [ 'type' , initSourcemapReporter ] ,
234
274
'middleware:angularCliBlocker' : [ 'factory' , requestBlocker ]
235
275
} ) ;
0 commit comments