Skip to content

Commit d128fff

Browse files
devversionandrewseguin
authored andcommitted
build: test cdk with bazel (#13575)
* build: test cdk with bazel * Add comment for bazel tsconfig files * CDK tsconfig sync with Bazel build tsconfig
1 parent 85f04db commit d128fff

34 files changed

+1077
-400
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ jobs:
7676
- *copy_bazel_config
7777

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

8282
- *save_cache
8383

BUILD.bazel

-38
Original file line numberDiff line numberDiff line change
@@ -1,39 +1 @@
11
package(default_visibility = ["//visibility:public"])
2-
3-
# Glob pattern that matches all Angular testing bundles.
4-
ANGULAR_TESTING = [
5-
"node_modules/@angular/*/bundles/*-testing.umd.js",
6-
# The compiler and the dynamic platform-browser should be visible only in tests
7-
"node_modules/@angular/compiler/bundles/*.umd.js",
8-
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
9-
]
10-
11-
filegroup(
12-
name = "angular_bundles",
13-
srcs = glob(["node_modules/@angular/*/bundles/*.umd.js"], exclude = ANGULAR_TESTING),
14-
)
15-
16-
filegroup(
17-
name = "angular_test_bundles",
18-
testonly = 1,
19-
srcs = glob(ANGULAR_TESTING),
20-
)
21-
22-
filegroup(
23-
name = "tslib_bundle",
24-
testonly = 1,
25-
srcs = glob(["node_modules/tslib/tslib.js"]),
26-
)
27-
28-
# Files necessary for unit tests that use zonejs
29-
filegroup(
30-
name = "web_test_bootstrap_scripts",
31-
# The order of these deps is important.
32-
# Do not sort.
33-
srcs = [
34-
"//:node_modules/reflect-metadata/Reflect.js",
35-
"//:node_modules/zone.js/dist/zone.js",
36-
"//:node_modules/zone.js/dist/zone-testing.js",
37-
"//:node_modules/zone.js/dist/task-tracking.js",
38-
],
39-
)

WORKSPACE

+15
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,18 @@ rules_angular_dependencies()
8282
# Setup Angular workspace for building (Bazel managed node modules)
8383
load("@angular//:index.bzl", "ng_setup_workspace")
8484
ng_setup_workspace()
85+
86+
# Setup Go toolchain (required for Bazel web testing rules)
87+
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
88+
go_rules_dependencies()
89+
go_register_toolchains()
90+
91+
# Setup web testing. We need to setup a browser because the web testing rules for TypeScript need
92+
# a reference to a registered browser (ideally that's a hermetic version of a browser)
93+
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories",
94+
"web_test_repositories")
95+
96+
web_test_repositories()
97+
browser_repositories(
98+
chromium = True,
99+
)

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"@angular/router": "7.0.0-rc.0",
5454
"@angular/upgrade": "7.0.0-rc.0",
5555
"@bazel/ibazel": "0.3.1",
56-
"@bazel/typescript": "^0.19.1",
56+
"@bazel/karma": "0.20.2",
57+
"@bazel/typescript": "0.20.2",
5758
"@firebase/app-types": "^0.3.2",
5859
"@google-cloud/storage": "^1.1.1",
5960
"@octokit/rest": "^15.9.4",

src/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files([
4+
"bazel-tsconfig-build.json",
5+
"bazel-tsconfig-test.json",
6+
])

src/bazel-tsconfig-build.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// TypeScript configuration that will be used to build entry-points of the CDK. To avoid
2+
// duplicate logic, we decided to just have one package-wide tsconfig file that will be
3+
// used by Bazel to build the sources for an entry-point. This means that we no longer
4+
// need multiple tsconfig files (build & test) for each entry-point once Bazel replaces
5+
// our gulp build system.
6+
{
7+
"compilerOptions": {
8+
"baseUrl": ".",
9+
"declaration": true,
10+
"stripInternal": false,
11+
"experimentalDecorators": true,
12+
"noUnusedParameters": true,
13+
"strictNullChecks": true,
14+
"strictFunctionTypes": true,
15+
"noImplicitAny": true,
16+
"importHelpers": true,
17+
"newLine": "lf",
18+
"module": "es2015",
19+
"moduleResolution": "node",
20+
"sourceMap": true,
21+
"inlineSources": true,
22+
"target": "es2015",
23+
"lib": ["es2015", "dom"],
24+
"skipLibCheck": true,
25+
"types": ["tslib"]
26+
},
27+
"bazelOptions": {
28+
"suppressTsconfigOverrideWarnings": true
29+
}
30+
}

src/bazel-tsconfig-test.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// TypeScript configuration that will be used to build the test sources for entry-points
2+
// of the CDK. To avoid duplicate logic, we decided to just have one package-wide tsconfig
3+
// file that will be used by Bazel to build the test sources for an entry-point.
4+
{
5+
"extends": "./bazel-tsconfig-build.json",
6+
"compilerOptions": {
7+
"importHelpers": false,
8+
"types": ["jasmine"]
9+
}
10+
}

src/cdk/BUILD.bazel

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ ng_package(
2626
globals = ROLLUP_GLOBALS,
2727
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
2828
deps = CDK_TARGETS,
29-
tags = ["publish"],
29+
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
30+
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
31+
# files.
32+
tags = ["manual"],
3033
)

src/cdk/a11y/BUILD.bazel

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library")
4-
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
5-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
65

76
ng_module(
87
name = "a11y",
@@ -17,8 +16,7 @@ ng_module(
1716
"//src/cdk/keycodes",
1817
"//src/cdk/observers",
1918
"//src/cdk/platform",
20-
],
21-
tsconfig = "//src/cdk:tsconfig-build.json",
19+
]
2220
)
2321

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

35-
ts_library(
33+
ng_test_library(
3634
name = "a11y_test_sources",
37-
testonly = 1,
3835
srcs = glob(["**/*.spec.ts"]),
3936
deps = [
40-
":a11y",
37+
"@angular//packages/platform-browser",
38+
"@rxjs",
39+
"@rxjs//operators",
4140
"//src/cdk/keycodes",
4241
"//src/cdk/observers",
4342
"//src/cdk/platform",
4443
"//src/cdk/testing",
45-
"@rxjs",
46-
"@rxjs//operators",
47-
],
48-
tsconfig = "//src/cdk:tsconfig-build.json",
44+
":a11y",
45+
]
4946
)
5047

51-
ts_web_test(
48+
ng_web_test_suite(
5249
name = "unit_tests",
53-
# TODO(mmalerba): re-enable once ngfactory issue is resolved.
54-
tags = ["manual"],
55-
bootstrap = [
56-
"//:web_test_bootstrap_scripts",
57-
],
58-
# Do not sort
59-
deps = [
60-
"//:tslib_bundle",
61-
"//:angular_bundles",
62-
"//:angular_test_bundles",
63-
"//test:angular_test_init",
64-
":a11y_test_sources",
65-
],
50+
deps = [":a11y_test_sources"],
6651
)

src/cdk/accordion/BUILD.bazel

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility=["//visibility:public"])
22

3-
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
4-
load("//tools:defaults.bzl", "ng_module")
3+
load("//tools:defaults.bzl", "ng_module", "ts_library", "ng_test_library", "ng_web_test_suite")
54

65
ng_module(
76
name = "accordion",
@@ -12,30 +11,20 @@ ng_module(
1211
"@rxjs",
1312
"//src/cdk/coercion",
1413
"//src/cdk/collections",
15-
],
16-
tsconfig = "//src/cdk:tsconfig-build.json",
14+
]
1715
)
1816

19-
ts_library(
17+
ng_test_library(
2018
name = "accordion_test_sources",
21-
testonly = 1,
2219
srcs = glob(["**/*.spec.ts"]),
2320
deps = [
21+
"@angular//packages/platform-browser",
22+
"@angular//packages/platform-browser/animations",
2423
":accordion",
25-
"@rxjs",
26-
],
27-
tsconfig = "//src/cdk:tsconfig-build.json",
24+
]
2825
)
2926

30-
ts_web_test(
27+
ng_web_test_suite(
3128
name = "unit_tests",
32-
bootstrap = ["//:web_test_bootstrap_scripts"],
33-
# Do not sort
34-
deps = [
35-
"//:tslib_bundle",
36-
"//:angular_bundles",
37-
"//:angular_test_bundles",
38-
"//test:angular_test_init",
39-
":accordion_test_sources",
40-
],
29+
deps = [":accordion_test_sources"],
4130
)

src/cdk/bidi/BUILD.bazel

+9-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility=["//visibility:public"])
22

3-
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
4-
load("//tools:defaults.bzl", "ng_module")
3+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
54

65
ng_module(
76
name = "bidi",
@@ -10,29 +9,19 @@ ng_module(
109
deps = [
1110
"@angular//packages/common",
1211
"@angular//packages/core",
13-
],
14-
tsconfig = "//src/cdk:tsconfig-build.json",
12+
]
1513
)
1614

17-
ts_library(
15+
ng_test_library(
1816
name = "bidi_test_sources",
19-
testonly = 1,
2017
srcs = glob(["**/*.spec.ts"]),
21-
deps = [":bidi"],
22-
tsconfig = "//src/cdk:tsconfig-build.json",
18+
deps = [
19+
"@angular//packages/platform-browser",
20+
":bidi"
21+
],
2322
)
2423

25-
ts_web_test(
24+
ng_web_test_suite(
2625
name = "unit_tests",
27-
bootstrap = [
28-
"//:web_test_bootstrap_scripts",
29-
],
30-
# Do not sort
31-
deps = [
32-
"//:tslib_bundle",
33-
"//:angular_bundles",
34-
"//:angular_test_bundles",
35-
"//test:angular_test_init",
36-
":bidi_test_sources",
37-
],
26+
deps = [":bidi_test_sources"],
3827
)

src/cdk/coercion/BUILD.bazel

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package(default_visibility=["//visibility:public"])
22

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

55
ts_library(
66
name = "coercion",
77
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
88
module_name = "@angular/cdk/coercion",
99
deps = ["@npm//tslib"],
10-
tsconfig = "//src/cdk:tsconfig-build.json",
1110
)
1211

1312
ts_library(
1413
name = "coercion_test_sources",
15-
testonly = 1,
1614
srcs = glob(["**/*.spec.ts"]),
17-
deps = [":coercion"],
15+
deps = [
16+
"@npm//@types/jasmine",
17+
":coercion"
18+
],
19+
testonly = 1,
1820
)
1921

20-
ts_web_test(
22+
jasmine_node_test(
2123
name = "unit_tests",
22-
bootstrap = ["//:web_test_bootstrap_scripts"],
2324
deps = [":coercion_test_sources"],
2425
)

src/cdk/collections/BUILD.bazel

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility=["//visibility:public"])
22

3-
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
4-
load("//tools:defaults.bzl", "ng_module")
3+
load("//tools:defaults.bzl", "ng_module", "ts_library", "jasmine_node_test")
54

65
ng_module(
76
name = "collections",
@@ -11,29 +10,19 @@ ng_module(
1110
"@angular//packages/core",
1211
"@rxjs"
1312
],
14-
tsconfig = "//src/cdk:tsconfig-build.json",
1513
)
1614

1715
ts_library(
1816
name = "collections_test_sources",
19-
testonly = 1,
2017
srcs = glob(["**/*.spec.ts"]),
2118
deps = [
22-
":collections",
23-
"@rxjs",
19+
"@npm//@types/jasmine",
20+
":collections"
2421
],
25-
tsconfig = "//src/cdk:tsconfig-build.json",
22+
testonly = 1,
2623
)
2724

28-
ts_web_test(
25+
jasmine_node_test(
2926
name = "unit_tests",
30-
bootstrap = ["//:web_test_bootstrap_scripts"],
31-
# Do not sort
32-
deps = [
33-
"//:tslib_bundle",
34-
"//:angular_bundles",
35-
"//:angular_test_bundles",
36-
"//test:angular_test_init",
37-
":collections_test_sources",
38-
],
27+
deps = [":collections_test_sources"],
3928
)

0 commit comments

Comments
 (0)