Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 853c1e7

Browse files
gregmagolanalan-agius4
authored andcommitted
build: run integration tests with bazel
1 parent 47b42e6 commit 853c1e7

File tree

21 files changed

+1469
-113
lines changed

21 files changed

+1469
-113
lines changed

.bazelignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.git
22
dist
33
node_modules
4-
integration
4+
integration/clover/node_modules
5+
integration/common-engine/dist
6+
integration/common-engine/node_modules
7+
integration/express-engine-ivy/node_modules
8+
integration/express-engine-hybrid/node_modules

.circleci/config.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ jobs:
7474
resource_class: xlarge
7575
steps:
7676
- custom_attach_workspace
77+
- browser-tools/install-chrome
7778
- copy-bazel-config
79+
# Install rsync which is used by the integration test launcher bash script
80+
- run: sudo apt-get update -y && sudo apt-get install -y rsync
7881
- run: yarn bazel test //...
7982
- run: scripts/build-modules-dist.sh
80-
8183
- save_cache:
8284
key: *cache_key
8385
paths:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ lerna-debug.log
3333
/lib/
3434
integration/**/yarn.lock
3535
integration/**/built/
36+
integration/**/.angular/
3637
.yarn_local_cache
3738
bazel-bin
3839
bazel-genfiles

BUILD.bazel

+44
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,47 @@ config_setting(
55
name = "stamp",
66
values = {"stamp": "true"},
77
)
8+
9+
config_setting(
10+
name = "linux_x86_64",
11+
constraint_values = [
12+
"@platforms//os:linux",
13+
"@platforms//cpu:x86_64",
14+
],
15+
)
16+
17+
config_setting(
18+
name = "linux_arm64",
19+
constraint_values = [
20+
"@platforms//os:linux",
21+
"@platforms//cpu:arm64",
22+
],
23+
)
24+
25+
config_setting(
26+
name = "macos_x86_64",
27+
constraint_values = [
28+
"@platforms//os:macos",
29+
"@platforms//cpu:x86_64",
30+
],
31+
)
32+
33+
config_setting(
34+
name = "macos_arm64",
35+
constraint_values = [
36+
"@platforms//os:macos",
37+
"@platforms//cpu:arm64",
38+
],
39+
)
40+
41+
filegroup(
42+
name = "node_files",
43+
srcs = select({
44+
# We're assuming the target platform & the execution platform as the same here
45+
"//:linux_x86_64": ["@nodejs_linux_amd64//:node_files"],
46+
"//:linux_arm64": ["@nodejs_linux_arm64//:node_files"],
47+
"//:macos_x86_64": ["@nodejs_darwin_amd64//:node_files"],
48+
# Need a minimum of Node 16 for M1 support
49+
# "//:macos_arm64": ["@nodejs_darwin_arm64//:node_files"],
50+
}),
51+
)

WORKSPACE

+12
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,24 @@ load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
3939

4040
yarn_install(
4141
name = "npm",
42+
all_node_modules_target_name = "node_modules_all",
4243
# Currently disabled due to:
4344
# 1. Incompatibilites with the `ts_library` rule.
4445
exports_directories_only = False,
46+
manual_build_file_contents = """\
47+
# Used by integration tests
48+
filegroup(
49+
name = "node_modules_files",
50+
srcs = ["node_modules"],
51+
)
52+
""",
4553
package_json = "//:package.json",
4654
# We prefer to symlink the `node_modules` to only maintain a single install.
4755
# See https://github.com/angular/dev-infra/pull/446#issuecomment-1059820287 for details.
4856
symlink_node_modules = True,
4957
yarn_lock = "//:yarn.lock",
5058
)
59+
60+
load("@npm//@angular/build-tooling/bazel/browsers:browser_repositories.bzl", "browser_repositories")
61+
62+
browser_repositories()

integration/clover/BUILD.bazel

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sh_test(
2+
name = "test",
3+
srcs = ["test.sh"],
4+
args = ["$(NODE_PATH)"],
5+
data = glob(
6+
["**"],
7+
exclude = ["BUILD.bazel"],
8+
) + [
9+
"@npm//:node_modules_files",
10+
"//modules/builders:npm_package",
11+
"//modules/common:npm_package_runfiles",
12+
"//:node_files",
13+
],
14+
# e2e test runner creates a tmpdir sandbox itself so no point in double sandboxing
15+
tags = ["local"],
16+
toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
17+
)

integration/clover/test.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset
3+
4+
# put node on the path
5+
node_path=$(dirname "$1")
6+
if [[ "$node_path" == external/* ]]; then
7+
node_path="${node_path:9}"
8+
fi
9+
PATH="$PWD/../$node_path:$PATH"
10+
11+
tmpdir=$(mktemp -d)
12+
13+
echo "Copying e2e test files to tmpdir sandbox $tmpdir"
14+
mkdir -p "$tmpdir/integration/clover"
15+
rsync -a -L integration/clover/ "$tmpdir/integration/clover" --exclude node_modules
16+
rsync -a ../npm/node_modules/ "$tmpdir/node_modules"
17+
mkdir -p "$tmpdir/dist/modules-dist"
18+
rsync -a -L modules/common/npm_package/ "$tmpdir/dist/modules-dist/common" --exclude node_modules
19+
rsync -a -L modules/builders/npm_package/ "$tmpdir/dist/modules-dist/builders" --exclude node_modules
20+
21+
cd "$tmpdir/integration/clover"
22+
23+
echo "Running e2e test yarn install"
24+
yarn --mutex network cache clean @nguniversal/common
25+
yarn --mutex network cache clean @nguniversal/builders
26+
yarn --mutex network install
27+
28+
echo "Running e2e test"
29+
yarn test

integration/common-engine/BUILD.bazel

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
sh_test(
2+
name = "test",
3+
srcs = ["test.sh"],
4+
args = ["$(NODE_PATH)"],
5+
data = glob(
6+
["**"],
7+
exclude = [
8+
"BUILD.bazel",
9+
"node_modules",
10+
"dist",
11+
],
12+
) + [
13+
"@npm//:node_modules_files",
14+
"//modules/builders:npm_package",
15+
"//modules/common:npm_package_runfiles",
16+
"//:node_files",
17+
] + select({
18+
# We're assuming the target platform & the execution platform as the same here
19+
"//:linux_x86_64": [
20+
"@org_chromium_chromedriver_linux_x64//:metadata",
21+
"@org_chromium_chromium_linux_x64//:chrome-linux",
22+
],
23+
# There are no Chromimum browsers configured for Linux arm64 yet in dev-infra
24+
# https://github.com/angular/dev-infra/blob/main/bazel/browsers/chromium/chromium.bzl
25+
# "//:linux_arm64": [
26+
# "@org_chromium_chromedriver_linux_arm64//:metadata",
27+
# "@org_chromium_chromium_linux_arm64//:chrome-linux",
28+
# ],
29+
"//:macos_x86_64": [
30+
"@org_chromium_chromedriver_macos_x64//:metadata",
31+
"@org_chromium_chromium_macos_x64//:chrome-mac",
32+
],
33+
"//:macos_arm64": [
34+
"@org_chromium_chromedriver_macos_arm64//:metadata",
35+
"@org_chromium_chromium_macos_arm64//:chrome-mac",
36+
],
37+
}),
38+
env = {
39+
"CHROME_BIN": "$(CHROMIUM)",
40+
"CHROMEDRIVER_BIN": "$(CHROMEDRIVER)",
41+
},
42+
# e2e test runner creates a tmpdir sandbox itself so no point in double sandboxing
43+
tags = ["local"],
44+
toolchains = [
45+
"@nodejs_toolchains//:resolved_toolchain",
46+
"@npm//@angular/build-tooling/bazel/browsers/chromium:toolchain_alias",
47+
],
48+
)

integration/common-engine/e2e/protractor.conf.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@
33
// https://github.com/angular/protractor/blob/master/lib/config.ts
44

55
const { SpecReporter } = require('jasmine-spec-reporter');
6+
const path = require('path');
7+
8+
const isBazel = !!process.env['TEST_TARGET'];
69

710
/**
811
* @type { import("protractor").Config }
912
*/
10-
exports.config = {
13+
const config = {
1114
allScriptsTimeout: 11000,
1215
specs: ['./src/**/*.e2e-spec.ts'],
1316
capabilities: {
1417
browserName: 'chrome',
1518
chromeOptions: {
16-
args: ['--headless'],
17-
binary: require('puppeteer').executablePath(),
19+
binary: isBazel
20+
? path.resolve(process.env.CHROME_BIN)
21+
: require('puppeteer').executablePath(),
22+
// See /integration/README.md#browser-tests for more info on these args
23+
args: [
24+
'--no-sandbox',
25+
'--headless',
26+
'--disable-gpu',
27+
'--disable-dev-shm-usage',
28+
'--hide-scrollbars',
29+
'--mute-audio',
30+
],
1831
},
1932
},
2033
directConnect: true,
@@ -32,3 +45,9 @@ exports.config = {
3245
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
3346
},
3447
};
48+
49+
if (isBazel) {
50+
config.chromeDriver = path.resolve(process.env.CHROMEDRIVER_BIN);
51+
}
52+
53+
exports.config = config;

integration/common-engine/test.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset
3+
4+
# put node on the path
5+
node_path=$(dirname "$1")
6+
if [[ "$node_path" == external/* ]]; then
7+
node_path="${node_path:9}"
8+
fi
9+
PATH="$PWD/../$node_path:$PATH"
10+
11+
tmpdir=$(mktemp -d)
12+
13+
export CHROME_BIN="$PWD/$CHROME_BIN"
14+
export CHROMEDRIVER_BIN="$PWD/$CHROMEDRIVER_BIN"
15+
16+
echo "Copying e2e test files to tmpdir sandbox $tmpdir"
17+
mkdir -p "$tmpdir/integration/common-engine"
18+
rsync -a -L integration/common-engine/ "$tmpdir/integration/common-engine" --exclude node_modules
19+
rsync -a ../npm/node_modules/ "$tmpdir/node_modules"
20+
mkdir -p "$tmpdir/dist/modules-dist"
21+
rsync -a -L modules/common/npm_package/ "$tmpdir/dist/modules-dist/common" --exclude node_modules
22+
rsync -a -L modules/builders/npm_package/ "$tmpdir/dist/modules-dist/builders" --exclude node_modules
23+
24+
cd "$tmpdir/integration/common-engine"
25+
26+
echo "Running e2e test yarn install"
27+
yarn --mutex network cache clean @nguniversal/common
28+
yarn --mutex network cache clean @nguniversal/builders
29+
yarn --mutex network install
30+
31+
echo "Running e2e test"
32+
yarn test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
sh_test(
2+
name = "test",
3+
srcs = ["test.sh"],
4+
args = ["$(NODE_PATH)"],
5+
data = glob(
6+
["**"],
7+
exclude = [
8+
"BUILD.bazel",
9+
"node_modules",
10+
"dist",
11+
],
12+
) + [
13+
"@npm//:node_modules_files",
14+
"//modules/builders:npm_package",
15+
"//modules/common:npm_package_runfiles",
16+
"//modules/express-engine:npm_package_runfiles",
17+
"//:node_files",
18+
] + select({
19+
# We're assuming the target platform & the execution platform as the same here
20+
"//:linux_x86_64": [
21+
"@org_chromium_chromedriver_linux_x64//:metadata",
22+
"@org_chromium_chromium_linux_x64//:chrome-linux",
23+
],
24+
# There are no Chromimum browsers configured for Linux arm64 yet in dev-infra
25+
# https://github.com/angular/dev-infra/blob/main/bazel/browsers/chromium/chromium.bzl
26+
# "//:linux_arm64": [
27+
# "@org_chromium_chromedriver_linux_arm64//:metadata",
28+
# "@org_chromium_chromium_linux_arm64//:chrome-linux",
29+
# ],
30+
"//:macos_x86_64": [
31+
"@org_chromium_chromedriver_macos_x64//:metadata",
32+
"@org_chromium_chromium_macos_x64//:chrome-mac",
33+
],
34+
"//:macos_arm64": [
35+
"@org_chromium_chromedriver_macos_arm64//:metadata",
36+
"@org_chromium_chromium_macos_arm64//:chrome-mac",
37+
],
38+
}),
39+
env = {
40+
"CHROME_BIN": "$(CHROMIUM)",
41+
"CHROMEDRIVER_BIN": "$(CHROMEDRIVER)",
42+
},
43+
# e2e test runner creates a tmpdir sandbox itself so no point in double sandboxing
44+
tags = ["local"],
45+
toolchains = [
46+
"@nodejs_toolchains//:resolved_toolchain",
47+
"@npm//@angular/build-tooling/bazel/browsers/chromium:toolchain_alias",
48+
],
49+
)

integration/express-engine-ivy-hybrid/e2e/protractor.conf.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@
33
// https://github.com/angular/protractor/blob/master/lib/config.ts
44

55
const { SpecReporter } = require('jasmine-spec-reporter');
6-
const { exec, execSync } = require('child_process');
7-
let serverDaemon;
6+
const path = require('path');
7+
8+
const isBazel = !!process.env['TEST_TARGET'];
89

910
/**
1011
* @type { import("protractor").Config }
1112
*/
12-
exports.config = {
13+
const config = {
1314
allScriptsTimeout: 11000,
1415
specs: ['./src/**/*.e2e-spec.ts'],
1516
capabilities: {
1617
browserName: 'chrome',
1718
chromeOptions: {
18-
args: ['--headless'],
19-
binary: require('puppeteer').executablePath(),
19+
binary: isBazel
20+
? path.resolve(process.env.CHROME_BIN)
21+
: require('puppeteer').executablePath(),
22+
// See /integration/README.md#browser-tests for more info on these args
23+
args: [
24+
'--no-sandbox',
25+
'--headless',
26+
'--disable-gpu',
27+
'--disable-dev-shm-usage',
28+
'--hide-scrollbars',
29+
'--mute-audio',
30+
],
2031
},
2132
},
2233
directConnect: true,
@@ -34,3 +45,9 @@ exports.config = {
3445
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
3546
},
3647
};
48+
49+
if (isBazel) {
50+
config.chromeDriver = path.resolve(process.env.CHROMEDRIVER_BIN);
51+
}
52+
53+
exports.config = config;

0 commit comments

Comments
 (0)