Testing WebAssembly
Test the core logic natively first (cargo test, ctest, Go tests), then in Wasm Unit (Wasm, browser)
wasm-bindgen-test (wasm-pack test --headless --chrome/--firefox), Emscripten + Node test runners Unit (Wasm, WASI)
cargo test --target wasm32-wasip1 with Wasmtime as the runner (CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime)
as-pect, assemblyscript-unittest-framework Vitest/Jest/Mocha loading the Wasm (Node), Playwright for browser end-to-end
The WebAssembly spec test suite (.wast scripts: assert_return, assert_trap, assert_invalid) for engine/tool developers. wast2json, wasmtime wast.
cargo fuzz, wasm-smith (generate random valid modules), differential fuzzing between runtimes, Binaryen's fuzzer
Test WIT interfaces via jco in Node, or Wasmtime host test harnesses
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn adds() {
assert_eq!(wasm_demo::sum(&[1.0, 2.0]), 3.0);
};; spec-style test
(module (func (export "add") (param i32 i32) (result i32) (i32.add (local.get 0) (local.get 1))))
(assert_return (invoke "add" (i32.const 1) (i32.const 2)) (i32.const 3))
(assert_trap (module (func (export "t") (unreachable))) "unreachable")