@@ -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