Skip to content

Commit 4b1204c

Browse files
devversionAndrewKushnir
authored andcommitted
build: disable jasminewd2 types for sourcemap playground test (angular#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 angular#46888
1 parent d42ed73 commit 4b1204c

3 files changed

Lines changed: 48 additions & 42 deletions

File tree

modules/playground/e2e_test/example_test.bzl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
load("//tools:defaults.bzl", "protractor_web_test_suite", "ts_library")
22

3-
def example_test(name, srcs, server, data = [], deps = [], **kwargs):
3+
def example_test(name, srcs, server, data = [], deps = [], use_legacy_webdriver_types = True, **kwargs):
4+
ts_deps = [
5+
"@npm//@angular/dev-infra-private/bazel/benchmark/driver-utilities",
6+
"//packages/private/testing",
7+
"@npm//@types/selenium-webdriver",
8+
"@npm//protractor",
9+
] + deps
10+
11+
# Reliance on the Control Flow in Selenium Webdriver is not recommended long-term,
12+
# especially with the deprecation of Protractor. New tests should not use the legacy
13+
# webdriver types but rather use the actual `@types/jasmine` types.
14+
if use_legacy_webdriver_types:
15+
ts_deps.append("@npm//@types/jasminewd2")
16+
417
ts_library(
518
name = "%s_lib" % name,
619
testonly = True,
720
srcs = srcs,
821
tsconfig = "//modules/playground:tsconfig-e2e.json",
9-
deps = [
10-
"@npm//@angular/dev-infra-private/bazel/benchmark/driver-utilities",
11-
"//packages/private/testing",
12-
"@npm//@types/jasminewd2",
13-
"@npm//@types/selenium-webdriver",
14-
"@npm//protractor",
15-
] + deps,
22+
deps = ts_deps,
1623
)
1724

1825
protractor_web_test_suite(

modules/playground/e2e_test/sourcemap/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ example_test(
88
"//modules/playground/src/sourcemap:index.ts",
99
],
1010
server = "//modules/playground/src/sourcemap:devserver",
11+
use_legacy_webdriver_types = False,
1112
deps = [
1213
"@npm//source-map",
1314
],

modules/playground/e2e_test/sourcemap/sourcemap_spec.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,38 @@ import {RawSourceMap, SourceMapConsumer} from 'source-map';
1414
describe('sourcemaps', function() {
1515
const URL = '/';
1616

17-
it('should map sources', function() {
18-
browser.get(URL);
19-
20-
$('error-app .errorButton').click();
21-
22-
browser.manage().logs().get(logging.Type.BROWSER).then(async function(logs: any) {
23-
let errorLine: number|null = null;
24-
let errorColumn: number|null = null;
25-
logs.forEach(function(log: any) {
26-
const match = log.message.match(/\.createError\s+\(.+:(\d+):(\d+)/m);
27-
if (match) {
28-
errorLine = parseInt(match[1]);
29-
errorColumn = parseInt(match[2]);
30-
}
31-
});
32-
33-
expect(errorLine).not.toBeNull();
34-
expect(errorColumn).not.toBeNull();
35-
36-
const content =
37-
readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8');
38-
const marker = '//# sourceMappingURL=data:application/json;base64,';
39-
const index = content.indexOf(marker);
40-
const sourceMapData =
41-
Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8');
42-
43-
const decoder = await new SourceMapConsumer(JSON.parse(sourceMapData) as RawSourceMap);
44-
const originalPosition =
45-
decoder.originalPositionFor({line: errorLine!, column: errorColumn!});
46-
const sourceCodeLines = readFileSync(require.resolve('../../src/sourcemap/index.ts'), {
47-
encoding: 'utf-8'
48-
}).split('\n');
49-
expect(sourceCodeLines[originalPosition.line! - 1])
50-
.toMatch(/throw new Error\(\'Sourcemap test\'\)/);
17+
it('should map sources', async function() {
18+
await browser.get(URL);
19+
20+
await $('error-app .errorButton').click();
21+
22+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
23+
24+
let errorLine: number|null = null;
25+
let errorColumn: number|null = null;
26+
logs.forEach(function(log: any) {
27+
const match = log.message.match(/\.createError\s+\(.+:(\d+):(\d+)/m);
28+
if (match) {
29+
errorLine = parseInt(match[1]);
30+
errorColumn = parseInt(match[2]);
31+
}
5132
});
33+
34+
expect(errorLine).not.toBeNull();
35+
expect(errorColumn).not.toBeNull();
36+
37+
const content = readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8');
38+
const marker = '//# sourceMappingURL=data:application/json;base64,';
39+
const index = content.indexOf(marker);
40+
const sourceMapData =
41+
Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8');
42+
43+
const decoder = await new SourceMapConsumer(JSON.parse(sourceMapData) as RawSourceMap);
44+
const originalPosition = decoder.originalPositionFor({line: errorLine!, column: errorColumn!});
45+
const sourceCodeLines = readFileSync(require.resolve('../../src/sourcemap/index.ts'), {
46+
encoding: 'utf-8'
47+
}).split('\n');
48+
expect(sourceCodeLines[originalPosition.line! - 1])
49+
.toMatch(/throw new Error\(\'Sourcemap test\'\)/);
5250
});
5351
});

0 commit comments

Comments
 (0)