| 
									
										
										
										
											2016-06-23 09:47:54 -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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 18:13:11 -08:00
										 |  |  | import {$, browser} from 'protractor'; | 
					
						
							|  |  |  | import {logging} from 'selenium-webdriver'; | 
					
						
							| 
									
										
										
										
											2015-05-29 14:33:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const sourceMap = require('source-map'); | 
					
						
							| 
									
										
										
										
											2015-02-11 14:54:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 14:33:54 -07:00
										 |  |  | describe('sourcemaps', function() { | 
					
						
							| 
									
										
										
										
											2019-02-01 14:46:38 +01:00
										 |  |  |   const URL = '/'; | 
					
						
							| 
									
										
										
										
											2015-02-11 14:54:59 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should map sources', function() { | 
					
						
							|  |  |  |     browser.get(URL); | 
					
						
							| 
									
										
										
										
											2015-04-30 11:25:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $('error-app .errorButton').click(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 18:13:11 -08:00
										 |  |  |     browser.manage().logs().get(logging.Type.BROWSER).then(function(logs: any) { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       let errorLine: number = null; | 
					
						
							|  |  |  |       let errorColumn: number = null; | 
					
						
							| 
									
										
										
										
											2016-11-10 18:13:11 -08:00
										 |  |  |       logs.forEach(function(log: any) { | 
					
						
							| 
									
										
										
										
											2016-08-05 09:50:49 -07:00
										 |  |  |         const match = log.message.match(/\.createError\s+\(.+:(\d+):(\d+)/m); | 
					
						
							| 
									
										
										
										
											2015-02-11 14:54:59 -08:00
										 |  |  |         if (match) { | 
					
						
							|  |  |  |           errorLine = parseInt(match[1]); | 
					
						
							|  |  |  |           errorColumn = parseInt(match[2]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(errorLine).not.toBeNull(); | 
					
						
							|  |  |  |       expect(errorColumn).not.toBeNull(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-24 11:01:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |       const content = | 
					
						
							| 
									
										
										
										
											2019-02-01 14:46:38 +01:00
										 |  |  |           fs.readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8'); | 
					
						
							| 
									
										
										
										
											2016-08-05 09:56:53 -07:00
										 |  |  |       const marker = '//# sourceMappingURL=data:application/json;base64,'; | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  |       const index = content.indexOf(marker); | 
					
						
							|  |  |  |       const sourceMapData = | 
					
						
							| 
									
										
										
										
											2018-09-04 10:48:12 -07:00
										 |  |  |           Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8'); | 
					
						
							| 
									
										
										
										
											2015-11-23 14:58:18 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       const decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData)); | 
					
						
							| 
									
										
										
										
											2015-02-11 14:54:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       const originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn}); | 
					
						
							| 
									
										
										
										
											2015-02-11 14:54:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 14:46:38 +01:00
										 |  |  |       const sourceCodeLines = fs.readFileSync(require.resolve('../../src/sourcemap/index.ts'), { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |                                   encoding: 'UTF-8' | 
					
						
							|  |  |  |                                 }).split('\n'); | 
					
						
							| 
									
										
										
										
											2015-09-02 20:58:02 -07:00
										 |  |  |       expect(sourceCodeLines[originalPosition.line - 1]) | 
					
						
							| 
									
										
										
										
											2016-08-25 00:50:16 -07:00
										 |  |  |           .toMatch(/throw new Error\(\'Sourcemap test\'\)/); | 
					
						
							| 
									
										
										
										
											2015-02-11 14:54:59 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |