"""Run Node contract tests for frontend helpers (``*.test.mjs``).""" from __future__ import annotations import shutil import subprocess import sys from pathlib import Path import pytest REPO_ROOT = Path(__file__).resolve().parent.parent @pytest.mark.skipif(shutil.which("node") is None, reason="Node.js not installed") def test_frontend_contracts_via_node() -> None: tests = sorted((REPO_ROOT / "frontend").glob("*.test.mjs")) for t in tests: assert t.is_file(), t proc = subprocess.run( [shutil.which("node") or "node", "--test", *[str(t) for t in tests]], cwd=str(REPO_ROOT), capture_output=True, text=True, timeout=60, ) if proc.returncode != 0: sys.stderr.write(proc.stdout or "") sys.stderr.write(proc.stderr or "") assert proc.returncode == 0, "node --test frontend/*.test.mjs failed"