mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
* Switches away from the ESM-incompatible & unmaintained `ts_devserver` to `http_server`. This is the canonical server maintained by dev-infra * Switches tests away from CommonJS specific logic. e.g. require.resolve * Adjusts tests to work with Protractor spec bundling (Protractor does not support ESM execution, but we want to take ESM-written specs) * Reworks playground and benchmarks to use `app_bundle` and `esbuild` instead of loading hundreds of files individually. This also makes tests more stable and more aligned with real applications. PR Close #48521
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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
|
|
*/
|
|
|
|
import {runfiles} from '@bazel/runfiles';
|
|
import {readFileSync} from 'fs';
|
|
import {$, browser} from 'protractor';
|
|
import {logging} from 'selenium-webdriver';
|
|
import {RawSourceMap, SourceMapConsumer} from 'source-map';
|
|
|
|
describe('sourcemaps', function() {
|
|
const URL = '/';
|
|
|
|
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]);
|
|
}
|
|
});
|
|
|
|
expect(errorLine).not.toBeNull();
|
|
expect(errorColumn).not.toBeNull();
|
|
|
|
const mapContent =
|
|
readFileSync(runfiles.resolvePackageRelative('../../src/sourcemap/app_bundle.js.map'))
|
|
.toString('utf8');
|
|
const decoder = await new SourceMapConsumer(JSON.parse(mapContent) as RawSourceMap);
|
|
const originalPosition = decoder.originalPositionFor({line: errorLine!, column: errorColumn!});
|
|
const sourceCodeLines =
|
|
readFileSync(runfiles.resolvePackageRelative('../../src/sourcemap/index.ts'), {
|
|
encoding: 'utf-8'
|
|
}).split('\n');
|
|
expect(sourceCodeLines[originalPosition.line! - 1])
|
|
.toMatch(/throw new Error\(\'Sourcemap test\'\)/);
|
|
});
|
|
});
|