Skip to content

Commit 6fe4b85

Browse files
committed
Support web-platform-tests heuristics for test selection
Fixes #5481
1 parent a7b0ec8 commit 6fe4b85

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

bugbug/test_scheduling.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,4 +1003,32 @@ def collect_support_files(value):
10031003
if f.is_file()
10041004
)
10051005

1006+
# If a web-platform test or meta is modified, run the relevant web-platform folder.
1007+
if not any(path.endswith(ignore) for ignore in ("/META.yml", "/README.md")):
1008+
for base in ("testing/web-platform/mozilla", "testing/web-platform"):
1009+
if path.startswith(f"{base}/meta/") or path.startswith(
1010+
f"{base}/tests/"
1011+
):
1012+
sub = "meta" if "/meta/" in path else "tests"
1013+
1014+
relative = Path(path).relative_to(f"{base}/{sub}")
1015+
1016+
test_root = repo_dir / base / "tests"
1017+
cur_dir = test_root / relative.parent
1018+
1019+
def has_html_files(d: Path) -> bool:
1020+
return any(p.suffix.lower() == ".html" for p in d.iterdir())
1021+
1022+
while cur_dir != test_root and not has_html_files(cur_dir):
1023+
cur_dir = cur_dir.parent
1024+
1025+
# Ignore files in top level "meta" or "tests".
1026+
if len(cur_dir.parts) == 1:
1027+
break
1028+
1029+
if has_html_files(cur_dir):
1030+
manifests.add(str(cur_dir.relative_to(repo_dir)))
1031+
1032+
break
1033+
10061034
return manifests

tests/test_test_scheduling.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,3 +1114,78 @@ def test_find_manifests_for_paths(tmp_path) -> None:
11141114
assert test_scheduling.find_manifests_for_paths(
11151115
str(tmp_path), ["absolute_path_with_subdirglob/subdir/asd.js"]
11161116
) == {"test/chrome.toml"}
1117+
1118+
(tmp_path / "testing/web-platform/tests/html/semantics").mkdir(parents=True)
1119+
(tmp_path / "testing/web-platform/tests/.gitignore").touch()
1120+
(
1121+
tmp_path
1122+
/ "testing/web-platform/tests/html/semantics/rellist-feature-detection.html"
1123+
).touch()
1124+
(tmp_path / "testing/web-platform/tests/html/semantics/META.yml").touch()
1125+
(tmp_path / "testing/web-platform/tests/html/semantics/interactive-elements").mkdir(
1126+
parents=True
1127+
)
1128+
(
1129+
tmp_path
1130+
/ "testing/web-platform/tests/html/semantics/interactive-elements"
1131+
/ "contextmenu-historical.html"
1132+
).touch()
1133+
(tmp_path / "testing/web-platform/mozilla/meta/pointerevents").mkdir(parents=True)
1134+
(
1135+
tmp_path
1136+
/ "testing/web-platform/mozilla/meta/pointerevents/pointerevent_click_during_parent_capture.html.ini"
1137+
).touch()
1138+
(tmp_path / "testing/web-platform/mozilla/tests/pointerevents").mkdir(parents=True)
1139+
(
1140+
tmp_path
1141+
/ "testing/web-platform/mozilla/tests/pointerevents/pointerevent_click_during_parent_capture.html"
1142+
).touch()
1143+
(tmp_path / "testing/web-platform/tests/encrypted-media/content").mkdir(
1144+
parents=True
1145+
)
1146+
(
1147+
tmp_path
1148+
/ "testing/web-platform/tests/encrypted-media/clearkey-events.https.html"
1149+
).touch()
1150+
(
1151+
tmp_path
1152+
/ "testing/web-platform/tests/encrypted-media/content/content-metadata.js"
1153+
).touch()
1154+
1155+
assert (
1156+
test_scheduling.find_manifests_for_paths(
1157+
str(tmp_path), ["testing/web-platform/tests/.gitignore"]
1158+
)
1159+
== set()
1160+
)
1161+
1162+
assert test_scheduling.find_manifests_for_paths(
1163+
str(tmp_path),
1164+
["testing/web-platform/tests/html/semantics/rellist-feature-detection.html"],
1165+
) == {"testing/web-platform/tests/html/semantics"}
1166+
1167+
assert (
1168+
test_scheduling.find_manifests_for_paths(
1169+
str(tmp_path), ["testing/web-platform/tests/html/semantics/META.yml"]
1170+
)
1171+
== set()
1172+
)
1173+
1174+
assert test_scheduling.find_manifests_for_paths(
1175+
str(tmp_path),
1176+
[
1177+
"testing/web-platform/tests/html/semantics/interactive-elements/contextmenu-historical.html"
1178+
],
1179+
) == {"testing/web-platform/tests/html/semantics/interactive-elements"}
1180+
1181+
assert test_scheduling.find_manifests_for_paths(
1182+
str(tmp_path),
1183+
[
1184+
"testing/web-platform/mozilla/meta/pointerevents/pointerevent_click_during_parent_capture.html.ini"
1185+
],
1186+
) == {"testing/web-platform/mozilla/tests/pointerevents"}
1187+
1188+
assert test_scheduling.find_manifests_for_paths(
1189+
str(tmp_path),
1190+
["testing/web-platform/tests/encrypted-media/content/content-metadata.js"],
1191+
) == {"testing/web-platform/tests/encrypted-media"}

0 commit comments

Comments
 (0)