Skip to content

Commit 4f0670d

Browse files
committed
WPT: Allow creating test variants + support autogates
1 parent d3fa366 commit 4f0670d

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

build/wpt_test.bzl

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
load("@bazel_skylib//lib:paths.bzl", "paths")
66
load("//:build/wd_test.bzl", "wd_test")
77

8-
def wpt_test(name, wpt_directory, test_config):
8+
def wpt_test(name, wpt_directory, config, autogates = []):
99
"""
1010
Main entry point.
1111
1. Generates a workerd test suite in JS. This contains the logic to run
@@ -16,7 +16,7 @@ def wpt_test(name, wpt_directory, test_config):
1616
"""
1717

1818
js_test_gen_rule = "{}@_wpt_js_test_gen".format(name)
19-
test_config_as_js = test_config.removesuffix(".ts") + ".js"
19+
test_config_as_js = config.removesuffix(".ts") + ".js"
2020
wpt_tsproject = "//src/wpt:wpt-all@tsproject"
2121
harness_as_js = "//src/wpt:harness/harness.js"
2222
compat_date = "//src/workerd/io:trimmed-supported-compatibility-date.txt"
@@ -38,6 +38,7 @@ def wpt_test(name, wpt_directory, test_config):
3838
test_js_generated = js_test_gen_rule,
3939
harness = harness_as_js,
4040
compat_date = compat_date,
41+
autogates = autogates,
4142
)
4243

4344
wd_test(
@@ -151,6 +152,7 @@ def _wpt_wd_test_gen_impl(ctx):
151152
bindings = generate_external_bindings(src.owner, ctx.attr.wpt_directory.files),
152153
harness = wd_relative_path(src.owner, ctx.file.harness),
153154
compat_date = wd_relative_path(src.owner, ctx.file.compat_date),
155+
autogates = generate_autogates_field(ctx.attr.autogates),
154156
),
155157
)
156158

@@ -183,8 +185,20 @@ const unitTests :Workerd.Config = (
183185
disk = ".",
184186
)
185187
],
188+
{autogates}
186189
);"""
187190

191+
def generate_autogates_field(autogates):
192+
"""
193+
Generates a capnproto fragment listing the specified autogates.
194+
"""
195+
196+
if not autogates:
197+
return ""
198+
199+
autogate_list = ", ".join(['"{}"'.format(autogate) for autogate in autogates])
200+
return "autogates = [{}],".format(autogate_list)
201+
188202
def wd_relative_path(label, target):
189203
"""
190204
Generates a path that can be used in a .wd-test file to refer to another file. Paths are relative
@@ -243,6 +257,8 @@ _wpt_wd_test_gen = rule(
243257
"harness": attr.label(allow_single_file = True),
244258
# Target specifying the location of the trimmed-supported-compatibility-date.txt file
245259
"compat_date": attr.label(allow_single_file = True),
260+
# A list of autogates to specify in the generated wd-test file
261+
"autogates": attr.string_list(),
246262
},
247263
)
248264

src/wpt/BUILD.bazel

+19-11
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@ load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
22
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
33
load("//:build/wpt_test.bzl", "wpt_test")
44

5-
harness_srcs = glob(
6-
[
7-
"harness/*.ts",
8-
],
5+
wpt_test(
6+
name = "url",
7+
config = "url-test.ts",
8+
wpt_directory = "@wpt//:url",
99
)
1010

11-
test_srcs = glob(["**/*-test.ts"])
11+
wpt_test(
12+
name = "urlpattern",
13+
config = "urlpattern-test.ts",
14+
wpt_directory = "@wpt//:urlpattern",
15+
)
1216

13-
srcs = harness_srcs + test_srcs
17+
wpt_test(
18+
name = "dom/abort",
19+
config = "dom/abort-test.ts",
20+
wpt_directory = "@wpt//:dom/abort",
21+
)
1422

15-
[wpt_test(
16-
name = file.replace("-test.ts", ""),
17-
test_config = file,
18-
wpt_directory = "@wpt//:{}".format(file.replace("-test.ts", "")),
19-
) for file in test_srcs]
23+
srcs = glob(
24+
[
25+
"**/*.ts",
26+
],
27+
)
2028

2129
ts_project(
2230
name = "wpt-all@tsproject",

0 commit comments

Comments
 (0)