fix(wpt): discover htm testharness documents

This commit is contained in:
ldm0
2026-09-14 06:50:58 +08:00
committed by Donough Liu
parent c0a87c6960
commit 1a12ee01ec
2 changed files with 50 additions and 9 deletions
@@ -7,11 +7,11 @@ URLs, ``==`` / ``!=`` references, timeout metadata, and fuzzy bounds.
A testharness case is selectable if:
* The file does not live under one of the default excluded directory prefixes.
* It is a navigable ``.html`` file, a selected ``.any.js`` global, or a
* It is a navigable ``.html`` / ``.htm`` file, a selected ``.any.js`` global, or a
``.window.js`` / ``.worker.js`` script case that can be wrapped as a
testharness page.
* Its filename does not contain ``.tentative`` or ``.optional``.
* Its filename does not end in ``-manual.html``.
* Its filename does not end in ``-manual.html`` or ``-manual.htm``.
* It is not under a ``resources`` support directory.
* HTML cases reference ``/resources/testharness.js``.
* The file body does NOT reference ``/resources/testdriver`` (testdriver
@@ -49,6 +49,7 @@ import re
from dataclasses import dataclass
from html import unescape
from html.parser import HTMLParser
from itertools import chain
from pathlib import Path
from typing import Any, Iterator
from urllib.parse import urljoin, urlsplit
@@ -853,7 +854,7 @@ def enumerate_cases(
base = wpt_root / prefix
if not base.exists():
continue
for path in base.rglob("*.html"):
for path in chain(base.rglob("*.html"), base.rglob("*.htm")):
if not path.is_file():
continue
rel = path.relative_to(wpt_root).as_posix()
@@ -1133,7 +1134,7 @@ def _is_default_goal_container_query_case(rel: str) -> bool:
def _is_manual_or_support_case(rel: str) -> bool:
parts = rel.split("/")
return parts[-1].endswith("-manual.html") or any(
return parts[-1].endswith(("-manual.html", "-manual.htm")) or any(
part in {"resources", "support"} for part in parts[:-1]
)
+45 -5
View File
@@ -2421,6 +2421,36 @@ class WptCrossTests(unittest.TestCase):
self.assertFalse(audit["ok"])
self.assertEqual(audit["counts"]["resolved_known_failures"], 1)
def test_enumerate_cases_includes_htm_before_applying_limit(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
wpt_root = Path(temp_dir)
case_dir = wpt_root / "dom"
case_dir.mkdir()
harness = '<script src="/resources/testharness.js"></script>'
(case_dir / "a.htm").write_text(
'<meta name="timeout" content="long">'
'<meta name="variant" content="?mode=z">'
'<meta name="variant" content="?mode=a">'
+ harness,
encoding="utf-8",
)
(case_dir / "z.html").write_text(harness, encoding="utf-8")
expected = [
WptCase("dom/a.htm?mode=a", LONG_TIMEOUT_MULTIPLIER),
WptCase("dom/a.htm?mode=z", LONG_TIMEOUT_MULTIPLIER),
WptCase("dom/z.html"),
]
for prefixes in (None, ("dom",)):
with self.subTest(dir_prefixes=prefixes):
self.assertEqual(
enumerate_cases(wpt_root, dir_prefixes=prefixes), expected
)
self.assertEqual(
enumerate_cases(wpt_root, dir_prefixes=prefixes, limit=1),
expected[:1],
)
def test_enumerate_cases_expands_wpt_meta_variants(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
wpt_root = Path(temp_dir)
@@ -2732,14 +2762,24 @@ class WptCrossTests(unittest.TestCase):
<script src="/resources/testharness.js"></script>
<script>test(() => {}, "ok");</script>
"""
(case_dir / "kept.html").write_text(case_html, encoding="utf-8")
(case_dir / "upload-manual.html").write_text(case_html, encoding="utf-8")
(resource_dir / "helper.html").write_text(case_html, encoding="utf-8")
(support_dir / "helper.html").write_text(case_html, encoding="utf-8")
for suffix in (".html", ".htm"):
(case_dir / f"kept{suffix}").write_text(case_html, encoding="utf-8")
(case_dir / f"upload-manual{suffix}").write_text(
case_html, encoding="utf-8"
)
(resource_dir / f"helper{suffix}").write_text(
case_html, encoding="utf-8"
)
(support_dir / f"helper{suffix}").write_text(
case_html, encoding="utf-8"
)
cases = enumerate_cases(wpt_root)
self.assertEqual([case.case_path for case in cases], ["FileAPI/kept.html"])
self.assertEqual(
[case.case_path for case in cases],
["FileAPI/kept.htm", "FileAPI/kept.html"],
)
def test_explicit_dir_prefix_bypasses_default_rendering_blacklist(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir: