Skip to main content

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 fixtures;
64pub mod health;
65pub mod process;
66pub mod scenario;
67pub mod server;
68
69pub use config::{ServerConfig, ServerConfigBuilder};
70pub use error::{Error, Result};
71pub use fixtures::{
72    minimal_openapi_spec, openapi_spec_crud, openapi_spec_with_get, write_spec_to, write_temp_spec,
73};
74pub use health::{HealthCheck, HealthStatus};
75pub use scenario::ScenarioManager;
76pub use server::MockForgeServer;
77
78/// Re-export commonly used types
79pub use reqwest;
80pub use tokio;
81
82#[cfg(test)]
83mod tests {
84    use super::*;
85
86    #[test]
87    fn test_config_builder() {
88        let config = ServerConfig::builder().http_port(3000).admin_port(3001).build();
89
90        assert_eq!(config.http_port, 3000);
91        assert_eq!(config.admin_port, Some(3001));
92    }
93}