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
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.
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""The lex JS unit tests (``tests/lex/*.test.mjs``) under pytest.
|
||
|
||
The modules are ES modules in ``.js`` files with no ``package.json``
|
||
``"type": "module"`` (Gitea serves them as they are), which node runs only
|
||
from 22.7 on (syntax detection on by default). Ruling S1-P5: this test skips
|
||
when the host has no node, or an older one; 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/lex/*.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_lex_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/lex").glob("*.test.mjs")
|
||
)
|
||
assert files, "no tests/lex/*.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:]
|
||
)
|