Skip to content

Commit 2e4e8a6

Browse files
committed
build: bazel build & unit tests
includes common, server, client & syntaxes tests test with, `yarn test:bazel` watch mode using, `yarn test:bazel-watch`
1 parent 511218f commit 2e4e8a6

27 files changed

+548
-6
lines changed

.bazelignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
integration/pre_apf_project/node_modules/
3+
integration/workspace/node_modules/

.bazelrc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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
3+
4+
###############################
5+
# Filesystem interactions #
6+
###############################
7+
8+
# Turn off legacy external runfiles
9+
build --nolegacy_external_runfiles
10+
run --nolegacy_external_runfiles
11+
test --nolegacy_external_runfiles
12+
13+
# Turn on --incompatible_strict_action_env which was on by default
14+
# in Bazel 0.21.0 but turned off again in 0.22.0. Follow
15+
# https://github.com/bazelbuild/bazel/issues/7026 for more details.
16+
# This flag is needed to so that the bazel cache is not invalidated
17+
# when running bazel via `yarn bazel`.
18+
# See https://github.com/angular/angular/issues/27514.
19+
build --incompatible_strict_action_env
20+
run --incompatible_strict_action_env
21+
test --incompatible_strict_action_env
22+
23+
# Do not build runfile trees by default. If an execution strategy relies on runfile
24+
# symlink teee, the tree is created on-demand. See: https://github.com/bazelbuild/bazel/issues/6627
25+
# and https://github.com/bazelbuild/bazel/commit/03246077f948f2790a83520e7dccc2625650e6df
26+
build --nobuild_runfile_links
27+
28+
build --enable_runfiles
29+
30+
###############################
31+
# Output #
32+
###############################
33+
34+
# A more useful default output mode for bazel query
35+
# Prints eg. "ng_module rule //foo:bar" rather than just "//foo:bar"
36+
query --output=label_kind
37+
38+
# By default, failing tests don't print any output, it goes to the log file
39+
test --test_output=errors
40+
41+
####################################################
42+
# User bazel configuration
43+
# NOTE: This needs to be the *last* entry in the config.
44+
####################################################
45+
46+
# Load any settings which are specific to the current user. Needs to be *last* statement
47+
# in this config, as the user configuration should be able to overwrite flags from this file.
48+
try-import .bazelrc.user

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.2.0

.circleci/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,24 @@ 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+
- run: yarn test:bazel
3038
workflows:
3139
build-and-test:
3240
jobs:
3341
- build-and-test:
3442
name: build-and-test
3543
dependency_type: "package.json"
44+
bazel-build-and-test:
45+
jobs:
46+
- bazel-build-and-test:
47+
name: bazel-build-and-test
3648
buid-and-test-against-builds:
3749
jobs:
3850
- build-and-test:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ dist/
1717
*.log
1818
.ng-dev.user*
1919
.husky/_
20+
21+
# bazel
22+
bazel-*

BUILD.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_library")
2+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
3+
load("@npm//:defs.bzl", "npm_link_all_packages")
4+
5+
npm_link_all_packages(name = "node_modules")
6+
7+
js_library(
8+
name = "package_json",
9+
srcs = ["package.json"],
10+
visibility = ["//syntaxes/test:__pkg__"],
11+
)
12+
13+
ts_config(
14+
name = "tsconfig",
15+
src = "tsconfig.json",
16+
visibility = ["//visibility:public"]
17+
)

WORKSPACE

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
http_archive(
4+
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",
8+
)
9+
10+
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
11+
12+
rules_js_dependencies()
13+
14+
http_archive(
15+
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",
19+
)
20+
21+
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
22+
23+
rules_ts_dependencies(ts_version_from = "//:package.json",)
24+
25+
http_archive(
26+
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",
30+
)
31+
32+
load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependencies")
33+
34+
rules_jasmine_dependencies()
35+
36+
load("@aspect_rules_jasmine//jasmine:repositories.bzl", "rules_jasmine_repositories", JASMINE_LATEST_VERSION = "LATEST_VERSION")
37+
38+
rules_jasmine_repositories(
39+
name = "jasmine",
40+
jasmine_version = JASMINE_LATEST_VERSION,
41+
)
42+
43+
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
44+
45+
nodejs_register_toolchains(
46+
name = "nodejs",
47+
node_version = DEFAULT_NODE_VERSION,
48+
)
49+
50+
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
51+
52+
npm_translate_lock(
53+
name = "npm",
54+
yarn_lock = "//:yarn.lock",
55+
package_json = "//:package.json",
56+
verify_node_modules_ignored = "//:.bazelignore",
57+
)
58+
59+
load("@npm//:repositories.bzl", "npm_repositories")
60+
61+
npm_repositories()
62+
63+
npm_translate_lock(
64+
name = "npm_integration_workspace",
65+
yarn_lock = "//integration/workspace:yarn.lock",
66+
package_json = "//integration/workspace:package.json",
67+
verify_node_modules_ignored = "//:.bazelignore",
68+
)
69+
70+
load("@npm_integration_workspace//:repositories.bzl", npm_integration_workspace_repositories = "npm_repositories")
71+
72+
npm_integration_workspace_repositories()
73+
74+
npm_translate_lock(
75+
name = "npm_integration_pre_apf_project",
76+
yarn_lock = "//integration/pre_apf_project:yarn.lock",
77+
package_json = "//integration/pre_apf_project:package.json",
78+
verify_node_modules_ignored = "//:.bazelignore",
79+
)
80+
81+
load("@npm_integration_pre_apf_project//:repositories.bzl", npm_integration_pre_apf_project_repositories = "npm_repositories")
82+
83+
npm_integration_pre_apf_project_repositories()

client/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
2+
3+
ts_config(
4+
name = "tsconfig",
5+
src = "tsconfig.json",
6+
deps = [
7+
"//:tsconfig",
8+
"//common:tsconfig",
9+
],
10+
visibility = ["//client:__subpackages__"]
11+
)

client/src/BUILD.bazel

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
2+
3+
4+
ts_project(
5+
name = "src",
6+
srcs = glob(["*.ts"]),
7+
composite = True,
8+
declaration = True,
9+
source_map = True,
10+
tsconfig = "//client:tsconfig",
11+
deps = [
12+
"//:node_modules/@types/node",
13+
"//:node_modules/@types/vscode",
14+
"//:node_modules/typescript",
15+
"//:node_modules/vscode-languageclient",
16+
"//common",
17+
],
18+
visibility = [
19+
"//client:__subpackages__",
20+
],
21+
)

client/src/tests/BUILD.bazel

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
2+
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")
3+
4+
ts_config(
5+
name = "tsconfig",
6+
src = "tsconfig.json",
7+
deps = [
8+
"//:tsconfig",
9+
"//client:tsconfig",
10+
],
11+
)
12+
13+
ts_project(
14+
name = "tests",
15+
srcs = glob(["*.ts"]),
16+
declaration = True,
17+
source_map = True,
18+
tsconfig = ":tsconfig",
19+
deps = [
20+
"//client/src",
21+
"//:node_modules/@types/vscode",
22+
"//:node_modules/@types/jasmine",
23+
"//:node_modules/vscode-languageserver-textdocument",
24+
],
25+
)
26+
27+
jasmine_test(
28+
name = "test",
29+
data = [":tests"],
30+
args = ["*_spec.js"],
31+
chdir = package_name(),
32+
tags = ["unit_test"],
33+
)

common/BUILD.bazel

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
2+
3+
ts_config(
4+
name = "tsconfig",
5+
src = "tsconfig.json",
6+
visibility = [
7+
"//client:__subpackages__",
8+
"//common:__subpackages__",
9+
"//server:__subpackages__",
10+
"//integration:__subpackages__",
11+
],
12+
deps = ["//:tsconfig"],
13+
)
14+
15+
ts_project(
16+
name = "common",
17+
srcs = glob(["*.ts"]),
18+
composite = True,
19+
declaration = True,
20+
source_map = True,
21+
tsconfig = ":tsconfig",
22+
visibility = [
23+
"//client:__subpackages__",
24+
"//common:__subpackages__",
25+
"//server:__subpackages__",
26+
"//integration:__subpackages__",
27+
],
28+
deps = [
29+
"//:node_modules/@types/node",
30+
"//:node_modules/vscode-jsonrpc",
31+
"//:node_modules/vscode-languageserver-protocol",
32+
],
33+
)

common/tests/BUILD.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
2+
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")
3+
4+
ts_config(
5+
name = "tsconfig",
6+
src = "tsconfig.json",
7+
deps = [
8+
"//:tsconfig",
9+
"//common:tsconfig",
10+
],
11+
)
12+
13+
ts_project(
14+
name = "tests",
15+
srcs = glob(["*.ts"]),
16+
declaration = True,
17+
source_map = True,
18+
tsconfig = ":tsconfig",
19+
deps = [
20+
"//common",
21+
"//:node_modules/@types/jasmine",
22+
],
23+
)
24+
25+
jasmine_test(
26+
name = "test",
27+
data = [":tests"],
28+
args = ["*_spec.js"],
29+
chdir = package_name(),
30+
tags = ["unit_test"],
31+
)

integration/BUILD.bazel

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
2+
3+
ts_config(
4+
name = "tsconfig",
5+
src = "tsconfig.json",
6+
deps = [
7+
"//:tsconfig",
8+
"//server:tsconfig",
9+
],
10+
visibility = ["//integration:__subpackages__"]
11+
)
12+
13+
ts_project(
14+
name = "integration",
15+
srcs = glob([
16+
"*.ts",
17+
# NB: there is an import cycle between lsp/*.ts and test_constants.ts so they cannot be
18+
# broken up into separate ts_project targets
19+
"lsp/*.ts",
20+
]),
21+
declaration = True,
22+
source_map = True,
23+
tsconfig = ":tsconfig",
24+
deps = [
25+
"//:node_modules/@types/jasmine",
26+
"//:node_modules/@types/node",
27+
"//:node_modules/vscode-jsonrpc",
28+
"//:node_modules/vscode-languageserver-protocol",
29+
"//:node_modules/vscode-uri",
30+
"//common",
31+
],
32+
visibility = [
33+
"//integration:__subpackages__",
34+
],
35+
)

integration/e2e/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
2+
3+
ts_project(
4+
name = "e2e",
5+
srcs = glob(["*.ts"]),
6+
declaration = True,
7+
source_map = True,
8+
tsconfig = "//integration:tsconfig",
9+
deps = [
10+
"//:node_modules/@types/jasmine",
11+
"//:node_modules/@types/node",
12+
"//:node_modules/@types/vscode",
13+
"//:node_modules/vscode-test",
14+
"//integration",
15+
],
16+
visibility = [
17+
"//integration:__subpackages__",
18+
],
19+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
load("@npm_integration_pre_apf_project//:defs.bzl", "npm_link_all_packages")
2+
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
3+
4+
npm_link_all_packages(name = "node_modules")
5+
6+
copy_to_bin(
7+
name = "pre_apf_project",
8+
srcs = glob(["**"]),
9+
visibility = ["//server/src/tests:__pkg__"],
10+
)

0 commit comments

Comments
 (0)