Skip to content

Commit f6bc578

Browse files
committed
build: test material with bazel
* Supports testing `src/lib` with Bazel.
1 parent e48a6a9 commit f6bc578

File tree

44 files changed

+708
-56
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+708
-56
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ jobs:
8383
- *copy_bazel_config
8484

8585
# TODO(jelbourn): Update this command to run all tests if the Bazel issues have been fixed.
86-
- run: bazel build src/cdk/... src/lib:material
87-
- run: bazel test src/cdk/...
86+
- run: bazel build src/cdk/... src/lib/...
87+
- run: bazel test src/cdk/... src/lib/...
8888

8989
- *save_cache
9090

src/lib/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ ng_package(
4646
packages = ["//src/lib/schematics:npm_package"],
4747
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
4848
deps = MATERIAL_TARGETS,
49-
tags = ["publish"],
49+
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
50+
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
51+
# files.
52+
tags = ["manual"],
5053
)

src/lib/autocomplete/BUILD.bazel

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "autocomplete",
@@ -42,3 +42,30 @@ sass_library(
4242
name = "theme",
4343
srcs = glob(["**/*-theme.scss"]),
4444
)
45+
46+
ng_test_library(
47+
name = "autocomplete_test_sources",
48+
srcs = glob(["**/*.spec.ts"]),
49+
deps = [
50+
"@angular//packages/forms",
51+
"@angular//packages/platform-browser",
52+
"@angular//packages/platform-browser/animations",
53+
"@rxjs",
54+
"@rxjs//operators",
55+
"//src/cdk/bidi",
56+
"//src/cdk/keycodes",
57+
"//src/cdk/overlay",
58+
"//src/cdk/scrolling",
59+
"//src/cdk/testing",
60+
"//src/lib/core",
61+
"//src/lib/form-field",
62+
"//src/lib/input",
63+
":autocomplete"
64+
]
65+
)
66+
67+
ng_web_test_suite(
68+
name = "unit_tests",
69+
deps = [":autocomplete_test_sources"],
70+
prebuilt_theme = True,
71+
)

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {By} from '@angular/platform-browser';
3838
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
3939
import {Observable, Subject, Subscription} from 'rxjs';
4040
import {map, startWith} from 'rxjs/operators';
41-
import {MatInputModule} from '../input/index';
41+
import {MatInputModule} from '@angular/material/input';
4242
import {
4343
getMatAutocompleteMissingPanelError,
4444
MAT_AUTOCOMPLETE_DEFAULT_OPTIONS,

src/lib/badge/BUILD.bazel

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

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "badge",
@@ -26,3 +26,19 @@ sass_library(
2626
name = "theme",
2727
srcs = glob(["**/*-theme.scss"]),
2828
)
29+
30+
ng_test_library(
31+
name = "badge_test_sources",
32+
srcs = glob(["**/*.spec.ts"]),
33+
deps = [
34+
"@angular//packages/platform-browser",
35+
"//src/lib/core",
36+
":badge",
37+
]
38+
)
39+
40+
ng_web_test_suite(
41+
name = "unit_tests",
42+
deps = [":badge_test_sources"]
43+
)
44+

src/lib/bottom-sheet/BUILD.bazel

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "bottom-sheet",
@@ -42,3 +42,26 @@ sass_library(
4242
name = "theme",
4343
srcs = glob(["**/*-theme.scss"]),
4444
)
45+
46+
ng_test_library(
47+
name = "bottom_sheet_test_sources",
48+
srcs = glob(["**/*.spec.ts"]),
49+
deps = [
50+
"@angular//packages/common",
51+
"@angular//packages/common/testing",
52+
"@angular//packages/platform-browser/animations",
53+
"//src/cdk/bidi",
54+
"//src/cdk/keycodes",
55+
"//src/cdk/overlay",
56+
"//src/cdk/scrolling",
57+
"//src/cdk/testing",
58+
":bottom-sheet",
59+
]
60+
)
61+
62+
ng_web_test_suite(
63+
name = "unit_tests",
64+
deps = [":bottom_sheet_test_sources"],
65+
prebuilt_theme = True,
66+
)
67+

src/lib/button-toggle/BUILD.bazel

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "button-toggle",
@@ -34,3 +34,20 @@ sass_library(
3434
name = "theme",
3535
srcs = glob(["**/*-theme.scss"]),
3636
)
37+
38+
ng_test_library(
39+
name = "button_toggle_test_sources",
40+
srcs = glob(["**/*.spec.ts"]),
41+
deps = [
42+
"@angular//packages/forms",
43+
"@angular//packages/platform-browser",
44+
"//src/cdk/testing",
45+
":button-toggle",
46+
]
47+
)
48+
49+
ng_web_test_suite(
50+
name = "unit_tests",
51+
deps = [":button_toggle_test_sources"]
52+
)
53+

src/lib/button/BUILD.bazel

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "button",
@@ -41,3 +41,18 @@ sass_library(
4141
name = "theme",
4242
srcs = glob(["**/*-theme.scss"]),
4343
)
44+
45+
ng_test_library(
46+
name = "button_test_sources",
47+
srcs = glob(["**/*.spec.ts"]),
48+
deps = [
49+
"@angular//packages/platform-browser",
50+
"//src/lib/core",
51+
":button"
52+
]
53+
)
54+
55+
ng_web_test_suite(
56+
name = "unit_tests",
57+
deps = [":button_test_sources"]
58+
)

src/lib/checkbox/BUILD.bazel

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "checkbox",
@@ -36,3 +36,20 @@ sass_library(
3636
name = "theme",
3737
srcs = glob(["**/*-theme.scss"]),
3838
)
39+
40+
ng_test_library(
41+
name = "checkbox_test_sources",
42+
srcs = glob(["**/*.spec.ts"]),
43+
deps = [
44+
"@angular//packages/forms",
45+
"@angular//packages/platform-browser",
46+
"//src/cdk/observers",
47+
"//src/cdk/testing",
48+
":checkbox",
49+
]
50+
)
51+
52+
ng_web_test_suite(
53+
name = "unit_tests",
54+
deps = [":checkbox_test_sources"]
55+
)

src/lib/chips/BUILD.bazel

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "chips",
@@ -40,3 +40,27 @@ sass_library(
4040
name = "theme",
4141
srcs = glob(["**/*-theme.scss"]),
4242
)
43+
44+
ng_test_library(
45+
name = "chips_test_sources",
46+
srcs = glob(["**/*.spec.ts"]),
47+
deps = [
48+
"@angular//packages/animations",
49+
"@angular//packages/forms",
50+
"@angular//packages/platform-browser",
51+
"@angular//packages/platform-browser/animations",
52+
"//src/cdk/a11y",
53+
"//src/cdk/bidi",
54+
"//src/cdk/keycodes",
55+
"//src/cdk/platform",
56+
"//src/cdk/testing",
57+
"//src/lib/form-field",
58+
"//src/lib/input",
59+
":chips",
60+
]
61+
)
62+
63+
ng_web_test_suite(
64+
name = "unit_tests",
65+
deps = [":chips_test_sources"]
66+
)

src/lib/chips/chip-list.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {FormControl, FormsModule, NgForm, ReactiveFormsModule, Validators} from
3535
import {MatFormFieldModule} from '@angular/material/form-field';
3636
import {By} from '@angular/platform-browser';
3737
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
38-
import {MatInputModule} from '../input/index';
38+
import {MatInputModule} from '@angular/material/input';
3939
import {MatChip} from './chip';
4040
import {MatChipInputEvent} from './chip-input';
4141
import {MatChipEvent, MatChipList, MatChipRemove, MatChipsModule} from './index';

src/lib/core/BUILD.bazel

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
44
load("//:packages.bzl", "MATERIAL_PACKAGES")
5-
load("//tools:defaults.bzl", "ng_module")
5+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
66

77
exports_files(["theming/_theming.scss"])
88

@@ -30,7 +30,6 @@ ng_module(
3030
],
3131
)
3232

33-
3433
# TODO(jelbourn): remove this when sass_library acts like a filegroup
3534
filegroup(
3635
name = "core_scss_partials",
@@ -106,3 +105,24 @@ sass_library(
106105
name = "theme",
107106
srcs = glob(["**/*-theme.scss"]),
108107
)
108+
109+
#################
110+
# Test targets
111+
#################
112+
113+
ng_test_library(
114+
name = "core_test_sources",
115+
srcs = glob(["**/*.spec.ts"]),
116+
deps = [
117+
"@angular//packages/platform-browser",
118+
"@angular//packages/platform-browser/animations",
119+
"//src/cdk/platform",
120+
"//src/cdk/testing",
121+
"//src/lib/core",
122+
]
123+
)
124+
125+
ng_web_test_suite(
126+
name = "unit_tests",
127+
deps = [":core_test_sources"]
128+
)

src/lib/datepicker/BUILD.bazel

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility=["//visibility:public"])
22

33
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
4-
load("//tools:defaults.bzl", "ng_module")
4+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "datepicker",
@@ -64,9 +64,34 @@ sass_binary(
6464
deps = ["//src/lib/core:core_scss_lib"],
6565
)
6666

67-
68-
6967
sass_library(
7068
name = "theme",
7169
srcs = glob(["**/*-theme.scss"]),
7270
)
71+
72+
ng_test_library(
73+
name = "datepicker_test_sources",
74+
srcs = glob(["**/*.spec.ts"]),
75+
deps = [
76+
"@angular//packages/forms",
77+
"@angular//packages/platform-browser",
78+
"@angular//packages/platform-browser-dynamic/testing",
79+
"@angular//packages/platform-browser/animations",
80+
"@rxjs",
81+
"//src/cdk/bidi",
82+
"//src/cdk/keycodes",
83+
"//src/cdk/overlay",
84+
"//src/cdk/scrolling",
85+
"//src/cdk/testing",
86+
"//src/lib/core",
87+
"//src/lib/form-field",
88+
"//src/lib/input",
89+
":datepicker",
90+
]
91+
)
92+
93+
ng_web_test_suite(
94+
name = "unit_tests",
95+
deps = [":datepicker_test_sources"],
96+
prebuilt_theme = True,
97+
)

src/lib/datepicker/datepicker.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {MatFormField, MatFormFieldModule} from '@angular/material/form-field';
2525
import {By} from '@angular/platform-browser';
2626
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
2727
import {Subject} from 'rxjs';
28-
import {MatInputModule} from '../input/index';
28+
import {MatInputModule} from '@angular/material/input';
2929
import {MatDatepicker} from './datepicker';
3030
import {MatDatepickerInput} from './datepicker-input';
3131
import {MatDatepickerToggle} from './datepicker-toggle';
@@ -604,7 +604,7 @@ describe('MatDatepicker', () => {
604604

605605
// When the calendar is in year view, the first cell should be for a month rather than
606606
// for a date.
607-
expect(firstCalendarCell.textContent)
607+
expect(firstCalendarCell.textContent!.trim())
608608
.toBe('JAN', 'Expected the calendar to be in year-view');
609609
});
610610

@@ -654,7 +654,7 @@ describe('MatDatepicker', () => {
654654

655655
// When the calendar is in year view, the first cell should be for a month rather than
656656
// for a date.
657-
expect(firstCalendarCell.textContent)
657+
expect(firstCalendarCell.textContent!.trim())
658658
.toBe('2016', 'Expected the calendar to be in multi-year-view');
659659
});
660660

0 commit comments

Comments
 (0)