pub struct TestApp { /* private fields */ }Expand description
Managed Tauri application lifecycle for integration testing.
Spawns a Tauri app as a child process, waits for the Victauri MCP server
to become healthy, and provides connected VictauriClient instances.
The app is killed when the TestApp is dropped.
Stderr output from the spawned process is captured in a background thread and the last few lines are included in error messages when the app fails to start or times out, making startup failures much easier to diagnose.
§Example
use victauri_test::TestApp;
#[tokio::test]
async fn my_app_works() {
let app = TestApp::spawn("cargo run -p my-app").await.unwrap();
let mut client = app.client().await.unwrap();
client.click_by_text("Submit").await.unwrap();
client.expect_text("Success").await.unwrap();
}Implementations§
Source§impl TestApp
impl TestApp
Sourcepub async fn spawn(cmd: &str) -> Result<Self, TestError>
pub async fn spawn(cmd: &str) -> Result<Self, TestError>
Spawn an application from a shell command and wait for it to become ready.
Polls the Victauri health endpoint until it responds (up to 30 seconds). Uses port auto-discovery via temp files, falling back to env vars and defaults.
§Errors
Returns TestError::Connection if the app fails to start or the health
endpoint doesn’t respond within the timeout.
Sourcepub async fn spawn_with_options(
cmd: &str,
port: Option<u16>,
timeout: Duration,
) -> Result<Self, TestError>
pub async fn spawn_with_options( cmd: &str, port: Option<u16>, timeout: Duration, ) -> Result<Self, TestError>
Spawn with explicit port and timeout configuration.
§Errors
Returns TestError::Connection if the app fails to start or the health
endpoint doesn’t respond within the timeout.
Sourcepub async fn spawn_demo() -> Result<Self, TestError>
pub async fn spawn_demo() -> Result<Self, TestError>
Spawn the bundled demo app from the workspace.
Equivalent to TestApp::spawn("cargo run -p demo-app") but with
appropriate environment variables set.
§Errors
Returns TestError::Connection if the demo app fails to start.
Sourcepub async fn attach(port: u16, token: Option<String>) -> Result<Self, TestError>
pub async fn attach(port: u16, token: Option<String>) -> Result<Self, TestError>
Connect to an already-running Victauri app (no process management).
Useful when the app is started externally (e.g., by CI or a dev script).
§Errors
Returns TestError::Connection if the health endpoint doesn’t respond.
Sourcepub async fn client(&self) -> Result<VictauriClient, TestError>
pub async fn client(&self) -> Result<VictauriClient, TestError>
Create a new connected VictauriClient for this app.
Each call returns a fresh MCP session.
§Errors
Returns errors from VictauriClient::connect_with_token.