@@ -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+
360393def generate_harness_modules (wd_test_file , files ):
361394 """
362395 Generates a module entry for each file in the harness package
0 commit comments