1
//! Meta-test that runs WASM frontend tests if browser tooling is available.
2
//!
3
//! This test spawns `wasm-pack test` as a subprocess, allowing WASM tests
4
//! to run seamlessly as part of `cargo test --workspace`.
5

            
6
use std::process::Command;
7

            
8
1
fn has_command(cmd: &str) -> bool {
9
1
    Command::new(cmd)
10
1
        .arg("--version")
11
1
        .stdout(std::process::Stdio::null())
12
1
        .stderr(std::process::Stdio::null())
13
1
        .status()
14
1
        .is_ok_and(|s| s.success())
15
1
}
16

            
17
#[test]
18
1
fn wasm_frontend_behavior_tests() {
19
1
    if !has_command("wasm-pack") {
20
1
        eprintln!("Skipping WASM tests: wasm-pack not installed");
21
1
        eprintln!("  Install with: cargo install wasm-pack");
22
1
        return;
23
    }
24

            
25
    let has_firefox = has_command("firefox") || has_command("geckodriver");
26
    let has_chrome =
27
        has_command("google-chrome") || has_command("chromium") || has_command("chromedriver");
28

            
29
    if !has_firefox && !has_chrome {
30
        eprintln!("Skipping WASM tests: no browser available");
31
        eprintln!("  Install Firefox or Chrome with their respective drivers");
32
        return;
33
    }
34

            
35
    let frontend_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("frontend");
36

            
37
    let browser_args = if has_firefox {
38
        vec![
39
            "test",
40
            "--headless",
41
            "--firefox",
42
            "--",
43
            "--no-default-features",
44
        ]
45
    } else {
46
        vec![
47
            "test",
48
            "--headless",
49
            "--chrome",
50
            "--",
51
            "--no-default-features",
52
        ]
53
    };
54

            
55
    eprintln!("Running WASM frontend tests...");
56

            
57
    let status = Command::new("wasm-pack")
58
        .args(&browser_args)
59
        .current_dir(&frontend_dir)
60
        .status()
61
        .expect("Failed to execute wasm-pack");
62

            
63
    assert!(status.success(), "WASM frontend tests failed");
64
1
}