Skip to main content

jugar_probar/runner/
mod.rs

1//! WASM Runner with Hot Reload (Advanced Feature D)
2//!
3//! Native WASM development server with automatic hot reload,
4//! rich debugging output, and zero external dependencies.
5
6mod builder;
7mod config;
8mod server;
9
10pub use builder::{BuildCoordinator, BuildEvent, BuildResult, BuildStatus};
11pub use config::{OptLevel, RunnerConfig, WasmRunnerConfig};
12pub use server::{DebugOutput, HotReloadEvent, WasmRunner, WasmRunnerBuilder};
13
14/// Default port for HTTP server
15pub const DEFAULT_HTTP_PORT: u16 = 8080;
16/// Default port for WebSocket server
17pub const DEFAULT_WS_PORT: u16 = 8081;
18
19#[cfg(test)]
20#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
21mod tests {
22    use super::*;
23
24    // =========================================================================
25    // H₀-RUN-01: Runner configuration
26    // =========================================================================
27
28    #[test]
29    fn h0_run_01_default_config() {
30        let config = WasmRunnerConfig::default();
31        assert_eq!(config.http_port, DEFAULT_HTTP_PORT);
32        assert_eq!(config.ws_port, DEFAULT_WS_PORT);
33        assert!(config.hot_reload);
34    }
35
36    #[test]
37    fn h0_run_02_config_builder() {
38        let config = WasmRunnerConfig::builder()
39            .http_port(9000)
40            .ws_port(9001)
41            .hot_reload(false)
42            .build();
43
44        assert_eq!(config.http_port, 9000);
45        assert_eq!(config.ws_port, 9001);
46        assert!(!config.hot_reload);
47    }
48
49    // =========================================================================
50    // H₀-RUN-03: Build coordinator
51    // =========================================================================
52
53    #[test]
54    fn h0_run_03_build_result_success() {
55        let result = BuildResult::success(1024, std::time::Duration::from_millis(500));
56        assert!(result.is_success());
57        assert_eq!(result.size_bytes(), Some(1024));
58    }
59
60    #[test]
61    fn h0_run_04_build_result_failure() {
62        let result = BuildResult::failure(vec!["error: test".to_string()]);
63        assert!(!result.is_success());
64        assert!(result.errors().is_some());
65    }
66
67    // =========================================================================
68    // H₀-RUN-05: Optimization levels
69    // =========================================================================
70
71    #[test]
72    fn h0_run_05_opt_levels() {
73        assert_eq!(OptLevel::Debug.as_str(), "0");
74        assert_eq!(OptLevel::Release.as_str(), "3");
75        assert_eq!(OptLevel::Size.as_str(), "s");
76        assert_eq!(OptLevel::MinSize.as_str(), "z");
77    }
78
79    // =========================================================================
80    // H₀-RUN-06: Debug output configuration
81    // =========================================================================
82
83    #[test]
84    fn h0_run_06_debug_output_default() {
85        let output = DebugOutput::default();
86        assert!(output.console);
87        assert!(output.metrics);
88    }
89
90    #[test]
91    fn h0_run_07_debug_output_none() {
92        let output = DebugOutput::none();
93        assert!(!output.console);
94        assert!(!output.metrics);
95        assert!(!output.network);
96        assert!(!output.memory);
97    }
98
99    // =========================================================================
100    // H₀-RUN-08: Hot reload events
101    // =========================================================================
102
103    #[test]
104    fn h0_run_08_hot_reload_event() {
105        let event = HotReloadEvent::Rebuild {
106            duration: std::time::Duration::from_millis(100),
107            preserved: vec!["AppState".to_string()],
108        };
109
110        match event {
111            HotReloadEvent::Rebuild {
112                duration,
113                preserved,
114            } => {
115                assert_eq!(duration.as_millis(), 100);
116                assert_eq!(preserved.len(), 1);
117            }
118            _ => panic!("Wrong event type"),
119        }
120    }
121
122    // =========================================================================
123    // H₀-RUN-09: Runner creation
124    // =========================================================================
125
126    #[test]
127    fn h0_run_09_runner_builder() {
128        let runner = WasmRunnerBuilder::new()
129            .http_port(8888)
130            .source_maps(true)
131            .build();
132
133        assert_eq!(runner.config().http_port, 8888);
134        assert!(runner.config().source_maps);
135    }
136}