Skip to content

build: run overlay and text-field tests with Bazel #13637

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
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
12 changes: 8 additions & 4 deletions src/cdk/overlay/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package(default_visibility=["//visibility:public"])

load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library")
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

ng_module(
Expand Down Expand Up @@ -32,6 +32,12 @@ sass_library(
srcs = [":overlay_scss_partials"],
)

sass_binary(
name = "overlay_prebuilt_scss",
src = "overlay-prebuilt.scss",
deps = [":overlay_scss_lib"]
)

ng_test_library(
name = "overlay_test_sources",
srcs = glob(["**/*.spec.ts"]),
Expand All @@ -54,7 +60,5 @@ ng_test_library(
ng_web_test_suite(
name = "unit_tests",
deps = [":overlay_test_sources"],
# TODO(devversion): Disabling this test until we found a way to set the screen resolution
# of the web test instance. Currently all positioning tests are not passing.
tags = ["manual"]
static_css = ["overlay_prebuilt_scss"],
)
4 changes: 1 addition & 3 deletions src/cdk/text-field/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ ng_test_library(
ng_web_test_suite(
name = "unit_tests",
deps = [":text-field_test_sources"],
# TODO(devversion): Disabling this test until we found a way to set the screen resolution
# of the web test instance. Currently all positioning tests are not passing.
tags = ["manual"],
static_css = [":text_field_prebuilt_scss"]
)
29 changes: 28 additions & 1 deletion tools/defaults.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,34 @@ def ng_test_library(deps = [], tsconfig = None, **kwargs):
**kwargs
)

def ng_web_test_suite(deps = [], srcs = [], **kwargs):
def ng_web_test_suite(deps = [], srcs = [], static_css = [], **kwargs):
# Workaround for https://github.com/bazelbuild/rules_typescript/issues/301
# Since some of our tests depend on CSS files which are not part of the `ng_module` rule,
# we need to somehow load static CSS files within Karma (e.g. overlay prebuilt). Those styles
# are required for successful test runs. Since the `ts_web_test_suite` rule currently only
# allows JS files to be included and served within Karma, we need to create a JS file that
# loads the given CSS file.
for css_label in static_css:
css_id = "static-css-file-%s" % (css_label.strip(':').strip('/'))
deps += [":%s" % css_id]

native.genrule(
name = css_id,
srcs = [css_label],
outs = ["%s.js" % css_id],
output_to_bindir = True,
cmd = """
files=($(locations %s))
css_content=$$(cat $${files[0]})
js_template="var cssElement = document.createElement('style'); \
cssElement.type = 'text/css'; \
cssElement.innerHTML = '$$css_content'; \
document.head.appendChild(cssElement);"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a separate file that's included in the rule rather than creating it on-demand with a genrule?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure what you mean? A separate rule for generating this file?

Not sure if that would be worth the effort.

This is just a matrix function, so we don't have access to a context.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean creating a real js file like overlay-test-style-include.js that's added to the deps of just the overlay rule?

Copy link
Member Author

@devversion devversion Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that will work. I'm not sure how we could load the prebuilt CSS output into the file without a custom rule/or genrule

-- Actually it would work if we somehow know the path to the CSS file which is served by Karma (just not included)

I can look into it tomorrow, if we want to go with your proposed approach

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now.


echo $$js_template > $@
""" % css_label
)

_ts_web_test_suite(
# Required for running the compiled ng modules that use TypeScript import helpers.
srcs = ["@npm//node_modules/tslib:tslib.js"] + srcs,
Expand Down