Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for stateless apps #3816

Merged
merged 17 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration_app_harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
SCREENSHOT_DIR: /tmp/screenshots
REDIS_URL: ${{ matrix.state_manager == 'redis' && 'redis:https://localhost:6379' || '' }}
run: |
poetry run playwright install --with-deps
poetry run pytest tests/integration
- uses: actions/upload-artifact@v4
name: Upload failed test screenshots
Expand Down
59 changes: 59 additions & 0 deletions tests/integration/tests_playwright/test_stateless_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Integration tests for a stateless app."""

from typing import Generator

import httpx
import pytest
from playwright.sync_api import Page, expect

import reflex as rx
from reflex.testing import AppHarness


def StatelessApp():
"""A stateless app that renders a heading."""
import reflex as rx

def index():
return rx.heading("This is a stateless app")

app = rx.App()
app.add_page(index)


@pytest.fixture(scope="module")
def stateless_app(tmp_path_factory) -> Generator[AppHarness, None, None]:
"""Create a stateless app AppHarness.

Args:
tmp_path_factory: pytest fixture for creating temporary directories.

Yields:
AppHarness: A harness for testing the stateless app.
"""
with AppHarness.create(
root=tmp_path_factory.mktemp("stateless_app"),
app_source=StatelessApp, # type: ignore
) as harness:
yield harness


def test_statelessness(stateless_app: AppHarness, page: Page):
"""Test that the stateless app renders a heading but backend/_event is not mounted.

Args:
stateless_app: A harness for testing the stateless app.
page: A Playwright page.
"""
assert stateless_app.frontend_url is not None
assert stateless_app.backend is not None
assert stateless_app.backend.started

res = httpx.get(rx.config.get_config().api_url + "/_event")
assert res.status_code == 404

res2 = httpx.get(rx.config.get_config().api_url + "/ping")
assert res2.status_code == 200

page.goto(stateless_app.frontend_url)
expect(page.get_by_role("heading")).to_have_text("This is a stateless app")
Loading