Skip to content

Commit fac1e58

Browse files
authored
run e2e tests under bazel (#24338)
* test: run legacy-cli e2e tests via bazel * fixup! test: run legacy-cli e2e tests via bazel * fixup! test: run legacy-cli e2e tests via bazel * fixup! test: run legacy-cli e2e tests via bazel
1 parent 7a37325 commit fac1e58

File tree

29 files changed

+627
-128
lines changed

29 files changed

+627
-128
lines changed

.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ build:snapshot --workspace_status_command="yarn -s ng-dev release build-env-stam
9090
build:snapshot --stamp
9191
build:snapshot --//:enable_snapshot_repo_deps
9292

93+
build:e2e --workspace_status_command="yarn -s ng-dev release build-env-stamp --mode=release"
94+
build:e2e --stamp
95+
test:e2e --test_timeout=3600
96+
9397
build:local --//:enable_package_json_tar_deps
9498

9599
###############################

.circleci/dynamic_config.yml

Lines changed: 169 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,27 @@ var_3_all_major: &all_nodeversion_major ['14', '16']
3535
# https://circleci.com/blog/deep-diving-into-circleci-workspaces/
3636
var_4: &workspace_location .
3737
# Filter to only release branches on a given job.
38-
var_5: &only_release_branches
38+
var_5_only_releases: &only_release_branches
3939
filters:
4040
branches:
4141
only:
4242
- main
4343
- /\d+\.\d+\.x/
44+
var_5_only_snapshots: &only_snapshot_branches
45+
filters:
46+
branches:
47+
only:
48+
- main
49+
# This is needed to run this steps on Renovate PRs that amend the snapshots package.json
50+
- /^pull\/.*/
4451

4552
var_6: &only_pull_requests
4653
filters:
4754
branches:
4855
only:
4956
- /pull\/\d+/
5057

58+
# All e2e test suites
5159
var_7: &all_e2e_subsets ['npm', 'esbuild', 'yarn']
5260

5361
# Executor Definitions
@@ -63,10 +71,20 @@ executors:
6371
working_directory: ~/ng
6472
resource_class: small
6573

74+
bazel-executor:
75+
parameters:
76+
nodeversion:
77+
type: string
78+
default: *default_nodeversion
79+
docker:
80+
- image: cimg/node:<< parameters.nodeversion >>-browsers
81+
working_directory: ~/ng
82+
resource_class: xlarge
83+
6684
windows-executor:
6785
# Same as https://circleci.com/orbs/registry/orb/circleci/windows, but named.
6886
working_directory: ~/ng
69-
resource_class: windows.medium
87+
resource_class: windows.large
7088
shell: powershell.exe -ExecutionPolicy Bypass
7189
machine:
7290
# Contents of this image:
@@ -116,7 +134,7 @@ commands:
116134
- initialize_env
117135
- run: nvm install 16.13
118136
- run: nvm use 16.13
119-
- run: npm install -g yarn@1.22.10
137+
- run: npm install -g yarn@1.22.10 @bazel/bazelisk@${BAZELISK_VERSION}
120138
- run: node --version
121139
- run: yarn --version
122140

@@ -126,6 +144,7 @@ commands:
126144
type: env_var_name
127145
default: CIRCLE_PROJECT_REPONAME
128146
steps:
147+
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
129148
- devinfra/setup-bazel-remote-exec:
130149
bazelrc: ./.bazelrc.user
131150

@@ -269,23 +288,24 @@ jobs:
269288
paths:
270289
- dist/_*.tgz
271290

272-
build-bazel-e2e:
273-
executor: action-executor
274-
resource_class: medium
291+
bazel-build:
292+
executor: bazel-executor
275293
steps:
276294
- custom_attach_workspace
277-
- run: yarn bazel build //tests/legacy-cli/...
295+
- setup_bazel_rbe
296+
- run:
297+
name: Bazel Build Packages
298+
command: yarn bazel build //...
299+
- fail_fast
278300

279-
unit-test:
280-
executor: action-executor
281-
resource_class: xlarge
301+
bazel-test:
302+
executor: bazel-executor
282303
parameters:
283304
nodeversion:
284305
type: string
285306
default: *default_nodeversion_major
286307
steps:
287308
- custom_attach_workspace
288-
- browser-tools/install-chrome
289309
- setup_bazel_rbe
290310
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
291311
- when:
@@ -311,6 +331,58 @@ jobs:
311331
no_output_timeout: 40m
312332
- fail_fast
313333

334+
bazel-e2e-tests:
335+
executor: bazel-executor
336+
parallelism: 8
337+
parameters:
338+
snapshots:
339+
type: boolean
340+
default: false
341+
subset:
342+
type: enum
343+
enum: *all_e2e_subsets
344+
default: 'npm'
345+
steps:
346+
- custom_attach_workspace
347+
- initialize_env
348+
- setup_bazel_rbe
349+
- run: mkdir /mnt/ramdisk/e2e
350+
- run:
351+
name: Execute CLI E2E Tests with << parameters.subset >>
352+
command: yarn bazel test --define=E2E_TEMP=/mnt/ramdisk/e2e --define=E2E_SHARD_TOTAL=${CIRCLE_NODE_TOTAL} --define=E2E_SHARD_INDEX=${CIRCLE_NODE_INDEX} --config=e2e //tests/legacy-cli:e2e<<# parameters.snapshots >>.snapshots<</ parameters.snapshots >>.<< parameters.subset >>
353+
no_output_timeout: 40m
354+
- store_artifacts:
355+
path: dist/testlogs/tests/legacy-cli/e2e.<< parameters.subset >>
356+
- store_test_results:
357+
path: dist/testlogs/tests/legacy-cli/e2e.<< parameters.subset >>
358+
- fail_fast
359+
360+
bazel-test-browsers:
361+
executor: bazel-executor
362+
steps:
363+
- custom_attach_workspace
364+
- initialize_env
365+
- setup_bazel_rbe
366+
- run:
367+
name: Initialize Saucelabs
368+
command: setSecretVar SAUCE_ACCESS_KEY $(echo $SAUCE_ACCESS_KEY | rev)
369+
- run:
370+
name: Start Saucelabs Tunnel
371+
command: ./scripts/saucelabs/start-tunnel.sh
372+
background: true
373+
# Waits for the Saucelabs tunnel to be ready. This ensures that we don't run tests
374+
# too early without Saucelabs not being ready.
375+
- run: ./scripts/saucelabs/wait-for-tunnel.sh
376+
- run:
377+
name: E2E Saucelabs Tests
378+
command: yarn bazel test --config=saucelabs //tests/legacy-cli:e2e.saucelabs
379+
- run: ./scripts/saucelabs/stop-tunnel.sh
380+
- store_artifacts:
381+
path: dist/testlogs/tests/legacy-cli/e2e.saucelabs
382+
- store_test_results:
383+
path: dist/testlogs/tests/legacy-cli/e2e.saucelabs
384+
- fail_fast
385+
314386
snapshot_publish:
315387
executor: action-executor
316388
resource_class: medium
@@ -375,6 +447,48 @@ jobs:
375447
node tests\legacy-cli\run_e2e.js --nb-shards=$env:CIRCLE_NODE_TOTAL --shard=$env:CIRCLE_NODE_INDEX --tmpdir=X:/ramdisk/e2e-main --ignore="tests/misc/browsers.ts"
376448
- fail_fast
377449

450+
bazel-e2e-cli-win:
451+
executor: windows-executor
452+
parallelism: 12
453+
steps:
454+
- checkout
455+
- rebase_pr_win
456+
- setup_windows
457+
- restore_cache:
458+
keys:
459+
- *cache_key_win
460+
- run:
461+
# We use Arsenal Image Mounter (AIM) instead of ImDisk because of: https://github.com/nodejs/node/issues/6861
462+
# Useful resources for AIM: http://reboot.pro/index.php?showtopic=22068
463+
name: 'Arsenal Image Mounter (RAM Disk)'
464+
command: |
465+
pwsh ./.circleci/win-ram-disk.ps1
466+
- run: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
467+
- save_cache:
468+
key: *cache_key_win
469+
paths:
470+
- ~/.cache/yarn
471+
# Path where Arsenal Image Mounter files are downloaded.
472+
# Must match path in .circleci/win-ram-disk.ps1
473+
- ./aim
474+
- run:
475+
name: Execute E2E Tests
476+
environment:
477+
# Required by `yarn ng-dev`
478+
# See https://github.com/angular/angular/issues/46858
479+
PWD: .
480+
command: |
481+
mkdir X:/ramdisk/e2e
482+
bazel test --define=E2E_TEMP=X:/ramdisk/e2e --define=E2E_SHARD_TOTAL=$env:CIRCLE_NODE_TOTAL --define=E2E_SHARD_INDEX=$env:CIRCLE_NODE_INDEX --config=e2e //tests/legacy-cli:e2e.npm
483+
# This timeout provides time for the actual tests to timeout and report status
484+
# instead of CircleCI stopping the job without test failure information.
485+
no_output_timeout: 40m
486+
- fail_fast
487+
- store_artifacts:
488+
path: dist/testlogs/tests/legacy-cli/e2e.npm
489+
- store_test_results:
490+
path: dist/testlogs/tests/legacy-cli/e2e.npm
491+
378492
workflows:
379493
version: 2
380494
default_workflow:
@@ -429,44 +543,73 @@ workflows:
429543
snapshots: true
430544
pre-steps:
431545
- when:
546+
# Don't run snapshot E2E's unless it's on the main branch or the snapshots file has been updated.
432547
condition:
433548
and:
434549
- not:
435550
equal: [main, << pipeline.git.branch >>]
436551
- not: << pipeline.parameters.snapshot_changed >>
437552
steps:
438-
# Don't run snapshot E2E's unless it's on the main branch or the snapshots file has been updated.
439553
- run: circleci-agent step halt
440554
requires:
441555
- build
442-
filters:
443-
branches:
444-
only:
445-
- main
446-
# This is needed to run this steps on Renovate PRs that amend the snapshots package.json
447-
- /^pull\/.*/
556+
<<: *only_snapshot_branches
448557

449558
# Bazel jobs
450559
# These jobs only really depend on Setup, but the build job is very quick to run (~35s) and
451560
# will catch any build errors before proceeding to the more lengthy and resource intensive
452561
# Bazel jobs.
453-
- unit-test:
562+
- bazel-test:
454563
name: test-node<< matrix.nodeversion >>
455564
matrix:
456565
parameters:
457566
nodeversion: *all_nodeversion_major
458567
requires:
459-
- build
460-
461-
# Compile the e2e tests with bazel to ensure the non-runtime typescript
462-
# compilation completes succesfully.
463-
- build-bazel-e2e:
464-
requires:
465-
- build
568+
- bazel-build
466569

467570
# Windows jobs
468571
- e2e-cli-win
469572

573+
- bazel-e2e-cli-win
574+
575+
# Bazel jobs
576+
- bazel-build:
577+
requires:
578+
- setup
579+
580+
- bazel-e2e-tests:
581+
name: bazel-e2e-cli-<< matrix.subset >>
582+
matrix:
583+
parameters:
584+
subset: *all_e2e_subsets
585+
snapshots: false
586+
requires:
587+
- bazel-build
588+
589+
- bazel-e2e-tests:
590+
name: bazel-e2e-snapshots-<< matrix.subset >>
591+
matrix:
592+
parameters:
593+
subset: *all_e2e_subsets
594+
snapshots: true
595+
pre-steps:
596+
- when:
597+
# Don't run snapshot E2E's unless it's on the main branch or the snapshots file has been updated.
598+
condition:
599+
and:
600+
- not:
601+
equal: [main, << pipeline.git.branch >>]
602+
- not: << pipeline.parameters.snapshot_changed >>
603+
steps:
604+
- run: circleci-agent step halt
605+
requires:
606+
- bazel-build
607+
<<: *only_snapshot_branches
608+
609+
- bazel-test-browsers:
610+
requires:
611+
- bazel-build
612+
470613
# Publish jobs
471614
- snapshot_publish:
472615
<<: *only_release_branches

.circleci/env.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ source $BASH_ENV;
3636

3737
# Disable husky.
3838
setPublicVar HUSKY 0
39+
40+
# Expose the Bazelisk version. We need to run Bazelisk globally since Windows has problems launching
41+
# Bazel from a node modules directoy that might be modified by the Bazel Yarn install then.
42+
setPublicVar BAZELISK_VERSION \
43+
"$(cd ${PROJECT_ROOT}; node -p 'require("./package.json").devDependencies["@bazel/bazelisk"]')"

.circleci/win-ram-disk.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ if (-not (Test-Path -Path $aimContents)) {
2626
./aim/cli/x64/aim_ll.exe --install ./aim/drivers
2727

2828
# Setup RAM disk mount. Same parameters as ImDisk
29+
# Ensure size is large enough to support the bazel 'shard_count's such as for e2e tests.
2930
# See: https://support.circleci.com/hc/en-us/articles/4411520952091-Create-a-windows-RAM-disk
30-
./aim/cli/x64/aim_ll.exe -a -s 5G -m X: -p "/fs:ntfs /q /y"
31+
./aim/cli/x64/aim_ll.exe -a -s 12G -m X: -p "/fs:ntfs /q /y"

BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
55
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
6+
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
67

78
package(default_visibility = ["//visibility:public"])
89

@@ -16,6 +17,14 @@ exports_files([
1617
"package.json",
1718
])
1819

20+
# Files required by e2e tests
21+
copy_to_bin(
22+
name = "config-files",
23+
srcs = [
24+
"package.json",
25+
],
26+
)
27+
1928
# Detect if the build is running under --stamp
2029
config_setting(
2130
name = "stamp",

WORKSPACE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,14 @@ nodejs_register_toolchains(
9898
name = "node16",
9999
node_version = "16.13.1",
100100
)
101+
102+
register_toolchains(
103+
"@npm//@angular/build-tooling/bazel/git-toolchain:git_linux_toolchain",
104+
"@npm//@angular/build-tooling/bazel/git-toolchain:git_macos_x86_toolchain",
105+
"@npm//@angular/build-tooling/bazel/git-toolchain:git_macos_arm64_toolchain",
106+
"@npm//@angular/build-tooling/bazel/git-toolchain:git_windows_toolchain",
107+
)
108+
109+
load("@npm//@angular/build-tooling/bazel/browsers:browser_repositories.bzl", "browser_repositories")
110+
111+
browser_repositories()

docs/DEVELOPER.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ You can find more info about debugging [tests with Bazel in the docs.](https://g
8585
- Compile the packages being tested: `yarn build`
8686
- Run all tests: `node tests/legacy-cli/run_e2e.js`
8787
- Run a subset of the tests: `node tests/legacy-cli/run_e2e.js tests/legacy-cli/e2e/tests/i18n/ivy-localize-*`
88-
- Run on a custom set of npm packages (tar files): `node tests/legacy-cli/run_e2e.js --package _angular_cli.tgz _angular_create.tgz dist/*.tgz ...`
88+
- Run on a custom set of npm packages (tar files): `node tests/legacy-cli/run_e2e.js --package _angular_cli.tgz _angular_create.tgz dist/*.tgz tests/legacy-cli/e2e/tests/i18n/ivy-localize-*`
8989

9090
When running the debug commands, Node will stop and wait for a debugger to attach.
9191
You can attach your IDE to the debugger to stop on breakpoints and step through the code. Also, see [IDE Specific Usage](#ide-specific-usage) for a

packages/angular/cli/src/utilities/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Version {
2323
}
2424
}
2525

26-
// TODO: Convert this to use build-time version stamping after flipping the build script to use bazel
26+
// TODO(bazel): Convert this to use build-time version stamping after flipping the build script to use bazel
2727
// export const VERSION = new Version('0.0.0-PLACEHOLDER');
2828
export const VERSION = new Version(
2929
(

0 commit comments

Comments
 (0)