2016-06-23 16:47:54 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 16:47:54 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2016-06-23 16:47:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-02-04 22:38:25 +00:00
|
|
|
import {readFileSync} from 'fs';
|
2016-11-11 02:13:11 +00:00
|
|
|
import {$, browser} from 'protractor';
|
|
|
|
|
import {logging} from 'selenium-webdriver';
|
2021-02-04 22:38:25 +00:00
|
|
|
import {RawSourceMap, SourceMapConsumer} from 'source-map';
|
2025-06-26 18:59:19 +00:00
|
|
|
import {resolve} from 'path';
|
2015-02-11 22:54:59 +00:00
|
|
|
|
2015-05-29 21:33:54 +00:00
|
|
|
describe('sourcemaps', function () {
|
2019-02-01 13:46:38 +00:00
|
|
|
const URL = '/';
|
2015-02-11 22:54:59 +00:00
|
|
|
|
2022-07-19 09:52:03 +00:00
|
|
|
it('should map sources', async function () {
|
|
|
|
|
await browser.get(URL);
|
|
|
|
|
|
|
|
|
|
await $('error-app .errorButton').click();
|
|
|
|
|
|
|
|
|
|
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
|
|
|
|
|
|
|
|
|
|
let errorLine: number | null = null;
|
|
|
|
|
let errorColumn: number | null = null;
|
|
|
|
|
logs.forEach(function (log: any) {
|
|
|
|
|
const match = log.message.match(/\.createError\s+\(.+:(\d+):(\d+)/m);
|
|
|
|
|
if (match) {
|
|
|
|
|
errorLine = parseInt(match[1]);
|
|
|
|
|
errorColumn = parseInt(match[2]);
|
|
|
|
|
}
|
2015-02-11 22:54:59 +00:00
|
|
|
});
|
2022-07-19 09:52:03 +00:00
|
|
|
|
|
|
|
|
expect(errorLine).not.toBeNull();
|
|
|
|
|
expect(errorColumn).not.toBeNull();
|
|
|
|
|
|
2022-12-14 19:30:53 +00:00
|
|
|
const mapContent = readFileSync(
|
2025-06-26 18:59:19 +00:00
|
|
|
resolve('./modules/playground/src/sourcemap/bundles/main.js.map'),
|
|
|
|
|
'utf-8',
|
|
|
|
|
);
|
2022-12-14 19:30:53 +00:00
|
|
|
const decoder = await new SourceMapConsumer(JSON.parse(mapContent) as RawSourceMap);
|
2022-07-19 09:52:03 +00:00
|
|
|
const originalPosition = decoder.originalPositionFor({line: errorLine!, column: errorColumn!});
|
2022-12-14 19:30:53 +00:00
|
|
|
const sourceCodeLines = readFileSync(
|
2025-06-26 18:59:19 +00:00
|
|
|
resolve('./modules/playground/src/sourcemap/main.ts'),
|
|
|
|
|
'utf-8',
|
2022-12-14 19:30:53 +00:00
|
|
|
).split('\n');
|
2022-07-19 09:52:03 +00:00
|
|
|
expect(sourceCodeLines[originalPosition.line! - 1]).toMatch(
|
|
|
|
|
/throw new Error\(\'Sourcemap test\'\)/,
|
|
|
|
|
);
|
2015-02-11 22:54:59 +00:00
|
|
|
});
|
|
|
|
|
});
|