Skip to content

Commit

Permalink
build: WIP: run e2e legacy-cli tests under bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed May 9, 2022
1 parent efa840e commit 52f1c3b
Show file tree
Hide file tree
Showing 31 changed files with 2,602 additions and 135 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Expand Up @@ -148,3 +148,4 @@ try-import .bazelrc.user
# Enable runfiles even on Windows.
# Architect resolves output files from data files, and this isn't possible without runfile support.
test --enable_runfiles
build --enable_runfiles
46 changes: 42 additions & 4 deletions .circleci/config.yml
Expand Up @@ -98,6 +98,8 @@ commands:
- run:
name: 'Setup bazel RBE remote execution'
command: |
sudo npm install --global @bazel/bazelisk
touch .bazelrc.user;
# We need ensure that the same default digest is used for encoding and decoding
# with openssl. Openssl versions might have different default digests which can
Expand Down Expand Up @@ -225,6 +227,36 @@ jobs:
node ./tests/legacy-cli/run_e2e --nb-shards=${CIRCLE_NODE_TOTAL} --shard=${CIRCLE_NODE_INDEX} <<# parameters.snapshots >>--ng-snapshots<</ parameters.snapshots >> --esbuild --tmpdir=/mnt/ramdisk/e2e-esbuild --glob="{tests/basic/**,tests/build/prod-build.ts}" --ignore="tests/basic/{environment,rebuild,serve,scripts-array}.ts"
- fail_fast

e2e-cli-bazel:
parameters:
nodeversion:
type: string
default: *default_nodeversion
snapshots:
type: boolean
default: false
executor:
name: test-executor
steps:
- custom_attach_workspace
- browser-tools/install-chrome
- setup_bazel_rbe
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
- run:
name: Initialize Environment
command: |
./.circleci/env.sh
- run:
name: Execute CLI E2E Tests (bazel)
command: bazel run //tests/legacy-cli:e2e
- run:
name: Execute CLI E2E Tests Subset with Yarn (bazel)
command: bazel run //tests/legacy-cli:e2e.yarn
- run:
name: Execute CLI E2E Tests Subset with esbuild builder (bazel)
command: bazel run //tests/legacy-cli:e2e.esbuild
- fail_fast

test-browsers:
executor:
name: test-executor
Expand Down Expand Up @@ -372,13 +404,19 @@ workflows:
requires:
- build

# Bazel jobs
# These jobs only really depend on Setup, but the build job is very quick to run (~35s) and
# will catch any build errors before proceeding to the more lengthy and resource intensive
# Bazel jobs.
- test:
requires:
- build
- setup
- e2e-cli-bazel:
nodeversion: '14.15'
requires:
- setup
- e2e-cli-bazel:
name: e2e-cli-node-16
nodeversion: '16.10'
requires:
- setup

# Windows jobs
- e2e-cli-win:
Expand Down
2 changes: 2 additions & 0 deletions BUILD.bazel
Expand Up @@ -13,7 +13,9 @@ exports_files([
"tsconfig.json", # @external
"tsconfig-test.json", # @external
"tsconfig-build.json", # @external
".monorepo.json",
"package.json",
".gitignore",
])

# Detect if the build is running under --stamp
Expand Down
15 changes: 15 additions & 0 deletions lib/BUILD.bazel
@@ -0,0 +1,15 @@
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "lib",
srcs = ["packages.ts"],
data = [
"//:.monorepo.json",
],
visibility = ["//visibility:public"],
deps = [
"//packages/angular_devkit/core",
"@npm//@types/node",
"@npm//typescript",
],
)
4 changes: 4 additions & 0 deletions lib/bootstrap-local.js
Expand Up @@ -20,6 +20,10 @@ const os = require('os');
const path = require('path');
const ts = require('typescript');

if (process.env.BAZEL_TARGET) {
throw new Error(`${__filename} should not be used when executing under bazel`);
}

const tmpRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'angular-devkit-'));

debugLocal('starting bootstrap local');
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -171,6 +171,7 @@
"minimatch": "5.0.1",
"ng-packagr": "14.0.0-next.10",
"node-fetch": "^2.2.0",
"npm": "6.14.15",
"npm-package-arg": "9.0.2",
"open": "8.4.0",
"ora": "5.4.1",
Expand Down Expand Up @@ -219,6 +220,7 @@
"webpack-subresource-integrity": "5.1.0",
"yargs": "17.4.1",
"yargs-parser": "21.0.1",
"yarn": "^1.22.18",
"zone.js": "^0.11.3"
}
}
Expand Up @@ -17,5 +17,8 @@ ts_library(
name = "TypeScript",
srcs = ["lib/typescript.d.ts"],
data = ["lib/typescript.js"],
visibility = ["//packages/schematics/angular:__subpackages__"],
visibility = [
"//packages/schematics/angular:__subpackages__",
"//tests/legacy-cli:__subpackages__",
],
)
173 changes: 173 additions & 0 deletions tests/legacy-cli/BUILD.bazel
@@ -0,0 +1,173 @@
load(":cli_integration_test.bzl", "cli_integration_test")
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "runner",
testonly = True,
srcs = glob(["**/*.ts"]),
data = [
"verdaccio.yaml",
"verdaccio_auth.yaml",
"//tests/legacy-cli/e2e/assets",
],
deps = [
"//packages/angular_devkit/core",
"//packages/angular_devkit/core/node",
"//tests/legacy-cli/e2e/utils",
"@npm//@types/glob",
"@npm//@types/yargs-parser",
"@npm//ansi-colors",
"@npm//yargs-parser",

# Loaded dynamically at runtime, not compiletime deps
"//tests/legacy-cli/e2e/setup",
"//tests/legacy-cli/e2e/tests",
],
)

# TODO(bazel): run e2e tests on node14+16, npm+yarn+esbuild

cli_integration_test(
name = "e2e",
data = [
# Test runner
":runner",

# Runtime deps
# TODO: not needed when no longer compiling inline?
"//:.gitignore",
"//:package.json",
"//:tsconfig.json",

# Runtime deps of everything
# TODO: do this dynamically within cli_integration_test, for now for simplicity
# just put every potential runtime dep.
#
# > cat `find packages/ | grep BUILD` | grep "@npm" | grep -v "@types" | sed -e 's/ //g' | sed -e 's/#.*//g' | sort -u
"@npm//@ampproject/remapping",
"@npm//@angular/animations",
"@npm//@angular/common",
"@npm//@angular/compiler",
"@npm//@angular/compiler-cli",
"@npm//@angular/core",
"@npm//@angular/localize",
"@npm//@angular/material",
"@npm//@angular/platform-browser",
"@npm//@angular/platform-browser-dynamic",
"@npm//@angular/platform-server",
"@npm//@angular/router",
"@npm//@angular/service-worker",
"@npm//@babel/core",
"@npm//@babel/generator",
"@npm//@babel/helper-annotate-as-pure",
"@npm//@babel/plugin-proposal-async-generator-functions",
"@npm//@babel/plugin-transform-async-to-generator",
"@npm//@babel/plugin-transform-runtime",
"@npm//@babel/preset-env",
"@npm//@babel/runtime",
"@npm//@babel/template",
"@npm//@discoveryjs/json-ext",
"@npm//@yarnpkg/lockfile",
"@npm//ajv",
"@npm//ajv-formats",
"@npm//ansi-colors",
"@npm//babel-loader",
"@npm//babel-plugin-istanbul",
"@npm//bootstrap",
"@npm//browserslist",
"@npm//cacache",
"@npm//chokidar",
"@npm//copy-webpack-plugin",
"@npm//critters",
"@npm//css-loader",
"@npm//esbuild",
"@npm//esbuild-wasm",
"@npm//express",
"@npm//font-awesome",
"@npm//glob",
"@npm//http-proxy",
"@npm//https-proxy-agent",
"@npm//ini",
"@npm//inquirer",
"@npm//jasmine",
"@npm//jasmine-spec-reporter",
"@npm//jquery",
"@npm//jsonc-parser",
"@npm//karma",
"@npm//karma-chrome-launcher",
"@npm//karma-coverage",
"@npm//karma-jasmine",
"@npm//karma-jasmine-html-reporter",
"@npm//karma-source-map-support",
"@npm//less",
"@npm//less-loader",
"@npm//license-webpack-plugin",
"@npm//loader-utils",
"@npm//magic-string",
"@npm//mini-css-extract-plugin",
"@npm//minimatch",
"@npm//ng-packagr",
"@npm//node-fetch",
"@npm//npm",
"@npm//npm-package-arg",
"@npm//open",
"@npm//ora",
"@npm//pacote",
"@npm//parse5-html-rewriting-stream",
"@npm//pidtree",
"@npm//pidusage",
"@npm//piscina",
"@npm//popper.js",
"@npm//postcss",
"@npm//postcss-import",
"@npm//postcss-loader",
"@npm//postcss-preset-env",
"@npm//prettier",
"@npm//protractor",
"@npm//puppeteer",
"@npm//regenerator-runtime",
"@npm//resolve-url-loader",
"@npm//rxjs",
"@npm//sass",
"@npm//sass-loader",
"@npm//semver",
"@npm//source-map",
"@npm//source-map-loader",
"@npm//source-map-support",
"@npm//stylus",
"@npm//stylus-loader",
"@npm//symbol-observable",
"@npm//terser",
"@npm//text-table",
"@npm//tree-kill",
"@npm//ts-node",
"@npm//tslib",
"@npm//typescript",
"@npm//webpack",
"@npm//webpack-dev-middleware",
"@npm//webpack-dev-server",
"@npm//webpack-merge",
"@npm//webpack-subresource-integrity",
"@npm//yargs",
"@npm//yargs-parser",
"@npm//yarn",
"@npm//zone.js",
],
entry_point = ":bazel_runner.js",
packages = [
# bazel query --output=label "kind('pkg_npm', //packages/...)"
"//packages/schematics/angular:npm_package",
"//packages/ngtools/webpack:npm_package",
"//packages/angular_devkit/schematics_cli:npm_package",
"//packages/angular_devkit/schematics:npm_package",
"//packages/angular_devkit/core:npm_package",
"//packages/angular_devkit/build_webpack:npm_package",
"//packages/angular_devkit/build_angular:npm_package",
# this is private so don't use here
# "//packages/angular_devkit/benchmark:npm_package",
"//packages/angular_devkit/architect_cli:npm_package",
"//packages/angular_devkit/architect:npm_package",
"//packages/angular/pwa:npm_package",
"//packages/angular/cli:npm_package",
],
)
29 changes: 29 additions & 0 deletions tests/legacy-cli/bazel_e2e_setup.ts
@@ -0,0 +1,29 @@
'use strict';

import { join } from 'path';

import { IS_BAZEL, setPackages } from './e2e/utils/bazel';
if (!IS_BAZEL) {
throw new Error(`${__filename} must be invoked via bazel`);
}

// When run via bazel the extra argument is a config file containing an array of test configs.
// Read the config file and metadata about each package.
const packages = require(process.argv[2]).map((pkg: any) => {
// The path relative to this file (relative to the BUILD compiling it);
const pkgPath = pkg.path;

// require() using relative path
const packageJSON = require(`${pkgPath}/package.json`);

return {
name: packageJSON.name,
version: packageJSON.version,
path: join(__dirname, pkgPath),
};
});

console.log('BAZEL_PACKAGES: ', packages);

// Globally persist the packages
setPackages(packages);
3 changes: 3 additions & 0 deletions tests/legacy-cli/bazel_runner.js
@@ -0,0 +1,3 @@
'use strict';
require('./bazel_e2e_setup');
require('./e2e_runner');

0 comments on commit 52f1c3b

Please sign in to comment.