Skip to content

Commit 28f0816

Browse files
authored
Merge pull request #5792 from cloudflare/yagiz/include-wpt-common
include common folder for web-platform tests
2 parents 6045d2a + 6add1ab commit 28f0816

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

build/wpt_test.bzl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], a
3838
wpt_tsproject = "//src/wpt:wpt-all@tsproject"
3939
harness = "//src/wpt:harness@js"
4040
wpt_cacert = "@wpt//:tools/certs/cacert.pem"
41+
wpt_common = "@wpt//:common@module"
4142

4243
if compat_date == "":
4344
compat_date = "2999-12-31"
@@ -60,6 +61,7 @@ def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], a
6061
harness = harness,
6162
autogates = autogates,
6263
wpt_cacert = wpt_cacert,
64+
wpt_common = wpt_common,
6365
compat_flags = compat_flags + ["experimental", "nodejs_compat", "unsupported_process_actual_platform"],
6466
)
6567

@@ -69,6 +71,7 @@ def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], a
6971
wpt_directory, # e.g. wpt/url/**",
7072
harness, # e.g. wpt/harness/*.ts
7173
wpt_cacert, # i.e. "wpt/tools/certs/cacert.pem",
74+
wpt_common, # i.e. "wpt/common/**"
7275
]
7376

7477
wd_test(
@@ -228,13 +231,18 @@ def _wpt_wd_test_gen_impl(ctx):
228231
src = ctx.actions.declare_file("{}.wd-test".format(ctx.attr.test_name))
229232
base = ctx.attr.wpt_directory[WPTModuleInfo].base
230233

234+
# Generate bindings for test directory files plus common/**/*.js
235+
bindings = generate_external_bindings(src, base, ctx.attr.wpt_directory.files)
236+
common_base = ctx.attr.wpt_common[WPTModuleInfo].base
237+
common_bindings = generate_common_bindings(src, common_base, ctx.attr.wpt_common.files)
238+
all_bindings = bindings + ",\n" + common_bindings if bindings and common_bindings else (bindings or common_bindings)
231239
ctx.actions.write(
232240
output = src,
233241
content = WPT_WD_TEST_TEMPLATE.format(
234242
test_name = ctx.attr.test_name,
235243
test_config = ctx.file.test_config.basename,
236244
test_js_generated = ctx.file.test_js_generated.basename,
237-
bindings = generate_external_bindings(src, base, ctx.attr.wpt_directory.files),
245+
bindings = all_bindings,
238246
harness_modules = generate_harness_modules(src, ctx.attr.harness.files),
239247
wpt_cacert = wd_test_relative_path(src, ctx.file.wpt_cacert),
240248
autogates = generate_autogates_field(ctx.attr.autogates),
@@ -261,6 +269,8 @@ _wpt_wd_test_gen = rule(
261269
"harness": attr.label(),
262270
# Target specifying the location of the WPT CA certificate
263271
"wpt_cacert": attr.label(allow_single_file = True),
272+
# Target specifying the WPT common directory module
273+
"wpt_common": attr.label(),
264274
# A list of autogates to specify in the generated wd-test file
265275
"autogates": attr.string_list(),
266276
# A list of compatibility flags to specify in the generated wd-test file
@@ -357,6 +367,29 @@ def generate_external_bindings(wd_test_file, base, files):
357367

358368
return ",\n".join(result)
359369

370+
def generate_common_bindings(wd_test_file, base, files):
371+
"""
372+
Generates appropriate bindings for each file in the WPT common module.
373+
Files are prefixed with /common/ path.
374+
375+
Only JS files are included as some JSON files in common/ contain
376+
non-standard JSON (e.g., with comments) that would cause parsing errors.
377+
"""
378+
379+
result = []
380+
381+
for file in files.to_list():
382+
if file.extension == "js":
383+
binding_type = "text"
384+
else:
385+
# Skip non-JS files to avoid issues with non-standard JSON
386+
continue
387+
388+
relative_path = module_relative_path(base, file)
389+
result.append('(name = "/common/{}", {} = embed "{}")'.format(relative_path, binding_type, wd_test_relative_path(wd_test_file, file)))
390+
391+
return ",\n".join(result)
392+
360393
def generate_harness_modules(wd_test_file, files):
361394
"""
362395
Generates a module entry for each file in the harness package

src/wpt/harness/harness.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ const EXCLUDED_PATHS = new Set([
295295
'/resources/utils.js',
296296
'/common/utils.js',
297297
'/common/get-host-info.sub.js',
298-
'/common/gc.js',
299298
'/common/sab.js',
300299
]);
301300

src/wpt/harness/utils.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ declare global {
5858
function token(): string;
5959
function setup(func: UnknownFunc | Record<string, unknown>): void;
6060
function add_completion_callback(func: UnknownFunc): void;
61-
function garbageCollect(): void;
61+
// Provided by /common/gc.js
62+
function garbageCollect(): Promise<void>;
6263
function format_value(val: unknown): string;
6364
function createBuffer(
6465
type: 'ArrayBuffer' | 'SharedArrayBuffer',
@@ -139,12 +140,6 @@ globalThis.add_completion_callback = (func: UnknownFunc): void => {
139140
globalThis.state.completionCallbacks.push(func);
140141
};
141142

142-
globalThis.garbageCollect = (): void => {
143-
if (typeof gc === 'function') {
144-
gc();
145-
}
146-
};
147-
148143
globalThis.format_value = (val): string => {
149144
return JSON.stringify(val, null, 2);
150145
};

0 commit comments

Comments
 (0)