54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Enforce frontend test framework policy: Jest + Playwright only."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
import json
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
BANNED_FRAMEWORKS = {"vitest", "cypress", "mocha", "ava", "karma", "qunit"}
|
||
|
|
ALLOWED_TEST_FRAMEWORKS = {"jest", "@playwright/test", "playwright"}
|
||
|
|
|
||
|
|
|
||
|
|
def parse_args() -> argparse.Namespace:
|
||
|
|
parser = argparse.ArgumentParser()
|
||
|
|
parser.add_argument("--root", default=".")
|
||
|
|
return parser.parse_args()
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> int:
|
||
|
|
args = parse_args()
|
||
|
|
root = Path(args.root).resolve()
|
||
|
|
package_json = root / "web" / "package.json"
|
||
|
|
if not package_json.exists():
|
||
|
|
print("UI framework check: skipped (web/package.json not found)")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
payload = json.loads(package_json.read_text(encoding="utf-8"))
|
||
|
|
deps = payload.get("dependencies", {}) or {}
|
||
|
|
dev_deps = payload.get("devDependencies", {}) or {}
|
||
|
|
scripts = payload.get("scripts", {}) or {}
|
||
|
|
all_pkgs = set(deps.keys()) | set(dev_deps.keys())
|
||
|
|
|
||
|
|
banned = sorted(BANNED_FRAMEWORKS.intersection(all_pkgs))
|
||
|
|
if banned:
|
||
|
|
print("UI framework check failed: banned test framework(s) detected:")
|
||
|
|
for pkg in banned:
|
||
|
|
print(f" {pkg}")
|
||
|
|
return 1
|
||
|
|
|
||
|
|
has_test_script = any(name.startswith("test") for name in scripts.keys())
|
||
|
|
has_allowed_framework = bool(ALLOWED_TEST_FRAMEWORKS.intersection(all_pkgs))
|
||
|
|
if has_test_script and not has_allowed_framework:
|
||
|
|
print("UI framework check failed: test scripts exist but Jest/Playwright dependency is missing")
|
||
|
|
return 1
|
||
|
|
|
||
|
|
print("UI framework checks: ok")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
sys.exit(main())
|