leptos-browser-test
Leptos test-app launcher for browser-driven integration tests.
This crate owns the cargo leptos serve / cargo leptos watch process management for a local Leptos test app:
- starts cargo-leptos for you, letting it serve your application
- waits until the app is fully started
- keeps a recent tail of stdout/stderr logs for failure diagnostics
- provides a handle to the launched application
- terminates the started cargo-leptos process gracefully when the handle is dropped, which in turn gracefully terminates the Leptos app
- the handle provides
.base_url(), conveniently telling you where (randomized port) the app is reachable
Test orchestration is intentionally left to the consumer. Take a look at
browser-test, for a convenient Rust-native integration test runner using
thirtyfour.
Installation
[]
= "0.2.0"
cargo-leptos requirement
leptos-browser-test v0.2.0 sets LEPTOS_GRACEFUL_SHUTDOWN_TIMEOUT_SECS and LEPTOS_GRACEFUL_SHUTDOWN_UNIX_SIGNAL on
the managed cargo-leptos child to drive the Leptos app's graceful-shutdown path on drop. These env vars require
cargo-leptos PR #648, which has not yet shipped. Until it lands
upstream, install cargo-leptos from here:
Runtime requirements
LeptosTestApp terminates the managed cargo leptos process when it is dropped, using
tokio_process_tools::TerminateOnDrop. This requires an active multithreaded Tokio runtime, so browser tests must use:
Usage
Starting an app
use ;
async
Report::into_dynamic erases the typed Report<LeptosBrowserTestError> into a generic Report so it composes with
the test harness's own error type.
Running browser-test
Start the app, pass its base URL into the runner context, and let drop-based cleanup handle the app process after
BrowserTestRunner::run(...) returns:
use ;
use ;
async
HTTPS
For apps served over HTTPS, override the URL scheme before starting:
use ;
async
SiteScheme only affects the base_url() returned to your harness. Configuring TLS on the served app itself is the
app's responsibility.
Tuning graceful shutdown
By default, the managed Leptos app gets 10 seconds to shut down on drop and is signalled with SIGINT on Unix (always
CTRL_BREAK_EVENT on Windows). Override this via:
use Duration;
use ;
async
The timeout is forwarded to cargo leptos via LEPTOS_GRACEFUL_SHUTDOWN_TIMEOUT_SECS, the signal via
LEPTOS_GRACEFUL_SHUTDOWN_UNIX_SIGNAL. The signal selector is ignored on Windows.
Manual debugging
Run the integration-test target from the consuming crate with --nocapture so the managed app's forwarded
stdout/stderr stays visible: