angular/modules/playground/e2e_test/sourcemap/sourcemap_spec.ts
Paul Gschwendtner 4b1204cca7 build: disable jasminewd2 types for sourcemap playground test (#46888)
The sourcemap test in the e2e playground is now using async/await code.
This results in errors now with the Bazel TS compilation because it
detects that `expect` is returning a promise and should be awaited.

This happens due to the jasminewd2 types. We should just use the actual
jasmine types and not rely on the deprecated selenium control flow,
using explicit async/await in the whole test. This also solves the issue
with the source-map types being async/await now.

PR Close #46888
2022-07-19 09:40:54 -07:00

51 lines
1.8 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 {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 content = readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8');
const marker = '//# sourceMappingURL=data:application/json;base64,';
const index = content.indexOf(marker);
const sourceMapData =
Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8');
const decoder = await new SourceMapConsumer(JSON.parse(sourceMapData) as RawSourceMap);
const originalPosition = decoder.originalPositionFor({line: errorLine!, column: errorColumn!});
const sourceCodeLines = readFileSync(require.resolve('../../src/sourcemap/index.ts'), {
encoding: 'utf-8'
}).split('\n');
expect(sourceCodeLines[originalPosition.line! - 1])
.toMatch(/throw new Error\(\'Sourcemap test\'\)/);
});
});