Skip to content

Commit 12855f3

Browse files
kormidejosephperrott
authored andcommitted
build(bazel): incrementally run aio example e2e tests
Replaces the workflow where all example e2es are run at once
1 parent f62339d commit 12855f3

File tree

48 files changed

+496
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+496
-537
lines changed

BUILD.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
load("//tools:defaults.bzl", "nodejs_binary")
2+
load("//:yarn.bzl", "YARN_PATH")
23

34
package(default_visibility = ["//visibility:public"])
45

56
exports_files([
67
"LICENSE",
78
"karma-js.conf.js",
89
"browser-providers.conf.js",
10+
YARN_PATH,
911
"scripts/ci/bazel-payload-size.sh",
1012
"scripts/ci/payload-size.sh",
1113
"scripts/ci/payload-size.js",
@@ -68,5 +70,8 @@ nodejs_binary(
6870
name = "yarn_vendored",
6971
data = [".yarn/releases/yarn-1.22.17.cjs"],
7072
entry_point = ".yarn/releases/yarn-1.22.17.cjs",
71-
visibility = ["//integration:__subpackages__"],
73+
visibility = [
74+
"//aio/tools/examples/shared:__pkg__",
75+
"//integration:__subpackages__",
76+
],
7277
)

WORKSPACE

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ workspace(
77
)
88

99
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
10+
load("//:yarn.bzl", "YARN_LABEL")
1011

1112
# Add a patch fix for rules_webtesting v0.3.5 required for enabling runfiles on Windows.
1213
# TODO: Remove the http_archive for this transitive dependency when a release is cut
@@ -94,7 +95,7 @@ yarn_install(
9495
# Note that we add the postinstall scripts here so that the dependencies are re-installed
9596
# when the postinstall patches are modified.
9697
data = [
97-
"//:.yarn/releases/yarn-1.22.17.cjs",
98+
YARN_LABEL,
9899
"//:.yarnrc",
99100
"//:scripts/puppeteer-chromedriver-versions.js",
100101
"//:scripts/webdriver-manager-update.js",
@@ -109,7 +110,7 @@ yarn_install(
109110
# We prefer to symlink the `node_modules` to only maintain a single install.
110111
# See https://github.com/angular/dev-infra/pull/446#issuecomment-1059820287 for details.
111112
symlink_node_modules = True,
112-
yarn = "//:.yarn/releases/yarn-1.22.17.cjs",
113+
yarn = YARN_LABEL,
113114
yarn_lock = "//:yarn.lock",
114115
)
115116

@@ -118,7 +119,7 @@ yarn_install(
118119
# Note that we add the postinstall scripts here so that the dependencies are re-installed
119120
# when the postinstall patches are modified.
120121
data = [
121-
"//:.yarn/releases/yarn-1.22.17.cjs",
122+
YARN_LABEL,
122123
"//:.yarnrc",
123124
"//aio:tools/cli-patches/patch.js",
124125
],
@@ -131,27 +132,7 @@ yarn_install(
131132
# We prefer to symlink the `node_modules` to only maintain a single install.
132133
# See https://github.com/angular/dev-infra/pull/446#issuecomment-1059820287 for details.
133134
symlink_node_modules = True,
134-
yarn = "//:.yarn/releases/yarn-1.22.17.cjs",
135-
yarn_lock = "//aio:yarn.lock",
136-
)
137-
138-
# Needed for the aio example e2e tests which run with patched node_module resolution through bazel
139-
yarn_install(
140-
name = "docs_examples_npm",
141-
data = [
142-
"//:.yarn/releases/yarn-1.22.17.cjs",
143-
"//:.yarnrc",
144-
],
145-
# Currently disabled due to:
146-
# 1. Missing Windows support currently.
147-
# 2. Incompatibilites with the `ts_library` rule.
148-
exports_directories_only = False,
149-
manual_build_file_contents = npm_package_archives(),
150-
package_json = "//aio/tools/examples/shared:package.json",
151-
# We prefer to symlink the `node_modules` to only maintain a single install.
152-
# See https://github.com/angular/dev-infra/pull/446#issuecomment-1059820287 for details.
153-
symlink_node_modules = True,
154-
yarn = "//:.yarn/releases/yarn-1.22.17.cjs",
135+
yarn = YARN_LABEL,
155136
yarn_lock = "//aio:yarn.lock",
156137
)
157138

@@ -215,5 +196,5 @@ http_archive(
215196
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")
216197

217198
sass_repositories(
218-
yarn_script = "//:.yarn/releases/yarn-1.22.17.cjs",
199+
yarn_script = YARN_LABEL,
219200
)

aio/content/examples/angular-compiler-options/example-config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"cmd": "yarn",
1010
"args": [
1111
"e2e",
12-
"--protractor-config=e2e/protractor-puppeteer.conf.js",
12+
"--protractor-config=e2e/protractor-bazel.conf.js",
1313
"--no-webdriver-update",
14-
"--port={PORT}"
14+
"--port=0"
1515
]
1616
}
1717
]

aio/content/examples/examples.bzl

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin")
22
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
3+
load("//aio/tools:defaults.bzl", "nodejs_test")
4+
load("//:yarn.bzl", "YARN_LABEL")
35

46
# This map controls which examples are included and whether or not to generate
57
# a stackblitz live examples and zip archives. Keys are the example name, and values
@@ -96,11 +98,13 @@ EXAMPLES = {
9698
"what-is-angular": {"stackblitz": True, "zip": True},
9799
}
98100

99-
def docs_example(name):
101+
def docs_example(name, test = True, test_tags = []):
100102
"""Stamp targets for adding boilerplate to examples, creating live examples, and creating zips.
101103
102104
Args:
103105
name: name of the example
106+
test: whether to run e2e tests
107+
test_tags: tags to add to e2e tests
104108
"""
105109
if name not in EXAMPLES:
106110
# buildifier: disable=print
@@ -119,6 +123,7 @@ def docs_example(name):
119123
env = {
120124
"BAZEL_EXAMPLE_BOILERPLATE_OUTPUT_PATH": "$(@D)",
121125
},
126+
data = [":files"],
122127
output_dir = True,
123128
tool = "//aio/tools/examples:example-boilerplate",
124129
)
@@ -134,6 +139,7 @@ def docs_example(name):
134139
],
135140
replace_prefixes = {
136141
"boilerplate": "",
142+
"aio/tools/examples/shared": "",
137143
},
138144
allow_overwrites = True,
139145
)
@@ -169,3 +175,38 @@ def docs_example(name):
169175
outs = outs,
170176
tool = "//aio/tools/example-zipper:generate-example-zip",
171177
)
178+
179+
if test:
180+
# These node_modules deps are symlinked into each example. These tree
181+
# artifact folder names must still be "node_modules" despite the symlink
182+
# being named node_modules. Otherwise, some deps will fail to resolve.
183+
node_modules_deps = {
184+
"local": "//aio/tools/examples/shared:local/node_modules",
185+
"npm": "//aio/tools/examples/shared:node_modules",
186+
}
187+
188+
for [node_modules_source, node_modules_label] in node_modules_deps.items():
189+
nodejs_test(
190+
name = "e2e_%s" % node_modules_source,
191+
data = [
192+
":%s" % name,
193+
YARN_LABEL,
194+
node_modules_label,
195+
"@aio_npm//@angular/dev-infra-private/bazel/browsers/chromium",
196+
],
197+
args = [
198+
"$(rootpath :%s)" % name,
199+
"$(rootpath %s)" % node_modules_label,
200+
"$(rootpath %s)" % YARN_LABEL,
201+
],
202+
configuration_env_vars = ["NG_BUILD_CACHE"],
203+
entry_point = "//aio/tools/examples:run-example-e2e",
204+
env = {
205+
"CHROME_BIN": "$(CHROMIUM)",
206+
"CHROMEDRIVER_BIN": "$(CHROMEDRIVER)",
207+
},
208+
toolchains = [
209+
"@aio_npm//@angular/dev-infra-private/bazel/browsers/chromium:toolchain_alias",
210+
],
211+
tags = test_tags,
212+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"tests": [
33
{"cmd": "yarn", "args": ["test", "--browsers=ChromeHeadless", "--no-watch"]},
4-
{"cmd": "yarn", "args": ["e2e", "--configuration=production", "--protractor-config=e2e/protractor-puppeteer.conf.js", "--no-webdriver-update", "--port={PORT}"]}
4+
{"cmd": "yarn", "args": ["e2e", "--configuration=production", "--protractor-config=e2e/protractor-bazel.conf.js", "--no-webdriver-update", "--port=0"]}
55
]
66
}

aio/content/examples/http/example-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"projectType": "testing",
33
"tests": [
44
{"cmd": "yarn", "args": ["test", "--browsers=ChromeHeadless", "--no-watch"]},
5-
{"cmd": "yarn", "args": ["e2e", "--configuration=production", "--protractor-config=e2e/protractor-puppeteer.conf.js", "--no-webdriver-update", "--port={PORT}"]}
5+
{"cmd": "yarn", "args": ["e2e", "--configuration=production", "--protractor-config=e2e/protractor-bazel.conf.js", "--no-webdriver-update", "--port=0"]}
66
]
77
}

aio/content/examples/i18n/example-config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"cmd": "yarn",
99
"args": [
1010
"e2e",
11-
"--protractor-config=e2e/protractor-puppeteer.conf.js",
11+
"--protractor-config=e2e/protractor-bazel.conf.js",
1212
"--no-webdriver-update",
13-
"--port={PORT}"
13+
"--port=0"
1414
]
1515
}
1616
]

aio/content/examples/ngcontainer/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ package(default_visibility = ["//visibility:public"])
44

55
docs_example(
66
name = "ngcontainer",
7+
test = False,
78
)

aio/content/examples/schematics-for-libraries/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ package(default_visibility = ["//visibility:public"])
44

55
docs_example(
66
name = "schematics-for-libraries",
7+
test = False,
78
)

aio/content/examples/service-worker-getting-started/example-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"projectType": "service-worker",
33
"tests": [
4-
{"cmd": "yarn", "args": ["e2e", "--protractor-config=e2e/protractor-puppeteer.conf.js", "--no-webdriver-update", "--port={PORT}"]},
4+
{"cmd": "yarn", "args": ["e2e", "--protractor-config=e2e/protractor-bazel.conf.js", "--no-webdriver-update", "--port=0"]},
55
{"cmd": "yarn", "args": ["build"]},
66
{"cmd": "node", "args": ["--eval", "assert(fs.existsSync('./dist/ngsw.json'), 'ngsw.json is missing')"]},
77
{"cmd": "node", "args": ["--eval", "assert(fs.existsSync('./dist/ngsw-worker.js'), 'ngsw-worker.js is missing')"]},

0 commit comments

Comments
 (0)