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
        .map(|s| s.success())
15
1
        .unwrap_or(false)
16
1
}
17

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

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

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

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

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

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

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

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