Skip to content

Commit

Permalink
fix(protractor): unable to specify server as configurable attribute (
Browse files Browse the repository at this point in the history
…#2643)

Currently it is not possible to specify the `protractor_web_test`
server using a configurable attribute. i.e. using `select`.

This happens because the `server` attribute is accessed directly
in the macro so that Bazel is unable to respect the `select`. We
fix this by no longer accessing the server in the macro.
  • Loading branch information
devversion authored Apr 29, 2021
1 parent da700dc commit 4965db6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/protractor/protractor_web_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def _protractor_web_test_impl(ctx):
)

runfiles = [configuration] + configuration_sources + on_prepare_sources
server_files = depset()

# If a server has been specified, add it to the runfiles together with it's required runfiles. This is necessary
# as the test executable references the server executable as per `TMPL_server` and executes it.
if ctx.executable.server:
server_files = depset(
[ctx.executable.server],
transitive = [ctx.attr.server[DefaultInfo].default_runfiles.files],
)

ctx.actions.write(
output = ctx.outputs.script,
Expand Down Expand Up @@ -166,7 +175,7 @@ ${{COMMAND}}
files = depset([ctx.outputs.script]),
runfiles = ctx.runfiles(
files = runfiles,
transitive_files = depset(transitive = [files, node_modules]),
transitive_files = depset(transitive = [files, node_modules, server_files]),
# Propagate protractor_bin and its runfiles
collect_data = True,
collect_default = True,
Expand Down Expand Up @@ -269,8 +278,6 @@ def protractor_web_test(
# Our binary dependency must be in data[] for collect_data to pick it up
# FIXME: maybe we can just ask :protractor_bin_name for its runfiles attr
web_test_data = data + [":" + protractor_bin_name]
if server:
web_test_data += [server]

_protractor_web_test(
name = name,
Expand Down
10 changes: 10 additions & 0 deletions packages/protractor/test/protractor-2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ protractor_web_test_suite(
":ts_spec",
],
)

protractor_web_test_suite(
name = "test_suite_with_configured_server",
configuration = ":conf.js",
on_prepare = ":on-prepare.js",
server = select({
"//conditions:default": ":devserver",
}),
deps = [":ts_spec"],
)

0 comments on commit 4965db6

Please sign in to comment.