Skip to content

build: bazel build & unit tests #1732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
integration/pre_apf_project/node_modules/
integration/workspace/node_modules/
48 changes: 48 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Enable debugging tests with --config=debug
test:debug --test_arg=--node_options=--inspect-brk --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results

###############################
# Filesystem interactions #
###############################

# Turn off legacy external runfiles
build --nolegacy_external_runfiles
run --nolegacy_external_runfiles
test --nolegacy_external_runfiles

# Turn on --incompatible_strict_action_env which was on by default
# in Bazel 0.21.0 but turned off again in 0.22.0. Follow
# https://github.com/bazelbuild/bazel/issues/7026 for more details.
# This flag is needed to so that the bazel cache is not invalidated
# when running bazel via `yarn bazel`.
# See https://github.com/angular/angular/issues/27514.
build --incompatible_strict_action_env
run --incompatible_strict_action_env
test --incompatible_strict_action_env

# Do not build runfile trees by default. If an execution strategy relies on runfile
# symlink teee, the tree is created on-demand. See: https://github.com/bazelbuild/bazel/issues/6627
# and https://github.com/bazelbuild/bazel/commit/03246077f948f2790a83520e7dccc2625650e6df
build --nobuild_runfile_links

build --enable_runfiles

###############################
# Output #
###############################

# A more useful default output mode for bazel query
# Prints eg. "ng_module rule //foo:bar" rather than just "//foo:bar"
query --output=label_kind

# By default, failing tests don't print any output, it goes to the log file
test --test_output=errors

####################################################
# User bazel configuration
# NOTE: This needs to be the *last* entry in the config.
####################################################

# Load any settings which are specific to the current user. Needs to be *last* statement
# in this config, as the user configuration should be able to overwrite flags from this file.
try-import .bazelrc.user
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.2.0
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ jobs:
- run: scripts/format.sh
- run: scripts/build.sh << parameters.dependency_type >>
- run: scripts/test.sh
bazel-build-and-test:
docker:
- image: cimg/node:14.18.3@sha256:30583ce79b08d318b1fc5e17a613d21ef960091e5442b06eb49c56fa180a3b30
steps:
- checkout
- node/install-packages:
pkg-manager: yarn
- run: yarn test:bazel
workflows:
build-and-test:
jobs:
- build-and-test:
name: build-and-test
dependency_type: "package.json"
bazel-build-and-test:
jobs:
- bazel-build-and-test:
name: bazel-build-and-test
buid-and-test-against-builds:
jobs:
- build-and-test:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ dist/
*.log
.ng-dev.user*
.husky/_

# bazel
bazel-*
17 changes: 17 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

js_library(
name = "package_json",
srcs = ["package.json"],
visibility = ["//syntaxes/test:__pkg__"],
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
visibility = ["//visibility:public"]
)
83 changes: 83 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "aspect_rules_js",
sha256 = "538049993bec3ee1ae9b1c3cd669156bca04eb67027b222883e47b0a2aed2e67",
strip_prefix = "rules_js-1.0.0",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

http_archive(
name = "aspect_rules_ts",
sha256 = "1945d5a356d0ec85359dea411467dec0f98502503a53798ead7f54aef849598b",
strip_prefix = "rules_ts-1.0.0-rc1",
url = "https://github.com/aspect-build/rules_ts/archive/refs/tags/v1.0.0-rc1.tar.gz",
)

load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

rules_ts_dependencies(ts_version_from = "//:package.json",)

http_archive(
name = "aspect_rules_jasmine",
sha256 = "741d3376fdbf0c0c742e3bac0f854b1d49dbe1998d3530ef6f22f467675ca177",
strip_prefix = "rules_jasmine-0.0.1",
url = "https://github.com/aspect-build/rules_jasmine/archive/refs/tags/v0.0.1.tar.gz",
)

load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependencies")

rules_jasmine_dependencies()

load("@aspect_rules_jasmine//jasmine:repositories.bzl", "rules_jasmine_repositories", JASMINE_LATEST_VERSION = "LATEST_VERSION")

rules_jasmine_repositories(
name = "jasmine",
jasmine_version = JASMINE_LATEST_VERSION,
)

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
yarn_lock = "//:yarn.lock",
package_json = "//:package.json",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()

npm_translate_lock(
name = "npm_integration_workspace",
yarn_lock = "//integration/workspace:yarn.lock",
package_json = "//integration/workspace:package.json",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm_integration_workspace//:repositories.bzl", npm_integration_workspace_repositories = "npm_repositories")

npm_integration_workspace_repositories()

npm_translate_lock(
name = "npm_integration_pre_apf_project",
yarn_lock = "//integration/pre_apf_project:yarn.lock",
package_json = "//integration/pre_apf_project:package.json",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm_integration_pre_apf_project//:repositories.bzl", npm_integration_pre_apf_project_repositories = "npm_repositories")

npm_integration_pre_apf_project_repositories()
11 changes: 11 additions & 0 deletions client/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig",
"//common:tsconfig",
],
visibility = ["//client:__subpackages__"]
)
21 changes: 21 additions & 0 deletions client/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")


ts_project(
name = "src",
srcs = glob(["*.ts"]),
composite = True,
declaration = True,
source_map = True,
tsconfig = "//client:tsconfig",
deps = [
"//:node_modules/@types/node",
"//:node_modules/@types/vscode",
"//:node_modules/typescript",
"//:node_modules/vscode-languageclient",
"//common",
],
visibility = [
"//client:__subpackages__",
],
)
33 changes: 33 additions & 0 deletions client/src/tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig",
"//client:tsconfig",
],
)

ts_project(
name = "tests",
srcs = glob(["*.ts"]),
declaration = True,
source_map = True,
tsconfig = ":tsconfig",
deps = [
"//client/src",
"//:node_modules/@types/vscode",
"//:node_modules/@types/jasmine",
"//:node_modules/vscode-languageserver-textdocument",
],
)

jasmine_test(
name = "test",
data = [":tests"],
args = ["*_spec.js"],
chdir = package_name(),
tags = ["unit_test"],
)
33 changes: 33 additions & 0 deletions common/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")

ts_config(
name = "tsconfig",
src = "tsconfig.json",
visibility = [
"//client:__subpackages__",
"//common:__subpackages__",
"//server:__subpackages__",
"//integration:__subpackages__",
],
deps = ["//:tsconfig"],
)

ts_project(
name = "common",
srcs = glob(["*.ts"]),
composite = True,
declaration = True,
source_map = True,
tsconfig = ":tsconfig",
visibility = [
"//client:__subpackages__",
"//common:__subpackages__",
"//server:__subpackages__",
"//integration:__subpackages__",
],
deps = [
"//:node_modules/@types/node",
"//:node_modules/vscode-jsonrpc",
"//:node_modules/vscode-languageserver-protocol",
],
)
31 changes: 31 additions & 0 deletions common/tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig",
"//common:tsconfig",
],
)

ts_project(
name = "tests",
srcs = glob(["*.ts"]),
declaration = True,
source_map = True,
tsconfig = ":tsconfig",
deps = [
"//common",
"//:node_modules/@types/jasmine",
],
)

jasmine_test(
name = "test",
data = [":tests"],
args = ["*_spec.js"],
chdir = package_name(),
tags = ["unit_test"],
)
35 changes: 35 additions & 0 deletions integration/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig",
"//server:tsconfig",
],
visibility = ["//integration:__subpackages__"]
)

ts_project(
name = "integration",
srcs = glob([
"*.ts",
# NB: there is an import cycle between lsp/*.ts and test_constants.ts so they cannot be
# broken up into separate ts_project targets
"lsp/*.ts",
]),
declaration = True,
source_map = True,
tsconfig = ":tsconfig",
deps = [
"//:node_modules/@types/jasmine",
"//:node_modules/@types/node",
"//:node_modules/vscode-jsonrpc",
"//:node_modules/vscode-languageserver-protocol",
"//:node_modules/vscode-uri",
"//common",
],
visibility = [
"//integration:__subpackages__",
],
)
19 changes: 19 additions & 0 deletions integration/e2e/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "e2e",
srcs = glob(["*.ts"]),
declaration = True,
source_map = True,
tsconfig = "//integration:tsconfig",
deps = [
"//:node_modules/@types/jasmine",
"//:node_modules/@types/node",
"//:node_modules/@types/vscode",
"//:node_modules/vscode-test",
"//integration",
],
visibility = [
"//integration:__subpackages__",
],
)
10 changes: 10 additions & 0 deletions integration/pre_apf_project/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@npm_integration_pre_apf_project//:defs.bzl", "npm_link_all_packages")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")

npm_link_all_packages(name = "node_modules")

copy_to_bin(
name = "pre_apf_project",
srcs = glob(["**"]),
visibility = ["//server/src/tests:__pkg__"],
)
Loading