Add integration tests for frontend path#5712
Add integration tests for frontend path#5712tartansandal wants to merge 6 commits intoreflex-dev:mainfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR introduces integration testing for frontend path functionality, specifically addressing issue #5674 where on_load and on_mount handlers fail to redirect properly when Reflex applications are served from non-root frontend paths (e.g., '/prefix').
The changes include two main components:
-
Environment Variable Addition: A new
REFLEX_FRONTEND_PATHenvironment variable is added to theEnvironmentVariablesclass inreflex/environment.py. This string variable defaults to an empty string and provides the configuration mechanism for specifying the base path under which the frontend is served. -
Comprehensive Integration Test: A new test file
tests/integration/tests_playwright/test_frontend_path.pycreates a complete end-to-end test using Playwright. The test creates a Reflex app with redirect pages and validates that redirects work correctly both in normal conditions and when served from a non-root frontend path.
The integration test uses two fixtures - one for production mode and another that sets the REFLEX_FRONTEND_PATH to '/prefix'. It employs parametrized testing to verify both scenarios, with the prefix case marked as xfail since it demonstrates the known bug that should be resolved by the related PR #5698.
This change fits into the broader Reflex ecosystem by enabling proper deployment behind reverse proxies, a common pattern where multiple applications are served from different paths on the same domain. The environment variable provides a clean configuration interface that other parts of the codebase can reference to adjust their behavior for non-root deployments.
Confidence score: 4/5
- This PR introduces well-structured integration testing with minimal risk to existing functionality
- Score reflects solid test design and environment variable implementation, though the xfail test indicates known issues
- Pay close attention to the test file to ensure proper cleanup of environment variables and test isolation
2 files reviewed, 2 comments
|
Note I'm using simple |
619abbb to
e5d9f9b
Compare
e5d9f9b to
26c3be7
Compare
26c3be7 to
02650f3
Compare
|
needs to be updated to remove the new Environment variables (those are exposed by default), and have the test update the |
When frontend_path is set, the build output (including 404.html) is nested under that prefix directory. Update the static file server to mirror what sirv does in real prod deployments.
Test on_load and on_mount redirects with and without a frontend_path prefix in both dev mode (AppHarness) and prod mode (AppHarnessProd). See reflex-dev#5674
Use REFLEX_SHOW_BUILT_WITH_REFLEX env var to set the Config value, avoiding the need for a custom environment variable definition.
AppHarness._initialize_app calls get_config(reload=True), which resets any direct Config mutations made before the harness starts.
9aebd43 to
4be4cbe
Compare
|
Thanks for taking another look at this! 🙏 I've rebased onto current main and revised the approach based on your feedback:
All 7 tests passing, pre-commit checks green ✅ |
faster run time, less code
|
TIL: |
Introduces an integration test for #5674.
This xfails on
mainbut passes on #5698Edit: also fixed an apparent bug in
test_link_hover.py. There may be a deeper issue here.Edit: removed xfail after merging main which now includes #5698.
Edit: added a test for 404s.