Skip to content

Commit 07824e3

Browse files
committed
tests(gp_sphinx_vite[ci]): pre-create node_modules in fake-vite roots
why: After 013884d added _ensure_node_modules() auto-install to the builder-inited hook, six pre-existing tests started shelling out to real `pnpm install --frozen-lockfile` because their fake vite roots never had node_modules/. CI (no pnpm on PATH) failed with FileNotFoundError across all 10 qa matrix jobs. what: - _write_fake_vite() gains with_node_modules: bool = True; default pre-creates node_modules/ so _ensure_node_modules short-circuits. - test_on_builder_inited_runs_install_when_node_modules_missing now passes with_node_modules=False to keep its install-path assertion meaningful. - Integration test test_sphinx_build_spawns_via_extension pre-creates node_modules/ in its fake-vite-root. - Auto-install behaviour itself is unchanged; the three dedicated install-path tests (skips/runs/fails) still cover it.
1 parent d2ebf1d commit 07824e3

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

tests/test_gp_sphinx_vite_hooks.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,19 @@ class _FakeApp:
4040
config: _FakeConfig = dataclasses.field(default_factory=_FakeConfig)
4141

4242

43-
def _write_fake_vite(tmp_path: pathlib.Path, *, body: str) -> pathlib.Path:
44-
"""Write a fake-vite script + a stub package.json at ``tmp_path``."""
43+
def _write_fake_vite(
44+
tmp_path: pathlib.Path, *, body: str, with_node_modules: bool = True
45+
) -> pathlib.Path:
46+
"""Write a fake-vite script + a stub package.json at ``tmp_path``.
47+
48+
Creates ``node_modules/`` by default so :func:`hooks._ensure_node_modules`
49+
short-circuits the auto-install path. Tests that exercise the install
50+
path explicitly pass ``with_node_modules=False`` and arrange their own
51+
``pnpm_install_command`` patch.
52+
"""
4553
(tmp_path / "package.json").write_text('{"name": "fake-vite-root"}\n')
54+
if with_node_modules:
55+
(tmp_path / "node_modules").mkdir(exist_ok=True)
4656
script = tmp_path / "fake_vite.py"
4757
script.write_text(textwrap.dedent(body))
4858
return script
@@ -339,6 +349,7 @@ def test_on_builder_inited_runs_install_when_node_modules_missing(
339349
)
340350
vite_script = _write_fake_vite(
341351
tmp_path,
352+
with_node_modules=False,
342353
body="""\
343354
import time
344355
print("vite watching", flush=True)

tests/test_gp_sphinx_vite_integration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def test_sphinx_build_spawns_via_extension(tmp_path: pathlib.Path) -> None:
7777
fake_vite_dir = tmp_path / "fake-vite-root"
7878
fake_vite_dir.mkdir()
7979
(fake_vite_dir / "package.json").write_text('{"name": "fake-vite-integration"}\n')
80+
# Pre-create node_modules/ so _ensure_node_modules short-circuits the
81+
# auto-install path (CI runners don't have pnpm on PATH).
82+
(fake_vite_dir / "node_modules").mkdir()
8083
fake_script = fake_vite_dir / "fake_vite.py"
8184
fake_script.write_text(
8285
textwrap.dedent(

0 commit comments

Comments
 (0)