Skip to content

Commit 063619a

Browse files
test: add required Bun-only and outdated Node integration coverage (#7899)
* test: add required Bun-only and outdated Node integration coverage * Revert line * Fix checking partial output * Add the same monkeypatch.delenv to nodeless_app * test: check Reflex's runtime choice and cover the prod build for bun - One fixture runs each test with no node and with an outdated node. It pins get_node_version to the scenario, because the per-process cache can hold a value probed under another PATH (telemetry fills it first). - The fixture asserts Reflex's own executor: plain bun with no node, and `bun --bun` over an outdated node, so the two cases are told apart. - Add a prod test: the production build must run and serve the page. - The dev test checks the compiled route module holds the app's text. - One `_require` helper skips, or fails in the dedicated job. - The job reads the Bun version from constants.Bun.VERSION and sets REFLEX_USE_SYSTEM_BUN, so Reflex runs the provisioned bun. * ci: fail the Bun version step when reading the version fails Inside echo, a failed command substitution does not stop bash -e, so an empty version reached setup-bun, which then installs the latest Bun. --------- Co-authored-by: Farhan <www.mfarvirus@gmail.com> Co-authored-by: Farhan Ali Raza <62690310+FarhanAliRaza@users.noreply.github.com>
1 parent 1609525 commit 063619a

2 files changed

Lines changed: 175 additions & 50 deletions

File tree

‎.github/workflows/integration_tests.yml‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ jobs:
311311
- name: Run non-browser integration tests
312312
env:
313313
REFLEX_REDIS_URL: ${{ matrix.state_manager == 'redis' && 'redis://localhost:6379' || '' }}
314-
run: uv run pytest tests/integration --ignore=tests/integration/tests_playwright --reruns 3 -v --maxfail=5
314+
run: uv run pytest tests/integration --ignore=tests/integration/tests_playwright --reruns 3 -rs -v --maxfail=5
315315

316316
app-harness-playwright:
317317
needs: changes
@@ -349,7 +349,56 @@ jobs:
349349
- name: Run Playwright integration tests
350350
env:
351351
REFLEX_REDIS_URL: ${{ matrix.state_manager == 'redis' && 'redis://localhost:6379' || '' }}
352-
run: uv run pytest tests/integration/tests_playwright --reruns 3 -v --maxfail=5 --splits 2 --group ${{ matrix.split_index }}
352+
run: uv run pytest tests/integration/tests_playwright --reruns 3 -rs -v --maxfail=5 --splits 2 --group ${{ matrix.split_index }}
353+
354+
bun-only-startup:
355+
needs: changes
356+
if: needs.changes.outputs.run == 'true'
357+
timeout-minutes: 20
358+
strategy:
359+
fail-fast: false
360+
matrix:
361+
os: [ubuntu-latest, macos-latest, windows-latest]
362+
python-version: ["3.11"]
363+
runs-on: ${{ matrix.os }}
364+
env:
365+
# Run the bun installed below, not a copy Reflex downloads itself.
366+
REFLEX_USE_SYSTEM_BUN: "1"
367+
steps:
368+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
369+
with:
370+
fetch-tags: true
371+
fetch-depth: 0
372+
persist-credentials: false
373+
- uses: ./.github/actions/setup_build_env
374+
with:
375+
python-version: ${{ matrix.python-version }}
376+
run-uv-sync: true
377+
- name: Read the Bun version Reflex pins
378+
id: bun
379+
run: |
380+
version=$(uv run python -c 'from reflex_base.constants import Bun; print(Bun.VERSION)')
381+
echo "version=$version" >> "$GITHUB_OUTPUT"
382+
- name: Install Bun
383+
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
384+
with:
385+
bun-version: ${{ steps.bun.outputs.version }}
386+
- name: Install outdated Node
387+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
388+
with:
389+
node-version: 20
390+
- name: Report runtime versions
391+
run: |
392+
uv run python --version
393+
echo "bun $(bun --version) at $(command -v bun)"
394+
echo "node $(node --version) at $(command -v node)"
395+
uname -a
396+
- name: Run Nodeless and Outdated-Node Integration Tests
397+
env:
398+
REQUIRE_BUN_NODELESS_TEST: "true"
399+
run: |
400+
uv run pytest tests/integration/test_nodeless_frontend.py -rs -v --junitxml=test-results.xml
401+
uv run python -c "import xml.etree.ElementTree as ET; root = ET.parse('test-results.xml').getroot(); skipped = root.findall('.//testcase/skipped'); assert not skipped, f'{len(skipped)} test(s) were skipped'"
353402
354403
# The one status check the branch rules require from this workflow. Naming the
355404
# jobs above directly does not survive: check names follow the matrix and the
@@ -364,6 +413,7 @@ jobs:
364413
reflex-docs-macos,
365414
app-harness,
366415
app-harness-playwright,
416+
bun-only-startup,
367417
]
368418
if: always()
369419
runs-on: ubuntu-latest
Lines changed: 123 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
"""Test that the frontend dev server starts on an install without Node."""
1+
"""Test that the frontend starts on installs where bun, not node, is the runtime."""
22

3+
import contextlib
34
import os
45
import shutil
5-
from collections.abc import Generator
6+
from collections.abc import Iterator
7+
from pathlib import Path
8+
from typing import NoReturn
9+
from urllib.parse import urljoin
610

711
import httpx
812
import pytest
13+
from packaging import version
14+
from reflex_base import constants
915

1016
import reflex.testing as reflex_testing
11-
from reflex.testing import AppHarness
17+
from reflex.testing import AppHarness, AppHarnessProd
1218
from reflex.utils import js_runtimes, path_ops
1319
from reflex.utils.exec import _DEV_CONDITION_FLAG
1420

21+
_APP_TEXT = "nodeless frontend is up"
22+
1523

1624
def NodelessApp():
17-
"""App whose only requirement is that the dev server serves its page."""
25+
"""App whose only requirement is that the frontend serves its page."""
1826
import reflex as rx
1927

2028
def index():
@@ -37,47 +45,87 @@ def _path_without_node() -> str:
3745
)
3846

3947

40-
@pytest.fixture(scope="module")
41-
def nodeless_app(tmp_path_factory) -> Generator[AppHarness, None, None]:
42-
"""Start NodelessApp with `node` unavailable, as on a bun-only install.
48+
def _require(reason: str) -> NoReturn:
49+
"""Skip a scenario whose runtime is missing, or fail the job that requires it.
4350
4451
Args:
45-
tmp_path_factory: pytest tmp_path_factory fixture.
52+
reason: Why the scenario cannot run.
53+
"""
54+
if os.environ.get("REQUIRE_BUN_NODELESS_TEST") == "true":
55+
pytest.fail(reason)
56+
pytest.skip(reason)
4657

47-
Yields:
48-
The running AppHarness.
58+
59+
@pytest.fixture(params=["nodeless", "outdated_node"])
60+
def bun_runtime(
61+
request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch
62+
) -> Path:
63+
"""Set up an environment where bun is the frontend runtime.
64+
65+
`nodeless` drops node from PATH, as on a bun-only install. `outdated_node`
66+
keeps an unsupported node on PATH, which bun has to take over from.
67+
68+
Args:
69+
request: The pytest request carrying the scenario name.
70+
monkeypatch: The pytest monkeypatch fixture.
71+
72+
Returns:
73+
The bun executable Reflex runs the frontend with.
4974
"""
50-
with pytest.MonkeyPatch.context() as monkeypatch:
75+
monkeypatch.delenv("REFLEX_USE_NPM", raising=False)
76+
node_version = None
77+
if request.param == "nodeless":
5178
monkeypatch.setenv("PATH", _path_without_node())
5279
if shutil.which("node") is not None:
53-
pytest.skip("node is still resolvable after filtering it off PATH")
54-
if path_ops.get_bun_path() is None:
55-
pytest.skip("bun is unavailable once node is off PATH")
56-
# The node probe is cached per process, so an earlier test may have
57-
# found node; it is off PATH now.
58-
monkeypatch.setattr(js_runtimes, "get_node_version", lambda: None)
59-
# Drop the `development` condition Reflex puts in the dev server's
60-
# environment. Bun applies neither NODE_OPTIONS nor BUN_OPTIONS to the
61-
# process it spawns for a package script, so node-less installs never
62-
# had that assist -- the condition has to reach bun as a flag on the
63-
# dev server command.
64-
monkeypatch.setattr(reflex_testing, "_with_development_condition", dict)
65-
harness = AppHarness.create(
66-
root=tmp_path_factory.mktemp("nodeless_app"), app_source=NodelessApp
67-
)
68-
# Started outside the `with` form on purpose: `__enter__` *is* `start()`,
69-
# so a failure to bring the frontend up skips `__exit__` and leaks the
70-
# backend thread, which then keeps the interpreter alive. This test
71-
# fails precisely that way, so it has to stop the harness itself.
72-
try:
73-
harness.start()
74-
yield harness
75-
finally:
76-
harness.stop()
80+
_require("node is still resolvable after filtering it off PATH")
81+
else:
82+
node_version = js_runtimes._get_version_of_executable(path_ops.get_node_path())
83+
if node_version is None:
84+
_require("node is not installed")
85+
if node_version >= version.parse(constants.Node.MIN_VERSION):
86+
_require(f"node {node_version} is supported, not outdated")
87+
bun_path = path_ops.get_bun_path()
88+
if bun_path is None:
89+
_require("bun is not installed")
90+
# The node probe is cached once per process, possibly under another PATH.
91+
monkeypatch.setattr(js_runtimes, "get_node_version", lambda: node_version)
92+
# Reflex picks bun, and forces it over an outdated node with `--bun`.
93+
assert js_runtimes.get_js_package_executor()[0] == [
94+
str(bun_path),
95+
*(["--bun"] if node_version else []),
96+
]
97+
return bun_path
98+
99+
100+
@contextlib.contextmanager
101+
def _started(harness_cls: type[AppHarness], root: Path) -> Iterator[AppHarness]:
102+
"""Run NodelessApp in a harness that is stopped even when it fails to start.
103+
104+
`__enter__` *is* `start()`, so a failure to bring the frontend up skips
105+
`__exit__` and leaks the backend thread, which then keeps the interpreter
106+
alive.
77107
108+
Args:
109+
harness_cls: The harness class that runs the app.
110+
root: The directory to create the app in.
111+
112+
Yields:
113+
The running harness.
114+
"""
115+
harness = harness_cls.create(root=root, app_source=NodelessApp)
116+
try:
117+
harness.start()
118+
yield harness
119+
finally:
120+
harness.stop()
78121

79-
def test_nodeless_frontend_serves(nodeless_app: AppHarness):
80-
"""The dev server starts and serves a page with no Node installed.
122+
123+
def test_dev_frontend_serves(
124+
bun_runtime: Path,
125+
monkeypatch: pytest.MonkeyPatch,
126+
tmp_path_factory: pytest.TempPathFactory,
127+
):
128+
"""The dev server starts and compiles the page with bun as the runtime.
81129
82130
`react-router dev` needs the `development` export condition and relaunches
83131
itself to enable it. Bun runs the CLI here and ignores the condition in the
@@ -87,15 +135,42 @@ def test_nodeless_frontend_serves(nodeless_app: AppHarness):
87135
flag up front.
88136
89137
Args:
90-
nodeless_app: The harness running without node on PATH.
138+
bun_runtime: The bun executable the scenario runs the frontend with.
139+
monkeypatch: The pytest monkeypatch fixture.
140+
tmp_path_factory: The pytest temporary path factory.
141+
"""
142+
# Drop the `development` condition Reflex puts in the dev server's
143+
# environment. Bun applies neither NODE_OPTIONS nor BUN_OPTIONS to the
144+
# process it spawns for a package script, so the condition has to reach
145+
# bun as a flag on the dev server command.
146+
monkeypatch.setattr(reflex_testing, "_with_development_condition", dict)
147+
with _started(AppHarness, tmp_path_factory.mktemp("nodeless_app")) as harness:
148+
assert harness.frontend_process is not None
149+
args = harness.frontend_process.args
150+
assert isinstance(args, list)
151+
assert args[:2] == [str(bun_runtime), _DEV_CONDITION_FLAG]
152+
assert harness.frontend_url is not None
153+
document = httpx.get(harness.frontend_url, timeout=60)
154+
assert document.status_code == 200
155+
assert "window.__reactRouterContext" in document.text
156+
# The page renders client-side, so check the route module the dev
157+
# server compiles for it.
158+
route = httpx.get(
159+
urljoin(harness.frontend_url, "/app/routes/_index.jsx"), timeout=60
160+
)
161+
assert route.status_code == 200
162+
assert _APP_TEXT in route.text
163+
164+
165+
@pytest.mark.usefixtures("bun_runtime")
166+
def test_prod_frontend_serves(tmp_path_factory: pytest.TempPathFactory):
167+
"""The production build runs and serves the page with bun as the runtime.
168+
169+
Args:
170+
tmp_path_factory: The pytest temporary path factory.
91171
"""
92-
assert nodeless_app.frontend_process is not None
93-
args = nodeless_app.frontend_process.args
94-
assert isinstance(args, list)
95-
assert _DEV_CONDITION_FLAG in args
96-
assert nodeless_app.frontend_url is not None
97-
response = httpx.get(nodeless_app.frontend_url, timeout=60)
98-
assert response.status_code == 200
99-
# The page is hydrated client-side, so assert on the react-router document
100-
# the dev server rendered rather than on the app's own text.
101-
assert "__reactRouterContext" in response.text
172+
with _started(AppHarnessProd, tmp_path_factory.mktemp("nodeless_app")) as harness:
173+
assert harness.frontend_url is not None
174+
response = httpx.get(harness.frontend_url, timeout=60)
175+
assert response.status_code == 200
176+
assert _APP_TEXT in response.text

0 commit comments

Comments
 (0)