Skip to content

Commit 71b99a0

Browse files
devversionjelbourn
authored andcommitted
build: run tests against view engine and ivy (#17491)
We currently only run tests against Ivy due to the commit that switched the `--define=compile` flag. This means that the `ivy_test` and `local_browsers` job are doing the same. Instead we should change `ivy_test` to run tests against View Engine. Same applies for the cronjobs.
1 parent c44aee6 commit 71b99a0

File tree

11 files changed

+111
-85
lines changed

11 files changed

+111
-85
lines changed

.circleci/config.yml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ var_15: &ignore_presubmit_branch_filter
105105
branches:
106106
ignore:
107107
- "_presubmit"
108-
- "ivy-2019"
109108

110109
# Runs a script that sets up the Bazel remote execution. This will be used by jobs that run
111110
# Bazel primarily and should benefit from remote caching and execution.
@@ -386,10 +385,10 @@ jobs:
386385
- run: bazel test src/... --build_tag_filters=-e2e --test_tag_filters=-e2e
387386

388387
# ----------------------------------------------------------------------------
389-
# Job that runs all Bazel tests against Ivy with the current Angular version
388+
# Job that runs all Bazel tests against View Engine with the current Angular version
390389
# specified in the project dev dependencies.
391390
# ----------------------------------------------------------------------------
392-
ivy_test:
391+
view_engine_test:
393392
<<: *job_defaults
394393
resource_class: xlarge
395394
environment:
@@ -403,17 +402,14 @@ jobs:
403402
- *yarn_install
404403
- *setup_bazel_binary
405404

406-
# Setup ngcc to make the Angular packages compatible with ngtsc (i.e. creating
407-
# directive and component definitions as static class members).
408-
- run: node ./scripts/circleci/setup-ivy-ngcc.js
409-
# Run project tests with ngtsc and the Ivy Angular packages.
410-
- run: bazel build src/... --build_tag_filters=-docs-package,-e2e --define=compile=aot
411-
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --define=compile=aot
405+
# Run project tests with NGC and View Engine.
406+
- run: bazel build src/... --build_tag_filters=-docs-package,-e2e --define=compile=legacy
407+
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --define=compile=legacy
412408

413409
# ----------------------------------------------------------------------------
414-
# Job that runs all Bazel tests against Ivy from angular/angular#master.
410+
# Job that runs all Bazel tests against View Engine from angular/angular#master.
415411
# ----------------------------------------------------------------------------
416-
ivy_snapshot_test_cronjob:
412+
view_engine_snapshot_test_cronjob:
417413
<<: *job_defaults
418414
resource_class: xlarge
419415
environment:
@@ -427,11 +423,11 @@ jobs:
427423
- *yarn_install
428424
- *setup_bazel_binary
429425

430-
# Setup Angular ivy snapshots built with ngtsc.
431-
- run: node ./scripts/circleci/setup-angular-snapshots.js --tag master-ivy-aot
432-
# Run project tests with ngtsc and the Ivy Angular packages.
433-
- run: bazel build src/... --build_tag_filters=-docs-package,-e2e --define=compile=aot
434-
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --define=compile=aot
426+
# Setup Angular snapshots by installing the artifacts from the Github repositories.
427+
- run: node ./scripts/circleci/setup-angular-snapshots.js --tag master
428+
# Run project tests with NGC and View Engine.
429+
- run: bazel build src/... --build_tag_filters=-docs-package,-e2e --define=compile=legacy
430+
- run: bazel test src/... --build_tag_filters=-docs-package,-e2e --test_tag_filters=-e2e --define=compile=legacy
435431

436432
# ----------------------------------------------------------------------------
437433
# Job that runs all Bazel tests against material-components-web#master.
@@ -494,7 +490,7 @@ workflows:
494490
jobs:
495491
- bazel_build:
496492
filters: *ignore_presubmit_branch_filter
497-
- ivy_test:
493+
- view_engine_test:
498494
filters: *ignore_presubmit_branch_filter
499495
- api_golden_checks:
500496
filters: *ignore_presubmit_branch_filter
@@ -536,7 +532,7 @@ workflows:
536532
# is no easy way to detect whether a job runs inside of a cronjob or specific
537533
# workflow. See: https://circleci.com/ideas/?idea=CCI-I-295
538534
- snapshot_tests_local_browsers
539-
- ivy_snapshot_test_cronjob
535+
- view_engine_snapshot_test_cronjob
540536
- mdc_snapshot_test_cronjob
541537
triggers:
542538
- schedule:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"yarn": ">= 1.17.3"
1414
},
1515
"scripts": {
16-
"postinstall": "node --preserve-symlinks --preserve-symlinks-main tools/bazel/postinstall-patches.js | ngcc --properties main",
16+
"postinstall": "node --preserve-symlinks --preserve-symlinks-main tools/bazel/postinstall-patches.js && ngcc --properties main --create-ivy-entry-points",
1717
"build": "bash ./scripts/build-packages-dist.sh",
1818
"bazel:buildifier": "find . -type f \\( -name \"*.bzl\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs buildifier -v --warnings=attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,constant-glob,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,git-repository,http-archive,integer-division,load,load-on-top,native-build,native-package,output-group,package-name,package-on-top,redefined-variable,repository-name,same-origin-load,string-iteration,unused-variable,unsorted-dict-items,out-of-order-load",
1919
"bazel:format-lint": "yarn -s bazel:buildifier --lint=warn --mode=check",

packages.bzl

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,42 @@ VERSION_PLACEHOLDER_REPLACEMENTS = {
88
"0.0.0-NG": ANGULAR_PACKAGE_VERSION,
99
}
1010

11-
# UMD bundles for Angular packages and subpackages we depend on for development and testing.
12-
ANGULAR_LIBRARY_UMDS = [
13-
"@npm//:node_modules/@angular/animations/bundles/animations-browser.umd.js",
14-
"@npm//:node_modules/@angular/animations/bundles/animations.umd.js",
15-
"@npm//:node_modules/@angular/common/bundles/common-http-testing.umd.js",
16-
"@npm//:node_modules/@angular/common/bundles/common-http.umd.js",
17-
"@npm//:node_modules/@angular/common/bundles/common-testing.umd.js",
18-
"@npm//:node_modules/@angular/common/bundles/common.umd.js",
19-
"@npm//:node_modules/@angular/compiler/bundles/compiler-testing.umd.js",
11+
# List of default Angular library UMD bundles which are not processed by ngcc.
12+
ANGULAR_NO_NGCC_BUNDLES = [
2013
"@npm//:node_modules/@angular/compiler/bundles/compiler.umd.js",
21-
"@npm//:node_modules/@angular/core/bundles/core-testing.umd.js",
22-
"@npm//:node_modules/@angular/core/bundles/core.umd.js",
23-
"@npm//:node_modules/@angular/elements/bundles/elements.umd.js",
24-
"@npm//:node_modules/@angular/forms/bundles/forms.umd.js",
25-
"@npm//:node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js",
26-
"@npm//:node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js",
27-
"@npm//:node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js",
28-
"@npm//:node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js",
29-
"@npm//:node_modules/@angular/platform-browser/bundles/platform-browser.umd.js",
30-
"@npm//:node_modules/@angular/router/bundles/router.umd.js",
3114
]
15+
16+
# List of Angular library UMD bundles which will are processed by ngcc.
17+
ANGULAR_NGCC_BUNDLES = [
18+
("@angular/animations", ["animations-browser.umd.js", "animations.umd.js"]),
19+
("@angular/common", ["common-http-testing.umd.js", "common-http.umd.js", "common-testing.umd.js", "common.umd.js"]),
20+
("@angular/compiler", ["compiler-testing.umd.js"]),
21+
("@angular/core", ["core-testing.umd.js", "core.umd.js"]),
22+
("@angular/elements", ["elements.umd.js"]),
23+
("@angular/forms", ["forms.umd.js"]),
24+
("@angular/platform-browser-dynamic", ["platform-browser-dynamic-testing.umd.js", "platform-browser-dynamic.umd.js"]),
25+
("@angular/platform-browser", ["platform-browser.umd.js", "platform-browser-testing.umd.js", "platform-browser-animations.umd.js"]),
26+
("@angular/router", ["router.umd.js"]),
27+
]
28+
29+
ANGULAR_LIBRARY_VIEW_ENGINE_UMDS = ANGULAR_NO_NGCC_BUNDLES + [
30+
"@npm//:node_modules/%s/bundles/%s" % (pkgName, bundleName)
31+
for pkgName, bundleNames in ANGULAR_NGCC_BUNDLES
32+
for bundleName in bundleNames
33+
]
34+
ANGULAR_LIBRARY_IVY_UMDS = ANGULAR_NO_NGCC_BUNDLES + [
35+
"@npm//:node_modules/%s/__ivy_ngcc__/bundles/%s" % (pkgName, bundleName)
36+
for pkgName, bundleNames in ANGULAR_NGCC_BUNDLES
37+
for bundleName in bundleNames
38+
]
39+
40+
"""
41+
Gets the list of targets for the Angular library UMD bundles. Conditionally
42+
switches between View Engine or Ivy UMD bundles based on the "--define=compile" flag.
43+
"""
44+
45+
def getAngularUmdTargets():
46+
return select({
47+
"//tools:view_engine_mode": ANGULAR_LIBRARY_VIEW_ENGINE_UMDS,
48+
"//conditions:default": ANGULAR_LIBRARY_IVY_UMDS,
49+
})

scripts/circleci/setup-ivy-ngcc.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/dev-app/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,20 @@ sass_binary(
9292
],
9393
)
9494

95+
genrule(
96+
name = "setup_compile_mode_script",
97+
outs = ["setup_compile_mode.js"],
98+
cmd = "echo window.bazelCompileMode = \"'$(compile)'\"\; > $@",
99+
)
100+
95101
dev_server(
96102
name = "devserver",
97103
srcs = [
98104
"favicon.ico",
99105
"index.html",
100106
"system-config.js",
101107
"system-rxjs-operators.js",
108+
":setup_compile_mode_script",
102109
":theme",
103110
"//src/dev-app/icon:icon_demo_assets",
104111
"@npm//:node_modules/@material/animation/dist/mdc.animation.js",

src/dev-app/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
<body>
2525
<dev-app>Loading...</dev-app>
2626
</body>
27+
2728
<script src="core-js/client/core.js"></script>
2829
<script src="zone.js/dist/zone.js"></script>
29-
3030
<script src="systemjs/dist/system.js"></script>
31+
<script src="setup_compile_mode.js"></script>
3132
<script src="system-config.js"></script>
3233
<script src="https://www.youtube.com/iframe_api"></script>
3334
<script src="https://maps.googleapis.com/maps/api/js"></script>

src/dev-app/system-config.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ var pathMapping = {};
8080
/** Package configurations that will be used in SystemJS. */
8181
var packagesConfig = {};
8282

83+
// The "bazelCompileMode" property will be set globally by the "setup-compile-mode.js"
84+
// script. This allows us to switch between Ivy and View Engine UMD bundles automatically.
85+
/** Whether the dev-app is served with Ivy enabled. */
86+
var isRunningWithIvy = window.bazelCompileMode === 'aot';
87+
8388
// Configure all primary entry-points.
8489
configureEntryPoint('cdk');
8590
configureEntryPoint('cdk-experimental');
@@ -115,6 +120,18 @@ function configureEntryPoint(pkgName, entryPoint) {
115120
packagesConfig[srcRunfilePath + '/' + examplesName] = {main: 'index.js'};
116121
}
117122

123+
/**
124+
* Gets the path to the given bundle. Respects processing done by ngcc when
125+
* running with Ivy enabled.
126+
*/
127+
function getBundlePath(bundleName, basePath) {
128+
var relativeBundlePath = 'bundles/' + bundleName;
129+
if (isRunningWithIvy) {
130+
relativeBundlePath = '__ivy_ngcc__/' + relativeBundlePath;
131+
}
132+
return (basePath || '') + '/' + relativeBundlePath ;
133+
}
134+
118135
var map = Object.assign({
119136
'main': 'main.js',
120137
'tslib': 'tslib/tslib.js',
@@ -162,18 +179,22 @@ var packages = Object.assign({
162179
'.': {defaultExtension: 'js'},
163180

164181
// Angular specific mappings.
165-
'@angular/core': {main: 'bundles/core.umd.js'},
166-
'@angular/common': {main: 'bundles/common.umd.js'},
167-
'@angular/common/http': {main: '../bundles/common-http.umd.js'},
168-
'@angular/compiler': {main: 'bundles/compiler.umd.js'},
169-
'@angular/forms': {main: 'bundles/forms.umd.js'},
170-
'@angular/animations': {main: 'bundles/animations.umd.js'},
171-
'@angular/elements': {main: 'bundles/elements.umd.js'},
172-
'@angular/router': {main: 'bundles/router.umd.js'},
173-
'@angular/animations/browser': {main: '../bundles/animations-browser.umd.js'},
174-
'@angular/platform-browser/animations': {main: '../bundles/platform-browser-animations.umd'},
175-
'@angular/platform-browser': {main: 'bundles/platform-browser.umd.js'},
176-
'@angular/platform-browser-dynamic': {main: 'bundles/platform-browser-dynamic.umd.js'},
182+
'@angular/core': {main: getBundlePath('core.umd.js')},
183+
'@angular/common': {main: getBundlePath('common.umd.js')},
184+
'@angular/common/http': {main: getBundlePath('common-http.umd.js', '../')},
185+
'@angular/compiler': {main: getBundlePath('compiler.umd.js')},
186+
'@angular/forms': {main: getBundlePath('forms.umd.js')},
187+
'@angular/animations': {main: getBundlePath('animations.umd.js')},
188+
'@angular/elements': {main: getBundlePath('elements.umd.js')},
189+
'@angular/router': {main: getBundlePath('router.umd.js')},
190+
'@angular/animations/browser': {
191+
main: getBundlePath('animations-browser.umd.js', '../')
192+
},
193+
'@angular/platform-browser/animations': {
194+
main: getBundlePath('platform-browser-animations.umd.js', '../')
195+
},
196+
'@angular/platform-browser': {main: getBundlePath('platform-browser.umd.js')},
197+
'@angular/platform-browser-dynamic': {main: getBundlePath('platform-browser-dynamic.umd.js')},
177198
}, packagesConfig);
178199

179200
// Configure the base path and map the different node packages.

src/e2e-app/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

33
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
4-
load("//:packages.bzl", "ANGULAR_LIBRARY_UMDS")
4+
load("//:packages.bzl", "getAngularUmdTargets")
55
load("//tools:defaults.bzl", "ng_module", "sass_binary")
66

77
exports_files([
@@ -105,7 +105,7 @@ ts_devserver(
105105
":devserver-configure.js",
106106
"//tools/rxjs:rxjs_umd_modules",
107107
"@npm//:node_modules/tslib/tslib.js",
108-
] + ANGULAR_LIBRARY_UMDS,
108+
] + getAngularUmdTargets(),
109109
# Serving path of the bundle that serves all files specified in "deps" and "scripts".
110110
serving_path = "/bundle.js",
111111
# Files which should be provided by Bazel when running the devserver. These are not

tools/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ platform(
1313
}
1414
""",
1515
)
16+
17+
config_setting(
18+
name = "view_engine_mode",
19+
values = {
20+
"define": "compile=legacy",
21+
},
22+
)

tools/bazel/postinstall-patches.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ searchAndReplace(
9999
// Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1208.
100100
shelljs.cat(path.join(__dirname, './manifest_externs_hermeticity.patch')).exec('patch -p0');
101101

102+
// Workaround for using Ngcc with "--create-ivy-entry-points". This is a special
103+
// issue for our repository since we want to run Ivy by default in the module resolution,
104+
// but still have the option to opt-out by not using the compiled ngcc entry-points.
105+
searchAndReplace(`[formatProperty + "_ivy_ngcc"]`, '[formatProperty]',
106+
'node_modules/@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.js');
107+
102108
/**
103109
* Reads the specified file and replaces matches of the search expression
104110
* with the given replacement. Throws if no changes were made.

tools/defaults.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test")
66
load("@npm_bazel_karma//:index.bzl", _karma_web_test_suite = "karma_web_test_suite")
77
load("@npm_bazel_protractor//:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
88
load("@npm_bazel_typescript//:index.bzl", _ts_library = "ts_library")
9-
load("//:packages.bzl", "ANGULAR_LIBRARY_UMDS", "VERSION_PLACEHOLDER_REPLACEMENTS")
9+
load("//:packages.bzl", "VERSION_PLACEHOLDER_REPLACEMENTS", "getAngularUmdTargets")
1010
load("//:rollup-globals.bzl", "ROLLUP_GLOBALS")
1111
load("//tools/markdown-to-html:index.bzl", _markdown_to_html = "markdown_to_html")
1212

@@ -163,7 +163,7 @@ def karma_web_test_suite(deps = [], srcs = [], **kwargs):
163163
# TODO(jelbourn): remove UMDs from here once we don't have to manually include them
164164
srcs = [
165165
"@npm//:node_modules/tslib/tslib.js",
166-
] + ANGULAR_LIBRARY_UMDS + srcs,
166+
] + getAngularUmdTargets() + srcs,
167167
**kwargs
168168
)
169169

0 commit comments

Comments
 (0)