Files
stack/tests/focus/test_js.py
kert c89fabf99e
Some checks failed
CI / lint (push) Successful in 1m6s
CI / notebooks-smoke (push) Successful in 2m6s
Deploy / changes (push) Successful in 16s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Deploy / api (push) Has been skipped
Deploy / bcda (push) Has been skipped
Deploy / llm (push) Has been skipped
Deploy / mc (push) Has been skipped
Deploy / report (push) Successful in 17s
CI / test (push) Failing after 4m38s
fix(test): accept node 24's reporter and colored Typer errors
Node 24's default spec reporter prints "fail 0" without the tap marker,
and Rich highlights --option inside an error so the phrase is split by
ANSI when the runner emits color.
2026-11-16 14:01:23 -05:00

69 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""The focus JS unit tests (``tests/focus/*.test.mjs``) under pytest.
The anchor module is an ES module. Node runs that from 22.7 on. This
test skips when the host has no such node; the gate is the docker run
docker run --rm -v /home/kert/stack:/w:ro -w /w node:22-slim \\
sh -c 'node --test tests/focus/*.test.mjs'
which must print ``# fail 0``. The tap reporter is forced: node 24's
default spec reporter prints ``ℹ fail 0`` instead.
"""
from __future__ import annotations
import re
import shutil
import subprocess
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[2]
MIN_NODE = (22, 7)
SKIP_REASON = "node ≥ 22.7 not on PATH; run NODE"
def node_version(text: str) -> tuple[int, int] | None:
"""``(major, minor)`` from ``node --version`` output such as ``v22.7.0``."""
m = re.match(r"\s*v(\d+)\.(\d+)", text or "")
return (int(m.group(1)), int(m.group(2))) if m else None
def node_ok(text: str) -> bool:
v = node_version(text)
return v is not None and v >= MIN_NODE
def test_node_gate() -> None:
assert node_version("v22.7.0\n") == (22, 7)
assert node_ok("v22.7.0") and node_ok("v24.1.3") and node_ok("v23.0.0")
assert not node_ok("v22.6.9") and not node_ok("v20.18.0")
assert not node_ok("") and not node_ok("node: not found")
def test_focus_js_unit_tests() -> None:
node = shutil.which("node")
if node is None:
pytest.skip(SKIP_REASON)
probe = subprocess.run(
[node, "--version"], capture_output=True, text=True, check=False
)
if not node_ok(probe.stdout):
pytest.skip(SKIP_REASON)
files = sorted(
str(p.relative_to(ROOT)) for p in (ROOT / "tests/focus").glob("*.test.mjs")
)
assert files, "no tests/focus/*.test.mjs"
r = subprocess.run(
[node, "--test", "--test-reporter=tap", *files],
cwd=ROOT,
capture_output=True,
text=True,
timeout=300,
check=False,
)
assert r.returncode == 0 and "# fail 0" in r.stdout, (
r.stdout[-6000:] + r.stderr[-2000:]
)