-
Notifications
You must be signed in to change notification settings - Fork 57
/
web.bzl
144 lines (124 loc) · 4.81 KB
/
web.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Public definitions for web_test related build rules."""
load(
"//web/internal:browser.bzl",
browser_alias = "browser",
)
load("//web/internal:constants.bzl", "DEFAULT_TEST_SUITE_TAGS")
load(
"//web/internal:web_test.bzl",
web_test_alias = "web_test",
)
load(
"//web/internal:web_test_archive.bzl",
web_test_archive_alias = "web_test_archive",
)
load(
"//web/internal:web_test_config.bzl",
web_test_config_alias = "web_test_config",
)
load(
"//web/internal:web_test_files.bzl",
web_test_files_alias = "web_test_files",
)
load(
"//web/internal:web_test_named_executable.bzl",
web_test_named_executable_alias = "web_test_named_executable",
)
load(
"//web/internal:web_test_named_file.bzl",
web_test_named_file_alias = "web_test_named_file",
)
load("@bazel_skylib//:lib.bzl", "types")
def web_test_suite(
name,
browsers,
test_suite_tags = None,
visibility = None,
**kwargs):
"""Defines a test_suite of web_test targets to be run.
Args:
name: Name; required. A unique name for this rule.
browsers: List of labels; required. The browsers with which to run the test.
test_suite_tags: List of strings; tags for the generated test_suite rule.
visibility: List of labels; optional.
**kwargs: Additional arguments for web_test rule.
"""
if not types.is_list(browsers):
fail("expected a list for attribute 'browsers' but got '%s'" %
type(browsers))
if not browsers:
fail("expected non-empty value for attribute 'browsers'")
# Check explicitly for None so that users can set this to the empty list.
if test_suite_tags == None:
test_suite_tags = DEFAULT_TEST_SUITE_TAGS
tests = []
for browser in browsers: # pylint: disable=redefined-outer-name
unqualified_browser = browser.split(":", 2)[1]
test_name = name + "_" + unqualified_browser
overridden_kwargs = _get_kwargs(unqualified_browser, kwargs)
web_test(
name = test_name,
browser = browser,
visibility = visibility,
**overridden_kwargs
)
tests += [test_name]
native.test_suite(
name = name,
tests = tests,
tags = test_suite_tags,
visibility = visibility,
)
def _get_kwargs(browser, in_kwargs):
"""Returns the arguments that should be used for a particular browser."""
out_kwargs = {}
for k, v in in_kwargs.items():
if types.is_dict(v):
if browser in v:
out_kwargs[k] = v[browser]
elif "default" in v:
out_kwargs[k] = v["default"]
else:
out_kwargs[k] = v
if not out_kwargs["tags"]:
out_kwargs["tags"] = ["browser:" + browser]
else:
out_kwargs["tags"] = ["browser:" + browser] + out_kwargs["tags"]
return out_kwargs
def browser(testonly = True, **kwargs):
"""Wrapper around browser to correctly set defaults."""
browser_alias(testonly = testonly, **kwargs)
def web_test(config = None, launcher = None, size = None, **kwargs):
"""Wrapper around web_test to correctly set defaults."""
config = config or str(Label("//web:default_config"))
launcher = launcher or str(Label("//go/wtl/main"))
size = size or "large"
web_test_alias(config = config, launcher = launcher, size = size, **kwargs)
def web_test_config(testonly = True, **kwargs):
"""Wrapper around web_test_config to correctly set defaults."""
web_test_config_alias(testonly = testonly, **kwargs)
def web_test_named_executable(testonly = True, **kwargs):
"""Wrapper around web_test_named_executable to correctly set defaults."""
web_test_named_executable_alias(testonly = testonly, **kwargs)
def web_test_named_file(testonly = True, **kwargs):
"""Wrapper around web_test_named_file to correctly set defaults."""
web_test_named_file_alias(testonly = testonly, **kwargs)
def web_test_archive(testonly = True, **kwargs):
"""Wrapper around web_test_archive to correctly set defaults."""
web_test_archive_alias(testonly = testonly, **kwargs)
def web_test_files(testonly = True, **kwargs):
"""Wrapper around web_test_files to correctly set defaults."""
web_test_files_alias(testonly = testonly, **kwargs)