This is the unpublished documentation of wasm-pack, the published documentation is available on the main Rust and WebAssembly documentation site . Features documented here may not be available in released versions of wasm-pack.

wasm-pack test

The wasm-pack test command wraps the wasm-bindgen-test-runner CLI allowing you to run wasm tests in different browsers without needing to install the different webdrivers yourself.

wasm-pack test --help


The wasm-pack test command can be given an optional path argument.

This path should point to a directory that contains a Cargo.toml file. If no path is given, the test command will run in the current directory.

# Run tests for the current directory's crate
wasm-pack test

# Run tests for a specified crate
wasm-pack test crates/crate-in-my-workspace


The test command accepts an optional profile argument: --release.

If none is supplied, then a debug test build will be used.

Test environment

Choose where to run your tests by passing in any combination of testing environment flags.

--headless is useful for running browser tests in a headless browser as part of a CI process.

wasm-pack test --node --firefox --chrome --safari --headless

Extra options

The test command can pass extra options straight to cargo test even if they are not supported in wasm-pack.

To use them simply add the extra arguments at the very end of your command, just as you would for cargo test.

cargo test -h for a list of all options that you can pass through.

Running only some tests

When debugging a specific issue, you may find yourself wanting to run a subset of tests, instead of your entire suite of tests.

Here are a few examples of how to run a subset of your tests:

# Example directory structure
$ tree crates/foo
├── Cargo.toml
├── src
│   ├── diff
│   │   ├──
│   │   └──
│   ├──
└── tests
# Run all tests in tests/ in Firefox
wasm-pack test crates/foo --firefox --headless --test diff_patch

# Run all tests in tests/ that contain the word "replace"
wasm-pack test crates/foo --firefox --headless --test diff_patch replace

# Run all tests inside of a `tests` module inside of src/lib/
wasm-pack test crates/foo --firefox --headless --lib diff::tests

# Same as the above, but only if they contain the word replace
wasm-pack test crates/foo --firefox --headless --lib diff::tests::replace

Note that you can also filter tests by location in which they're supposed to run. For example:

# Run all tests which are intended to execute in Node.js
wasm-pack test --node

# Run all tests which are intended to be executed in a browser
wasm-pack test --firefox --headless