@@ -9,8 +9,7 @@ load("//:pkg-externals.bzl", "PKG_EXTERNALS")
99load ("//tools/markdown-to-html:index.bzl" , _markdown_to_html = "markdown_to_html" )
1010load ("//tools/extract-tokens:index.bzl" , _extract_tokens = "extract_tokens" )
1111load ("//tools/bazel:ng_package_interop.bzl" , "ng_package_interop" )
12- load ("//tools:defaults2.bzl" , "spec_bundle" , _karma_web_test_suite = "karma_web_test_suite" )
13- load ("@rules_browsers//src/protractor_test:index.bzl" , "protractor_test" )
12+ load ("//tools:defaults2.bzl" , _ng_web_test_suite = "ng_web_test_suite" )
1413
1514npmPackageSubstitutions = select ({
1615 "//tools:stamp" : NPM_PACKAGE_SUBSTITUTIONS ,
@@ -20,7 +19,7 @@ npmPackageSubstitutions = select({
2019# Re-exports to simplify build file load statements
2120markdown_to_html = _markdown_to_html
2221extract_tokens = _extract_tokens
23- karma_web_test_suite = _karma_web_test_suite
22+ ng_web_test_suite = _ng_web_test_suite
2423
2524def sass_binary (sourcemap = False , include_paths = [], ** kwargs ):
2625 _sass_binary (
@@ -122,89 +121,3 @@ def pkg_npm(name, visibility = None, **kwargs):
122121 visibility = visibility ,
123122 ** kwargs
124123 )
125-
126- pkg_tar (
127- name = name + "_archive" ,
128- srcs = [":%s" % name ],
129- package_dir = "package/" ,
130- extension = "tar.gz" ,
131- strip_prefix = "./%s" % name ,
132- # Target should not build on CI unless it is explicitly requested.
133- tags = ["manual" ],
134- visibility = visibility ,
135- )
136-
137- def protractor_web_test_suite (name , deps , ** kwargs ):
138- spec_bundle (
139- name = "%s_bundle" % name ,
140- deps = deps ,
141- external = ["protractor" , "selenium-webdriver" ],
142- )
143-
144- protractor_test (
145- name = name ,
146- deps = [":%s_bundle" % name ],
147- extra_config = {
148- "useAllAngular2AppRoots" : True ,
149- "allScriptsTimeout" : 120000 ,
150- "getPageTimeout" : 120000 ,
151- "jasmineNodeOpts" : {
152- "defaultTimeoutInterval" : 120000 ,
153- },
154- # Since we want to use async/await we don't want to mix up with selenium's promise
155- # manager. In order to enforce this, we disable the promise manager.
156- "SELENIUM_PROMISE_MANAGER" : False ,
157- },
158- data = [
159- "//:node_modules/protractor" ,
160- "//:node_modules/selenium-webdriver" ,
161- ],
162- ** kwargs
163- )
164-
165- def ng_web_test_suite (deps = [], static_css = [], ** kwargs ):
166- # Always include a prebuilt theme in the test suite because otherwise tests, which depend on CSS
167- # that is needed for measuring, will unexpectedly fail. Also always adding a prebuilt theme
168- # reduces the amount of setup that is needed to create a test suite Bazel target. Note that the
169- # prebuilt theme will be also added to CDK test suites but shouldn't affect anything.
170- static_css = static_css + [
171- "//src/material/prebuilt-themes:azure-blue" ,
172- ]
173-
174- bootstrap = []
175-
176- # Workaround for https://github.com/bazelbuild/rules_typescript/issues/301
177- # Since some of our tests depend on CSS files which are not part of the `ng_project` rule,
178- # we need to somehow load static CSS files within Karma (e.g. overlay prebuilt). Those styles
179- # are required for successful test runs. Since the `karma_web_test_suite` rule currently only
180- # allows JS files to be included and served within Karma, we need to create a JS file that
181- # loads the given CSS file.
182- for css_label in static_css :
183- css_id = "static-css-file-%s" % (css_label .replace ("/" , "_" ).replace (":" , "-" ))
184- bootstrap .append (":%s" % css_id )
185-
186- native .genrule (
187- name = css_id ,
188- srcs = [css_label ],
189- outs = ["%s.css.init.js" % css_id ],
190- output_to_bindir = True ,
191- cmd = """
192- files=($(execpaths %s))
193- # Escape all double-quotes so that the content can be safely inlined into the
194- # JS template. Note that it needs to be escaped a second time because the string
195- # will be evaluated first in Bash and will then be stored in the JS output.
196- css_content=$$(cat $${files[0]} | sed 's/"/\\ \\ "/g')
197- js_template='var cssElement = document.createElement("style"); \
198- cssElement.type = "text/css"; \
199- cssElement.innerHTML = "'"$$css_content"'"; \
200- document.head.appendChild(cssElement);'
201- echo "$$js_template" > $@
202- """ % css_label ,
203- )
204-
205- karma_web_test_suite (
206- # Depend on our custom test initialization script. This needs to be the first dependency.
207- deps = deps ,
208- bootstrap = ["//test:angular_test_init" ] + bootstrap ,
209- ** kwargs
210- )
0 commit comments