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