Skip to content

Commit 83ddb01

Browse files
gregmagolanatscott
authored andcommitted
build: run bazel tests on CI and generate bazel build dist/npm_bazel folder (#1754)
Next steps after this are testing of all local workflows and cut-over to a bazel built release. Will co-ordinate with Angular team on this. (cherry picked from commit 4007657)
1 parent b66d51a commit 83ddb01

File tree

16 files changed

+163
-77
lines changed

16 files changed

+163
-77
lines changed

.bazelrc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
1-
# Enable debugging tests with --config=debug
2-
test:debug --test_arg=--node_options=--inspect-brk --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results
1+
# ======================================================================================================================
2+
# Support for debugging Node.js tests
3+
# Use `--config=debug` to enable these settings
4+
5+
# Use bazel run with `--config=debug` to turn on the NodeJS inspector agent.
6+
# The node process will break before user code starts and wait for the debugger to connect.
7+
# Pass the --inspect-brk option to all tests which enables the node inspector agent.
8+
# See https://nodejs.org/de/docs/guides/debugging-getting-started/#command-line-options for more details.
9+
run:debug -- --node_options=--inspect-brk
10+
11+
# Stream stdout/stderr output from each test in real-time.
12+
# See https://docs.bazel.build/versions/master/user-manual.html#flag--test_output for more details.
13+
test:debug --test_output=streamed
14+
15+
# Run one test at a time.
16+
test:debug --test_strategy=exclusive
17+
18+
# Prevent long running tests from timing out.
19+
# See https://docs.bazel.build/versions/master/user-manual.html#flag--test_timeout for more details.
20+
test:debug --test_timeout=9999
21+
22+
# Always run tests even if they have cached results.
23+
test:debug --nocache_test_results
24+
# ======================================================================================================================
325

426
###############################
527
# Filesystem interactions #

.circleci/config.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,12 @@ jobs:
2727
- run: scripts/format.sh
2828
- run: scripts/build.sh << parameters.dependency_type >>
2929
- run: scripts/test.sh
30-
bazel-build-and-test:
31-
docker:
32-
- image: cimg/node:14.18.3@sha256:30583ce79b08d318b1fc5e17a613d21ef960091e5442b06eb49c56fa180a3b30
33-
steps:
34-
- checkout
35-
- node/install-packages:
36-
pkg-manager: yarn
37-
# Disable bazel build & test temporarily
38-
- run: yarn bazel info
3930
workflows:
4031
build-and-test:
4132
jobs:
4233
- build-and-test:
4334
name: build-and-test
4435
dependency_type: "package.json"
45-
bazel-build-and-test:
46-
jobs:
47-
- bazel-build-and-test:
48-
name: bazel-build-and-test
4936
buid-and-test-against-builds:
5037
jobs:
5138
- build-and-test:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.npmrc
21
.vscode-test
32
.DS_Store
43
node_modules

.npmrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
2+
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
3+
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
4+
hoist=false
5+
6+
# Allow for missing peer dependencies on pnpm import.
7+
# See https://github.com/aspect-build/rules_js/pull/445 for more context.
8+
strict-peer-dependencies=false

BUILD.bazel

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
load("@aspect_rules_js//js:defs.bzl", "js_library")
2+
load("@aspect_rules_js//js/private:expand_template.bzl", "expand_template")
23
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
34
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
45
load("@npm//:defs.bzl", "npm_link_all_packages")
56
load("@npm//:vsce/package_json.bzl", vsce_bin = "bin")
7+
load(":version.bzl", "VERSION")
68

79
npm_link_all_packages(name = "node_modules")
810

@@ -18,10 +20,20 @@ ts_config(
1820
visibility = ["//visibility:public"]
1921
)
2022

23+
expand_template(
24+
name = "package_json_expanded",
25+
template = "package.json",
26+
out = "package_expanded.json",
27+
substitutions = {
28+
"0.0.0-PLACEHOLDER": VERSION,
29+
"./dist/client/src/extension": "./index",
30+
}
31+
)
32+
2133
npm_package(
22-
name = "npm",
34+
name = "vsix_sandbox",
2335
srcs = [
24-
"package.json",
36+
"package_expanded.json",
2537
"angular.png",
2638
"CHANGELOG.md",
2739
"README.md",
@@ -57,22 +69,37 @@ npm_package(
5769
"**/*.map",
5870
],
5971
replace_prefixes = {
72+
"package_expanded.json": "package.json",
6073
"client/": "",
6174
"syntaxes/src/": "syntaxes/",
6275
},
63-
visibility = ["//integration:__subpackages__"],
6476
)
6577

6678
vsce_bin.vsce(
6779
name = "vsix",
6880
srcs = [
69-
":npm",
81+
":vsix_sandbox",
7082
],
71-
outs = ["ng-template.vsix"],
72-
chdir = "npm",
83+
outs = ["ng-template-{}.vsix".format(VERSION)],
84+
chdir = "vsix_sandbox",
7385
args = [
7486
"package",
7587
"-o",
76-
"../ng-template.vsix"
88+
"../ng-template-{}.vsix".format(VERSION)
89+
],
90+
# vsce requires npm on the PATH; we can get this from the Bazel rules_nodejs but it is not
91+
# included by default in rules_js binary rules so we include it here explicitly
92+
include_npm = True,
93+
)
94+
95+
npm_package(
96+
name = "npm",
97+
srcs = [
98+
":vsix_sandbox",
99+
":vsix",
100+
],
101+
root_paths = [
102+
"vsix_sandbox"
77103
],
104+
visibility = ["//integration:__subpackages__"],
78105
)

WORKSPACE

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22

33
http_archive(
44
name = "aspect_rules_js",
5-
sha256 = "538049993bec3ee1ae9b1c3cd669156bca04eb67027b222883e47b0a2aed2e67",
6-
strip_prefix = "rules_js-1.0.0",
7-
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0.tar.gz",
5+
sha256 = "b9fde0f20de6324ad443500ae738bda00facbd73900a12b417ce794856e01407",
6+
strip_prefix = "rules_js-1.5.0",
7+
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.5.0.tar.gz",
88
)
99

1010
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
@@ -13,9 +13,9 @@ rules_js_dependencies()
1313

1414
http_archive(
1515
name = "aspect_rules_ts",
16-
sha256 = "1945d5a356d0ec85359dea411467dec0f98502503a53798ead7f54aef849598b",
17-
strip_prefix = "rules_ts-1.0.0-rc1",
18-
url = "https://github.com/aspect-build/rules_ts/archive/refs/tags/v1.0.0-rc1.tar.gz",
16+
sha256 = "743f0e988e4e3f1e25e52c79f9dc3da1ddd77507ae88787ae95b4e70c537872b",
17+
strip_prefix = "rules_ts-1.0.0-rc4",
18+
url = "https://github.com/aspect-build/rules_ts/archive/refs/tags/v1.0.0-rc4.tar.gz",
1919
)
2020

2121
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
@@ -24,9 +24,9 @@ rules_ts_dependencies(ts_version_from = "//:package.json",)
2424

2525
http_archive(
2626
name = "aspect_rules_jasmine",
27-
sha256 = "741d3376fdbf0c0c742e3bac0f854b1d49dbe1998d3530ef6f22f467675ca177",
28-
strip_prefix = "rules_jasmine-0.0.1",
29-
url = "https://github.com/aspect-build/rules_jasmine/archive/refs/tags/v0.0.1.tar.gz",
27+
sha256 = "938a2818100fd89e7600a45b7ba4fcd4114c11c5b5741db30ff7c6e0dcb2ea4b",
28+
strip_prefix = "rules_jasmine-0.1.0",
29+
url = "https://github.com/aspect-build/rules_jasmine/archive/refs/tags/v0.1.0.tar.gz",
3030
)
3131

3232
load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependencies")
@@ -35,9 +35,9 @@ rules_jasmine_dependencies()
3535

3636
http_archive(
3737
name = "aspect_rules_esbuild",
38-
sha256 = "6446a784e72b04c33bc48debd84c5a54db4727f0a4a61a0da9faa64bededd7c2",
39-
strip_prefix = "rules_esbuild-0909898c1344569f59fa83f70a1db7548563c274",
40-
url = "https://github.com/aspect-build/rules_esbuild/archive/0909898c1344569f59fa83f70a1db7548563c274.tar.gz",
38+
sha256 = "1e365451341ffb2490193292dfd9953f2ca009586c2381cb4dc08d01e48866b7",
39+
strip_prefix = "rules_esbuild-0.12.0",
40+
url = "https://github.com/aspect-build/rules_esbuild/archive/refs/tags/v0.12.0.tar.gz",
4141
)
4242

4343
load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies")
@@ -58,11 +58,11 @@ esbuild_register_toolchains(
5858
esbuild_version = ESBUILD_LATEST_VERSION,
5959
)
6060

61-
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
61+
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
6262

6363
nodejs_register_toolchains(
6464
name = "nodejs",
65-
node_version = DEFAULT_NODE_VERSION,
65+
node_version = "14.20.0",
6666
)
6767

6868
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
@@ -71,6 +71,7 @@ npm_translate_lock(
7171
name = "npm",
7272
yarn_lock = "//:yarn.lock",
7373
package_json = "//:package.json",
74+
npmrc = "//:.npmrc",
7475
verify_node_modules_ignored = "//:.bazelignore",
7576
public_hoist_packages = {
7677
# Hoist transitive closure of npm deps needed for vsce; this set was determined manually by
@@ -96,6 +97,7 @@ npm_translate_lock(
9697
name = "npm_integration_workspace",
9798
yarn_lock = "//integration/workspace:yarn.lock",
9899
package_json = "//integration/workspace:package.json",
100+
npmrc = "//:.npmrc",
99101
verify_node_modules_ignored = "//:.bazelignore",
100102
)
101103

@@ -107,6 +109,7 @@ npm_translate_lock(
107109
name = "npm_integration_pre_apf_project",
108110
yarn_lock = "//integration/pre_apf_project:yarn.lock",
109111
package_json = "//integration/pre_apf_project:package.json",
112+
npmrc = "//:.npmrc",
110113
verify_node_modules_ignored = "//:.bazelignore",
111114
)
112115

@@ -118,6 +121,7 @@ npm_translate_lock(
118121
name = "npm_integration_project",
119122
yarn_lock = "//integration/project:yarn.lock",
120123
package_json = "//integration/project:package.json",
124+
npmrc = "//:.npmrc",
121125
verify_node_modules_ignored = "//:.bazelignore",
122126
)
123127

integration/e2e/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ js_test(
2626
"//:npm",
2727
"//integration",
2828
"//integration/project",
29-
"//server:index",
3029
# Depend on //:node_modules/jasmine as a temporary work-around for jasmine escaping its
3130
# runfiles likely due to esm import issue in rules_js https://github.com/aspect-build/rules_js/issues/362
3231
"//:node_modules/jasmine",

integration/e2e/completion_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import * as vscode from 'vscode';
32

43
import {activate, COMPLETION_COMMAND, FOO_TEMPLATE_URI} from './helper';

integration/e2e/jasmine.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export async function run(): Promise<void> {
3333

3434
console.log(`Expecting to run ${jasmine.specFiles.length} specs.`);
3535

36+
console.log(JSON.stringify(jasmine.specFiles, null, 2))
37+
3638
if (jasmine.specFiles.length === 0) {
3739
throw new Error('No specs found');
3840
}

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,19 @@
209209
"format": "scripts/format.sh",
210210
"watch": "tsc -b -w",
211211
"package": "scripts/build.sh package.json",
212-
"test": "yarn compile:test && jasmine --config=jasmine.json",
213-
"test:inspect": "yarn compile:test && node --inspect-brk node_modules/jasmine/bin/jasmine.js --config=jasmine.json",
214-
"test:lsp": "yarn compile:integration && jasmine --config=integration/lsp/jasmine.json",
215-
"test:lsp-bazel": "yarn bazel test --test_output=streamed //integration:lsp_test",
216-
"test:e2e": "yarn compile:integration && node dist/integration/e2e",
217-
"test:e2e-bazel": "yarn bazel test --test_output=streamed //integration/e2e:e2e_test",
218-
"test:syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js",
219-
"test:bazel": "yarn bazel test --test_tag_filters=unit_test //...",
220-
"test:bazel-watch": "yarn ibazel test --test_tag_filters=unit_test //..."
212+
"test": "yarn bazel test --test_tag_filters=unit_test //...",
213+
"test:watch": "yarn ibazel test --test_tag_filters=unit_test //...",
214+
"test:lsp": "yarn bazel test --test_output=streamed //integration/lsp:test",
215+
"test:e2e": "yarn bazel test --test_output=streamed //integration/e2e:test",
216+
"test:inspect-client": "yarn bazel run --config=debug //client/src/tests:test",
217+
"test:inspect-common": "yarn bazel run --config=debug //common/tests:test",
218+
"test:inspect-server": "yarn bazel run --config=debug //server/src/tests:test",
219+
"test:inspect-syntaxes": "yarn bazel run --config=debug //syntaxes/test:test",
220+
"test:legacy-inspect": "yarn compile:test && node --inspect-brk node_modules/jasmine/bin/jasmine.js --config=jasmine.json",
221+
"test:legacy": "yarn compile:test && jasmine --config=jasmine.json",
222+
"test:legacy-lsp": "yarn compile:integration && jasmine --config=integration/lsp/jasmine.json",
223+
"test:legacy-e2e": "yarn compile:integration && node dist/integration/e2e",
224+
"test:legacy-syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js"
221225
},
222226
"dependencies": {
223227
"@angular/language-service": "14.2.0",

scripts/build.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,32 @@ fi
3030

3131
set -ex -o pipefail
3232

33+
# Clean up from last build
34+
rm -rf dist
35+
36+
# Run legacy yarn install to update the lock file since we may have modified the package.json above
37+
# and so that we can call bazel via yarn bazel
38+
yarn install
39+
40+
# Build the npm package with bazel
41+
yarn bazel build //:npm
42+
43+
# Copy the bazel built package to dist/npm_bazel
44+
# TODO: copy to dist/npm when ready to cut-over
45+
mkdir -p dist/npm_bazel
46+
cp -r bazel-bin/npm/ dist/npm_bazel
47+
chmod -R +w dist/npm_bazel
48+
49+
################################################################################
50+
#### LEGACY PRE-BAZEL BUILD --- can be removed after cut-over
51+
################################################################################
52+
3353
# Enable extended pattern matching features
3454
shopt -s extglob
3555

3656
# Clean up from last build
37-
rm -rf dist
3857
rm -rf **/*.tsbuildinfo
3958

40-
41-
yarn install;
42-
4359
# Build the client and server
4460
yarn run compile
4561

scripts/test.sh

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,8 @@
22

33
set -ex -o pipefail
44

5-
# Install test project dependencies
6-
if [[ -z "${CI}" ]]; then
7-
(cd integration/project && yarn)
8-
(cd integration/pre_apf_project && yarn)
9-
(cd integration/workspace && yarn)
10-
fi
11-
12-
# Server unit tests
13-
yarn run test
14-
15-
# Smoke test for LSP
16-
yarn run test:lsp
5+
yarn bazel test //...
176

187
# E2E test that brings up full vscode
198
# TODO: Disabled for now because it cannot be run on CircleCI
20-
# yarn run test:e2e
21-
22-
# Syntaxes tests
23-
yarn run test:syntaxes
24-
# Check git status to see if there are modified files
25-
STATUS="$(git status --porcelain)"
26-
echo $STATUS
27-
# If the status contains modified files in the syntaxes folder, they are out of date
28-
if [[ "$STATUS" == *"syntaxes"* ]]; then
29-
echo 'Syntax files are out-of-sync with source. Please run "yarn run build:syntaxes".'
30-
exit 1
31-
fi
9+
# bazel test --test_output=streamed //integration/e2e:test

syntaxes/BUILD.bazel

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
load("@aspect_rules_js//js:defs.bzl", "js_library")
1+
load("@aspect_rules_js//js:defs.bzl", "js_run_binary", "js_library")
22
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
3+
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
4+
5+
js_run_binary(
6+
name = "build",
7+
tool = "//syntaxes/src:build",
8+
outs = [
9+
# bazel output files names in the output tree are prefixed with `_` so
10+
# we can refer to both the source files & output files by label in the
11+
# write_source_files target below.
12+
"_expression.json",
13+
"_inline-styles.json",
14+
"_inline-template.json",
15+
"_template.json",
16+
]
17+
)
18+
19+
write_source_files(
20+
name = "syntaxes",
21+
files = {
22+
"expression.json": "_expression.json",
23+
"inline-styles.json": "_inline-styles.json",
24+
"inline-template.json": "_inline-template.json",
25+
"template.json": "_template.json",
26+
}
27+
)
328

429
js_library(
530
name = "json",

0 commit comments

Comments
 (0)