mockforge_test/
lib.rs

1//! # MockForge Test Utilities
2//!
3//! Test utilities for MockForge to simplify integration with test frameworks like Playwright and Vitest.
4//!
5//! ## Features
6//!
7//! - **Easy Server Spawning**: Start and stop MockForge servers programmatically
8//! - **Health Checks**: Wait for server readiness with configurable timeouts
9//! - **Scenario Management**: Switch scenarios/workspaces per-test
10//! - **Process Management**: Automatic cleanup of spawned processes
11//! - **Profile Support**: Run with different MockForge profiles
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use mockforge_test::{MockForgeServer, ServerConfig};
17//!
18//! #[tokio::test]
19//! async fn test_with_mockforge() {
20//!     // Start MockForge server
21//!     let server = MockForgeServer::builder()
22//!         .http_port(3000)
23//!         .build()
24//!         .await
25//!         .expect("Failed to start server");
26//!
27//!     // Server is ready - run your tests
28//!     let response = reqwest::get("http://localhost:3000/health")
29//!         .await
30//!         .expect("Failed to get health");
31//!
32//!     assert!(response.status().is_success());
33//!
34//!     // Server automatically stops when dropped
35//! }
36//! ```
37//!
38//! ## Scenario Switching
39//!
40//! ```rust,no_run
41//! use mockforge_test::MockForgeServer;
42//!
43//! #[tokio::test]
44//! async fn test_scenario_switching() {
45//!     let server = MockForgeServer::builder()
46//!         .http_port(3000)
47//!         .build()
48//!         .await
49//!         .expect("Failed to start server");
50//!
51//!     // Switch to a different scenario
52//!     server.scenario("user-auth-success")
53//!         .await
54//!         .expect("Failed to switch scenario");
55//!
56//!     // Test with the new scenario
57//!     // ...
58//! }
59//! ```
60
61pub mod config;
62pub mod error;
63pub mod health;
64pub mod process;
65pub mod scenario;
66pub mod server;
67
68pub use config::{ServerConfig, ServerConfigBuilder};
69pub use error::{Error, Result};
70pub use health::{HealthCheck, HealthStatus};
71pub use scenario::ScenarioManager;
72pub use server::MockForgeServer;
73
74/// Re-export commonly used types
75pub use reqwest;
76pub use tokio;
77
78#[cfg(test)]
79mod tests {
80    use super::*;
81
82    #[test]
83    fn test_config_builder() {
84        let config = ServerConfig::builder().http_port(3000).admin_port(3001).build();
85
86        assert_eq!(config.http_port, 3000);
87        assert_eq!(config.admin_port, Some(3001));
88    }
89}