-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
135 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
filegroup( | ||
name = "url", | ||
srcs = glob( | ||
include = ["url/**/*"], | ||
allow_empty = True, | ||
directories = glob( | ||
["*"], | ||
exclude = glob( | ||
[ | ||
"*", | ||
".*", | ||
], | ||
exclude_directories = 1, | ||
), | ||
visibility = ["//visibility:public"], | ||
exclude_directories = 0, | ||
) | ||
|
||
[filegroup( | ||
name = dir, | ||
srcs = glob(["{}/**/*".format(dir)]), | ||
visibility = ["//visibility:public"], | ||
) for dir in directories] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
load("//:build/wd_test.bzl", "wd_test") | ||
|
||
# The public entry point is a macro named wpt_test. It first invokes a private | ||
# rule named _wpt_test_gen to access the files in the wpt filegroup and | ||
# generate a corresponding wd-test file. It then invokes the wd_test macro | ||
# to set up the test. | ||
|
||
def wpt_test(name, wpt_directory, test_js): | ||
test_gen_rule = "{}@_wpt_test_gen".format(name) | ||
_wpt_test_gen( | ||
name = test_gen_rule, | ||
test_name = name, | ||
wpt_directory = wpt_directory, | ||
test_js = test_js, | ||
) | ||
|
||
wd_test( | ||
name = "{}".format(name), | ||
src = test_gen_rule, | ||
args = ["--experimental"], | ||
data = [ | ||
"//src/wpt:wpt-test-harness", | ||
test_js, | ||
wpt_directory, | ||
], | ||
) | ||
|
||
def _wpt_test_gen_impl(ctx): | ||
src = ctx.actions.declare_file("{}.wd-test".format(ctx.attr.test_name)) | ||
ctx.actions.write( | ||
output = src, | ||
content = WPT_TEST_TEMPLATE.format( | ||
test_name = ctx.attr.test_name, | ||
test_js = wd_relative_path(ctx.file.test_js), | ||
modules = generate_external_modules(ctx.attr.wpt_directory.files), | ||
date = "2024-10-10", # FIXME: we don't wanna be hardcoding that type of shizz | ||
), | ||
) | ||
|
||
return DefaultInfo( | ||
files = depset([src]), | ||
) | ||
|
||
WPT_TEST_TEMPLATE = """ | ||
using Workerd = import "/workerd/workerd.capnp"; | ||
const unitTests :Workerd.Config = ( | ||
services = [ | ||
( name = "{test_name}", | ||
worker = ( | ||
modules = [ | ||
(name = "worker", esModule = embed "{test_js}"), | ||
(name = "harness", esModule = embed "../../../../../workerd/src/wpt/harness.js"), | ||
{modules} | ||
], | ||
bindings = [ | ||
(name = "wpt", service = "wpt"), | ||
], | ||
compatibilityDate = "{date}", | ||
compatibilityFlags = ["nodejs_compat_v2", "experimental"], | ||
) | ||
), | ||
( | ||
name = "wpt", | ||
disk = ".", | ||
) | ||
], | ||
);""" | ||
|
||
def wd_relative_path(file): | ||
""" | ||
Returns a relative path which can be referenced in the .wd-test file. | ||
This is four directories up from the bazel short_path | ||
""" | ||
return "../" * 4 + file.short_path | ||
|
||
def generate_external_modules(files): | ||
""" | ||
Generates a string for all files in the given directory in the specified format. | ||
Example for a JS file: | ||
(name = "url-origin.any.js", esModule = embed "../../../../../wpt/url/url-origin.any.js"), | ||
Example for a JSON file: | ||
(name = "resources/urltestdata.json", json = embed "../../../../../wpt/url/resources/urltestdata.json"), | ||
""" | ||
result = [] | ||
|
||
for file in files.to_list(): | ||
file_path = wd_relative_path(file) | ||
if file.basename.endswith(".js"): | ||
entry = """(name = "{}", esModule = embed "{}")""".format(file.basename, file_path) | ||
elif file.basename.endswith(".json"): | ||
entry = """(name = "{}", json = embed "{}")""".format(file.basename, file_path) | ||
else: | ||
# For other file types, you can add more conditions or skip them | ||
continue | ||
|
||
result.append(entry) | ||
|
||
return ",\n".join(result) | ||
|
||
_wpt_test_gen = rule( | ||
implementation = _wpt_test_gen_impl, | ||
attrs = { | ||
# A string to use as the test name. Used in the wd-test filename and the worker's name | ||
"test_name": attr.string(), | ||
# A file group representing a directory of wpt tests. All files in the group will be embedded. | ||
"wpt_directory": attr.label(), | ||
# A JS file containing the actual test logic. | ||
"test_js": attr.label(allow_single_file = True), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
load("//:build/wd_test.bzl", "wd_test") | ||
load("//src/workerd/api/wpt:generate-tests.bzl", "gen_wpt_tests") | ||
load("//:build/wpt_test.bzl", "wpt_test") | ||
|
||
gen_wpt_tests(glob(["**/*.js"])) | ||
[wpt_test( | ||
name = file.replace("-test.js", ""), | ||
test_js = file, | ||
wpt_directory = "@wpt//:{}".format(file.replace("-test.js", "")), | ||
) for file in glob(["*-test.js"])] |
This file was deleted.
Oops, something went wrong.