Skip to content

Commit 5c8e0cb

Browse files
devversionjosephperrott
authored andcommitted
build: run overlay and text-field tests with Bazel (#13637)
1 parent 0c5b6e9 commit 5c8e0cb

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

src/cdk/overlay/BUILD.bazel

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

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

66
ng_module(
@@ -32,6 +32,12 @@ sass_library(
3232
srcs = [":overlay_scss_partials"],
3333
)
3434

35+
sass_binary(
36+
name = "overlay_prebuilt_scss",
37+
src = "overlay-prebuilt.scss",
38+
deps = [":overlay_scss_lib"]
39+
)
40+
3541
ng_test_library(
3642
name = "overlay_test_sources",
3743
srcs = glob(["**/*.spec.ts"]),
@@ -54,7 +60,5 @@ ng_test_library(
5460
ng_web_test_suite(
5561
name = "unit_tests",
5662
deps = [":overlay_test_sources"],
57-
# TODO(devversion): Disabling this test until we found a way to set the screen resolution
58-
# of the web test instance. Currently all positioning tests are not passing.
59-
tags = ["manual"]
63+
static_css = ["overlay_prebuilt_scss"],
6064
)

src/cdk/text-field/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,5 @@ ng_test_library(
5050
ng_web_test_suite(
5151
name = "unit_tests",
5252
deps = [":text-field_test_sources"],
53-
# TODO(devversion): Disabling this test until we found a way to set the screen resolution
54-
# of the web test instance. Currently all positioning tests are not passing.
55-
tags = ["manual"],
53+
static_css = [":text_field_prebuilt_scss"]
5654
)

tools/defaults.bzl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,34 @@ def ng_test_library(deps = [], tsconfig = None, **kwargs):
6868
**kwargs
6969
)
7070

71-
def ng_web_test_suite(deps = [], srcs = [], **kwargs):
71+
def ng_web_test_suite(deps = [], srcs = [], static_css = [], **kwargs):
72+
# Workaround for https://github.com/bazelbuild/rules_typescript/issues/301
73+
# Since some of our tests depend on CSS files which are not part of the `ng_module` rule,
74+
# we need to somehow load static CSS files within Karma (e.g. overlay prebuilt). Those styles
75+
# are required for successful test runs. Since the `ts_web_test_suite` rule currently only
76+
# allows JS files to be included and served within Karma, we need to create a JS file that
77+
# loads the given CSS file.
78+
for css_label in static_css:
79+
css_id = "static-css-file-%s" % (css_label.strip(':').strip('/'))
80+
deps += [":%s" % css_id]
81+
82+
native.genrule(
83+
name = css_id,
84+
srcs = [css_label],
85+
outs = ["%s.js" % css_id],
86+
output_to_bindir = True,
87+
cmd = """
88+
files=($(locations %s))
89+
css_content=$$(cat $${files[0]})
90+
js_template="var cssElement = document.createElement('style'); \
91+
cssElement.type = 'text/css'; \
92+
cssElement.innerHTML = '$$css_content'; \
93+
document.head.appendChild(cssElement);"
94+
95+
echo $$js_template > $@
96+
""" % css_label
97+
)
98+
7299
_ts_web_test_suite(
73100
# Required for running the compiled ng modules that use TypeScript import helpers.
74101
srcs = ["@npm//node_modules/tslib:tslib.js"] + srcs,

0 commit comments

Comments
 (0)