Skip to content

build: test cdk with bazel #13575

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 3 commits into from
Oct 15, 2018
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
- run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc

# TODO(jelbourn): Update this command to run all tests if the Bazel issues have been fixed.
- run: bazel build src/cdk:npm_package
- run: bazel test src/{cdk,lib}/schematics:unit_tests
- run: bazel build src/cdk/...
- run: bazel test src/cdk/...

- save_cache:
key: *cache_key
Expand Down
38 changes: 0 additions & 38 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
package(default_visibility = ["//visibility:public"])

# Glob pattern that matches all Angular testing bundles.
ANGULAR_TESTING = [
"node_modules/@angular/*/bundles/*-testing.umd.js",
# The compiler and the dynamic platform-browser should be visible only in tests
"node_modules/@angular/compiler/bundles/*.umd.js",
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
]

filegroup(
name = "angular_bundles",
srcs = glob(["node_modules/@angular/*/bundles/*.umd.js"], exclude = ANGULAR_TESTING),
)

filegroup(
name = "angular_test_bundles",
testonly = 1,
srcs = glob(ANGULAR_TESTING),
)

filegroup(
name = "tslib_bundle",
testonly = 1,
srcs = glob(["node_modules/tslib/tslib.js"]),
)

# Files necessary for unit tests that use zonejs
filegroup(
name = "web_test_bootstrap_scripts",
# The order of these deps is important.
# Do not sort.
srcs = [
"//:node_modules/reflect-metadata/Reflect.js",
"//:node_modules/zone.js/dist/zone.js",
"//:node_modules/zone.js/dist/zone-testing.js",
"//:node_modules/zone.js/dist/task-tracking.js",
],
)
15 changes: 15 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,18 @@ rules_angular_dependencies()
# Setup Angular workspace for building (Bazel managed node modules)
load("@angular//:index.bzl", "ng_setup_workspace")
ng_setup_workspace()

# Setup Go toolchain (required for Bazel web testing rules)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()

# Setup web testing. We need to setup a browser because the web testing rules for TypeScript need
# a reference to a registered browser (ideally that's a hermetic version of a browser)
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories",
"web_test_repositories")

web_test_repositories()
browser_repositories(
chromium = True,
)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"@angular/router": "7.0.0-rc.0",
"@angular/upgrade": "7.0.0-rc.0",
"@bazel/ibazel": "0.3.1",
"@bazel/typescript": "^0.19.1",
"@bazel/karma": "0.20.2",
"@bazel/typescript": "0.20.2",
"@firebase/app-types": "^0.3.2",
"@google-cloud/storage": "^1.1.1",
"@octokit/rest": "^15.9.4",
Expand Down
6 changes: 6 additions & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package(default_visibility = ["//visibility:public"])

exports_files([
"bazel-tsconfig-build.json",
"bazel-tsconfig-test.json",
])
30 changes: 30 additions & 0 deletions src/bazel-tsconfig-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// TypeScript configuration that will be used to build entry-points of the CDK. To avoid
// duplicate logic, we decided to just have one package-wide tsconfig file that will be
// used by Bazel to build the sources for an entry-point. This means that we no longer
// need multiple tsconfig files (build & test) for each entry-point once Bazel replaces
// our gulp build system.
{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"stripInternal": false,
"experimentalDecorators": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitAny": true,
"importHelpers": true,
"newLine": "lf",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"inlineSources": true,
"target": "es2015",
"lib": ["es2015", "dom"],
"skipLibCheck": true,
"types": ["tslib"]
},
"bazelOptions": {
"suppressTsconfigOverrideWarnings": true
}
}
10 changes: 10 additions & 0 deletions src/bazel-tsconfig-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// TypeScript configuration that will be used to build the test sources for entry-points
// of the CDK. To avoid duplicate logic, we decided to just have one package-wide tsconfig
// file that will be used by Bazel to build the test sources for an entry-point.
{
"extends": "./bazel-tsconfig-build.json",
"compilerOptions": {
"importHelpers": false,
"types": ["jasmine"]
}
}
5 changes: 4 additions & 1 deletion src/cdk/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ ng_package(
globals = ROLLUP_GLOBALS,
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
deps = CDK_TARGETS,
tags = ["publish"],
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
# files.
tags = ["manual"],
)
35 changes: 10 additions & 25 deletions src/cdk/a11y/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package(default_visibility=["//visibility:public"])

load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

ng_module(
name = "a11y",
Expand All @@ -17,8 +16,7 @@ ng_module(
"//src/cdk/keycodes",
"//src/cdk/observers",
"//src/cdk/platform",
],
tsconfig = "//src/cdk:tsconfig-build.json",
]
)

# TODO(jelbourn): remove this when sass_library acts like a filegroup
Expand All @@ -32,35 +30,22 @@ sass_library(
srcs = [":a11y_scss_partials"],
)

ts_library(
ng_test_library(
name = "a11y_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":a11y",
"@angular//packages/platform-browser",
"@rxjs",
"@rxjs//operators",
"//src/cdk/keycodes",
"//src/cdk/observers",
"//src/cdk/platform",
"//src/cdk/testing",
"@rxjs",
"@rxjs//operators",
],
tsconfig = "//src/cdk:tsconfig-build.json",
":a11y",
]
)

ts_web_test(
ng_web_test_suite(
name = "unit_tests",
# TODO(mmalerba): re-enable once ngfactory issue is resolved.
tags = ["manual"],
bootstrap = [
"//:web_test_bootstrap_scripts",
],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":a11y_test_sources",
],
deps = [":a11y_test_sources"],
)
27 changes: 8 additions & 19 deletions src/cdk/accordion/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package(default_visibility=["//visibility:public"])

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ts_library", "ng_test_library", "ng_web_test_suite")

ng_module(
name = "accordion",
Expand All @@ -12,30 +11,20 @@ ng_module(
"@rxjs",
"//src/cdk/coercion",
"//src/cdk/collections",
],
tsconfig = "//src/cdk:tsconfig-build.json",
]
)

ts_library(
ng_test_library(
name = "accordion_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
"@angular//packages/platform-browser",
"@angular//packages/platform-browser/animations",
":accordion",
"@rxjs",
],
tsconfig = "//src/cdk:tsconfig-build.json",
]
)

ts_web_test(
ng_web_test_suite(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":accordion_test_sources",
],
deps = [":accordion_test_sources"],
)
29 changes: 9 additions & 20 deletions src/cdk/bidi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package(default_visibility=["//visibility:public"])

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

ng_module(
name = "bidi",
Expand All @@ -10,29 +9,19 @@ ng_module(
deps = [
"@angular//packages/common",
"@angular//packages/core",
],
tsconfig = "//src/cdk:tsconfig-build.json",
]
)

ts_library(
ng_test_library(
name = "bidi_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [":bidi"],
tsconfig = "//src/cdk:tsconfig-build.json",
deps = [
"@angular//packages/platform-browser",
":bidi"
],
)

ts_web_test(
ng_web_test_suite(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":bidi_test_sources",
],
deps = [":bidi_test_sources"],
)
13 changes: 7 additions & 6 deletions src/cdk/coercion/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package(default_visibility=["//visibility:public"])

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("//tools:defaults.bzl", "ts_library", "jasmine_node_test")

ts_library(
name = "coercion",
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
module_name = "@angular/cdk/coercion",
deps = ["@npm//tslib"],
tsconfig = "//src/cdk:tsconfig-build.json",
)

ts_library(
name = "coercion_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [":coercion"],
deps = [
"@npm//@types/jasmine",
":coercion"
],
testonly = 1,
)

ts_web_test(
jasmine_node_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
deps = [":coercion_test_sources"],
)
23 changes: 6 additions & 17 deletions src/cdk/collections/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package(default_visibility=["//visibility:public"])

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ts_library", "jasmine_node_test")

ng_module(
name = "collections",
Expand All @@ -11,29 +10,19 @@ ng_module(
"@angular//packages/core",
"@rxjs"
],
tsconfig = "//src/cdk:tsconfig-build.json",
)

ts_library(
name = "collections_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":collections",
"@rxjs",
"@npm//@types/jasmine",
":collections"
],
tsconfig = "//src/cdk:tsconfig-build.json",
testonly = 1,
)

ts_web_test(
jasmine_node_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":collections_test_sources",
],
deps = [":collections_test_sources"],
)
Loading