wasm-pack test: Run Wasm Tests Headless in CI
wasm-pack test compiles your crate to wasm and runs its wasm-bindgen-test suite in Node.js or a headless browser.
For Rust code that targets the browser, wasm-pack test drives the wasm-bindgen test harness in a real (headless) engine so DOM and JS-interop tests actually execute in CI.
What it does
wasm-pack test builds the crate for wasm and launches the selected environment (Node or a browser via a WebDriver), running functions marked with #[wasm_bindgen_test] and reporting pass/fail.
Common usage
wasm-pack test --node
wasm-pack test --headless --chrome
wasm-pack test --headless --firefox
wasm-pack test --headless --chrome -- --features integrationOptions
| Flag | What it does |
|---|---|
| --node | Run the tests under Node.js |
| --headless | Run the browser without a UI (required in CI) |
| --chrome / --firefox / --safari | Choose the browser engine |
| -- <cargo args> | Pass extra args to cargo test after -- |
In CI
Always pass --headless in pipelines; without it the browser tries to open a window and hangs. The matching WebDriver (chromedriver / geckodriver) must be on PATH; GitHub-hosted runners ship Chrome and Firefox, but you still need the driver.
Common errors in CI
"wasm-pack: command not found" means wasm-pack is not installed. "chromedriver ... not found" or "geckodriver not found" means the driver is missing from PATH. "the code did not terminate" with a hang almost always means --headless was omitted. A wasm-bindgen version mismatch surfaces as "schema version mismatch".