Lines
34.88 %
Functions
66.67 %
Branches
100 %
//! Meta-test that runs WASM frontend tests if browser tooling is available.
//!
//! This test spawns `wasm-pack test` as a subprocess, allowing WASM tests
//! to run seamlessly as part of `cargo test --workspace`.
use std::process::Command;
fn has_command(cmd: &str) -> bool {
Command::new(cmd)
.arg("--version")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.map(|s| s.success())
.unwrap_or(false)
}
#[test]
fn wasm_frontend_behavior_tests() {
if !has_command("wasm-pack") {
eprintln!("Skipping WASM tests: wasm-pack not installed");
eprintln!(" Install with: cargo install wasm-pack");
return;
let has_firefox = has_command("firefox") || has_command("geckodriver");
let has_chrome =
has_command("google-chrome") || has_command("chromium") || has_command("chromedriver");
if !has_firefox && !has_chrome {
eprintln!("Skipping WASM tests: no browser available");
eprintln!(" Install Firefox or Chrome with their respective drivers");
let frontend_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("frontend");
let browser_args = if has_firefox {
vec![
"test",
"--headless",
"--firefox",
"--",
"--no-default-features",
]
} else {
"--chrome",
};
eprintln!("Running WASM frontend tests...");
let status = Command::new("wasm-pack")
.args(&browser_args)
.current_dir(&frontend_dir)
.expect("Failed to execute wasm-pack");
assert!(status.success(), "WASM frontend tests failed");