| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  | var SourceMapConsumer = require('source-map').SourceMapConsumer; | 
					
						
							|  |  |  | var DotsReporter = require('karma/lib/reporters/dots_color'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | var createErrorFormatter = function(basePath, emitter, SourceMapConsumer) { | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |   var lastServedFiles = []; | 
					
						
							| 
									
										
										
										
											2017-09-22 19:51:03 +02:00
										 |  |  |   emitter.on('file_list_modified', function(files) { lastServedFiles = files.served; }); | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |   function findFile(path) { return lastServedFiles.filter(_ => _.path === path)[0]; } | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |   var URL_REGEXP = new RegExp( | 
					
						
							|  |  |  |       '(?:https?:\\/\\/[^\\/]*)?\\/?' + | 
					
						
							|  |  |  |           '(base|absolute)' +               // prefix
 | 
					
						
							|  |  |  |           '((?:[A-z]\\:)?[^\\?\\s\\:]*)' +  // path
 | 
					
						
							|  |  |  |           '(\\?\\w*)?' +                    // sha
 | 
					
						
							|  |  |  |           '(\\:(\\d+))?' +                  // line
 | 
					
						
							|  |  |  |           '(\\:(\\d+))?' +                  // column
 | 
					
						
							|  |  |  |           '', | 
					
						
							|  |  |  |       'g'); | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |   return function(msg, indentation) { | 
					
						
							|  |  |  |     msg = (msg || '').replace(URL_REGEXP, function(_, prefix, path, __, ___, line, ____, column) { | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |       if (prefix === 'base') { | 
					
						
							|  |  |  |         path = basePath + path; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       line = parseInt(line || '0', 10); | 
					
						
							|  |  |  |       column = parseInt(column || '0', 10); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |       var file = findFile(path); | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |       if (file && file.sourceMap) { | 
					
						
							|  |  |  |         try { | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |           var original = new SourceMapConsumer(file.sourceMap) | 
					
						
							|  |  |  |                              .originalPositionFor({line: line, column: column}); | 
					
						
							|  |  |  |           return process.cwd() + '/modules/' + original.source + ':' + original.line + ':' + | 
					
						
							|  |  |  |               original.column; | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |         } catch (e) { | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  |           console.warn('SourceMap position not found for trace: %s', msg); | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return path + ':' + line + ':' + column; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // indent every line
 | 
					
						
							|  |  |  |     if (indentation) { | 
					
						
							| 
									
										
										
										
											2017-09-22 19:51:03 +02:00
										 |  |  |       msg = indentation + msg.replace(/\n/g, '\n' + indentation); | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return msg + '\n'; | 
					
						
							| 
									
										
										
										
											2017-09-22 19:51:03 +02:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | var InternalAngularReporter = function(config, emitter) { | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |   var formatter = createErrorFormatter(config.basePath, emitter, SourceMapConsumer); | 
					
						
							| 
									
										
										
										
											2017-09-22 19:51:03 +02:00
										 |  |  |   DotsReporter.call(this, formatter, false, config.colors); | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | InternalAngularReporter.$inject = ['config', 'emitter']; | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | module.exports = { | 
					
						
							|  |  |  |   'reporter:internal-angular': ['type', InternalAngularReporter] | 
					
						
							|  |  |  | }; |