Skip to content

Commit

Permalink
Unrevert WPT dom/abort tests (#3462)
Browse files Browse the repository at this point in the history
  • Loading branch information
npaun authored Feb 4, 2025
1 parent b6c2587 commit a0b8d14
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 107 deletions.
22 changes: 12 additions & 10 deletions build/BUILD.wpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
# Licensed under the Apache 2.0 license found in the LICENSE file or at:
# https://opensource.org/licenses/Apache-2.0

directories = glob(
["*"],
exclude = glob(
["*"],
exclude_directories = 1,
) + [
".*",
load("@workerd//:build/wpt_test.bzl", "wpt_get_directories")

[filegroup(
name = dir,
srcs = glob(["{}/**/*".format(dir)]),
visibility = ["//visibility:public"],
) for dir in wpt_get_directories(
excludes = [
"dom",
],
exclude_directories = 0,
)
root = "",
)]

[filegroup(
name = dir,
srcs = glob(["{}/**/*".format(dir)]),
visibility = ["//visibility:public"],
) for dir in directories]
) for dir in wpt_get_directories(root = "dom")]
61 changes: 44 additions & 17 deletions build/wpt_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def wpt_test(name, wpt_directory, test_config):

js_test_gen_rule = "{}@_wpt_js_test_gen".format(name)
test_config_as_js = test_config.removesuffix(".ts") + ".js"
harness = "//src/wpt:wpt-test-harness"
compat_date = "//src/workerd/io:trimmed-supported-compatibility-date.txt"

_wpt_js_test_gen(
name = js_test_gen_rule,
Expand All @@ -31,22 +33,41 @@ def wpt_test(name, wpt_directory, test_config):
wpt_directory = wpt_directory,
test_config = test_config_as_js,
test_js_generated = js_test_gen_rule,
harness = harness,
compat_date = compat_date,
)

wd_test(
name = "{}".format(name),
src = wd_test_gen_rule,
args = ["--experimental"],
ts_deps = ["//src/wpt:wpt-test-harness"],
ts_deps = [harness],
data = [
"//src/wpt:wpt-test-harness",
harness,
test_config,
js_test_gen_rule,
wpt_directory,
"//src/workerd/io:trimmed-supported-compatibility-date.txt",
compat_date,
],
)

def wpt_get_directories(root, excludes = []):
"""
Globs for files within a WPT directory structure, starting from root.
In addition to an explicitly provided excludes argument, hidden directories
and top-level files are also excluded as they don't contain test content.
"""

root_pattern = "{}/*".format(root) if root else "*"
return native.glob(
[root_pattern],
exclude = native.glob(
[root_pattern],
exclude_directories = 1,
) + [".*"] + excludes,
exclude_directories = 0,
)

def _wpt_js_test_gen_impl(ctx):
"""
Generates a workerd test suite in JS. This contains the logic to run
Expand Down Expand Up @@ -75,7 +96,7 @@ def generate_external_cases(files):

for file in files.to_list():
if file.extension == "js":
entry = """export const {} = run(config, '{}');""".format(test_case_name(file.basename), file.basename)
entry = """export const {} = run('{}');""".format(test_case_name(file.basename), file.basename)
result.append(entry)

return "\n".join(result)
Expand All @@ -97,9 +118,11 @@ def test_case_name(filename):

WPT_JS_TEST_TEMPLATE = """// This file is autogenerated by wpt_test.bzl
// DO NOT EDIT.
import {{ run }} from 'wpt:harness';
import {{ createRunner }} from 'wpt:harness';
import config from '{test_config}';
const run = createRunner(config);
{cases}
"""

Expand All @@ -109,15 +132,16 @@ def _wpt_wd_test_gen_impl(ctx):
paths to modules needed to run the test: generated test suite, test config
file, WPT test scripts, associated JSON resources.
"""

src = ctx.actions.declare_file("{}.wd-test".format(ctx.attr.test_name))
ctx.actions.write(
output = src,
content = WPT_WD_TEST_TEMPLATE.format(
test_name = ctx.attr.test_name,
test_config = ctx.file.test_config.basename,
test_js_generated = wd_relative_path(ctx.file.test_js_generated),
bindings = generate_external_bindings(ctx.attr.wpt_directory.files),
test_js_generated = ctx.file.test_js_generated.basename,
bindings = generate_external_bindings(src.owner, ctx.attr.wpt_directory.files),
harness = wd_relative_path(src.owner, ctx.file.harness),
compat_date = wd_relative_path(src.owner, ctx.file.compat_date),
),
)

Expand All @@ -134,14 +158,14 @@ const unitTests :Workerd.Config = (
modules = [
(name = "worker", esModule = embed "{test_js_generated}"),
(name = "{test_config}", esModule = embed "{test_config}"),
(name = "wpt:harness", esModule = embed "../../../../../workerd/src/wpt/harness.js"),
(name = "wpt:harness", esModule = embed "{harness}"),
],
bindings = [
(name = "wpt", service = "wpt"),
(name = "unsafe", unsafeEval = void),
{bindings}
],
compatibilityDate = embed "../../../../../workerd/src/workerd/io/trimmed-supported-compatibility-date.txt",
compatibilityDate = embed "{compat_date}",
compatibilityFlags = ["nodejs_compat", "experimental"],
)
),
Expand All @@ -152,15 +176,14 @@ const unitTests :Workerd.Config = (
],
);"""

def wd_relative_path(file):
def wd_relative_path(label, target):
"""
Returns a relative path which can be referenced in the .wd-test file.
This is four directories up from the bazel short_path
Generates a path that can be used in a .wd-test file to refer to another file. Paths are relative
to the .wd-test file. We determine the right path from the label that generated the .wd-test file
"""
return "../" * (label.package.count("/") + label.name.count("/") + 1) + target.short_path

return "../" * 4 + file.short_path

def generate_external_bindings(files):
def generate_external_bindings(label, files):
"""
Generates appropriate bindings for each file in the WPT module:
- JS files: text binding to allow code to be evaluated
Expand All @@ -170,7 +193,7 @@ def generate_external_bindings(files):
result = []

for file in files.to_list():
file_path = wd_relative_path(file)
file_path = wd_relative_path(label, file)
if file.extension == "js":
entry = """(name = "{}", text = embed "{}")""".format(file.basename, file_path)
elif file.extension == "json":
Expand All @@ -195,6 +218,10 @@ _wpt_wd_test_gen = rule(
"test_config": attr.label(allow_single_file = True),
# An auto-generated JS file containing the test logic.
"test_js_generated": attr.label(allow_single_file = True),
# Target specifying the location of the WPT test harness
"harness": attr.label(allow_single_file = True),
# Target specifying the location of the trimmed-supported-compatibility-date.txt file
"compat_date": attr.label(allow_single_file = True),
},
)

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/wpt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
load("//:build/wpt_test.bzl", "wpt_test")

srcs = glob(["*-test.ts"])
srcs = glob(["**/*-test.ts"])

[wpt_test(
name = file.replace("-test.ts", ""),
Expand Down
29 changes: 29 additions & 0 deletions src/workerd/api/wpt/dom/abort-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2017-2022 Cloudflare, Inc.
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
// https://opensource.org/licenses/Apache-2.0

import { type TestRunnerConfig } from 'wpt:harness';

export default {
'AbortSignal.any.js': {},
'abort-signal-any-tests.js': {},
'abort-signal-any.any.js': {
comment:
'(1, 2) Target should be set to signal. (3) Should be investigated.',
expectedFailures: [
'AbortSignal.any() follows a single signal (using AbortController)',
'AbortSignal.any() follows multiple signals (using AbortController)',
'Abort events for AbortSignal.any() signals fire in the right order (using AbortController)',
],
includeFile: 'abort-signal-any-tests.js',
},
'event.any.js': {
comment: 'Target should be set to signal',
expectedFailures: ['the abort event should have the right properties'],
},
'timeout-shadowrealm.any.js': {
comment: 'Enable when ShadowRealm is implemented',
skipAllTests: true,
},
'timeout.any.js': {},
} satisfies TestRunnerConfig;
2 changes: 1 addition & 1 deletion src/workerd/api/wpt/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { baseConfig } from '../../../../tools/base.eslint.config.mjs';
export default [
...baseConfig({ tsconfigRootDir: import.meta.dirname }),
{
files: ['src/workerd/api/wpt/*-test.js'],
files: ['src/workerd/api/wpt/**/*-test.ts'],
rules: {
'sort-keys': 'error',
},
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/wpt/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"wpt:*": ["../../../wpt/*"]
}
},
"include": ["**/*.ts", "../../../wpt/*.ts"],
"include": ["**/*.ts"],
"exclude": []
}
21 changes: 19 additions & 2 deletions src/workerd/api/wpt/url-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { type TestRunnerConfig } from 'wpt:harness';

export default {
'IdnaTestV2.window.js': {},
'a-element-origin.js': {
comment: 'Implement globalThis.document',
skipAllTests: true,
Expand All @@ -16,7 +17,6 @@ export default {
'historical.any.js': {
comment: 'Fix this eventually',
expectedFailures: [
'Constructor only takes strings',
'URL: no structured serialize/deserialize support',
'URLSearchParams: no structured serialize/deserialize support',
],
Expand All @@ -36,7 +36,8 @@ export default {
],
},
'percent-encoding.window.js': {
comment: 'Implement `async_test`',
comment:
'Implement test code modification feature to allow running this test without document',
skipAllTests: true,
},
'toascii.window.js': {
Expand All @@ -49,10 +50,17 @@ export default {
'Parsing: <http://example.com/\uD800\uD801\uDFFE\uDFFF\uFDD0\uFDCF\uFDEF\uFDF0\uFFFE\uFFFF?\uD800\uD801\uDFFE\uDFFF\uFDD0\uFDCF\uFDEF\uFDF0\uFFFE\uFFFF> without base',
],
},
'url-origin.any.js': {},
'url-searchparams.any.js': {},
'url-setters-a-area.window.js': {
comment: 'Implement globalThis.document',
skipAllTests: true,
},
'url-setters-stripping.any.js': {},
'url-setters.any.js': {},
'url-statics-canparse.any.js': {},
'url-statics-parse.any.js': {},
'url-tojson.any.js': {},
'urlencoded-parser.any.js': {
comment:
'Requests fail due to HTTP method "LADIDA", responses fail due to shift_jis encoding',
Expand Down Expand Up @@ -129,6 +137,7 @@ export default {
'response.formData() with input: b=%%2a',
],
},
'urlsearchparams-append.any.js': {},
'urlsearchparams-constructor.any.js': {
comment: 'Fix this eventually',
expectedFailures: [
Expand All @@ -138,8 +147,16 @@ export default {
'Construct with object with NULL, non-ASCII, and surrogate keys',
],
},
'urlsearchparams-delete.any.js': {},
'urlsearchparams-foreach.any.js': {},
'urlsearchparams-get.any.js': {},
'urlsearchparams-getall.any.js': {},
'urlsearchparams-has.any.js': {},
'urlsearchparams-set.any.js': {},
'urlsearchparams-size.any.js': {},
'urlsearchparams-sort.any.js': {
comment: 'Investigate url_search_params::sort in ada-url',
expectedFailures: ['Parse and sort: ffi&🌈', 'URL parse and sort: ffi&🌈'],
},
'urlsearchparams-stringifier.any.js': {},
} satisfies TestRunnerConfig;
5 changes: 5 additions & 0 deletions src/workerd/api/wpt/urlpattern-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default {
'Component: hash Left: {"hash":"a"} Right: {"hash":"b"}',
],
},
'urlpattern-compare.tentative.any.js': {},
'urlpattern-compare.tentative.https.any.js': {},
'urlpattern-hasregexpgroups-tests.js': {
comment: 'urlpattern implementation will soon be replaced with ada-url',
expectedFailures: [
Expand All @@ -45,6 +47,9 @@ export default {
'', // This file consists of one unnamed subtest
],
},
'urlpattern-hasregexpgroups.any.js': {},
'urlpattern.any.js': {},
'urlpattern.https.any.js': {},
'urlpatterntests.js': {
comment: 'urlpattern implementation will soon be replaced with ada-url',
expectedFailures: [
Expand Down
Loading

0 comments on commit a0b8d14

Please sign in to comment.