wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

wasm-pack test: How to append cargo test parameter?

Open gitmalong opened this issue 2 years ago • 3 comments

Such as --nocapture or --test-threads=1 .

This doesn't work:

  • wasm-pack test --chrome --headless -- --test-threads=1
  • wasm-pack test --chrome --headless --test-threads=1
% wasm-pack test -h                                  
👩‍🔬  test your wasm!

Usage: wasm-pack test [OPTIONS] [PATH_AND_EXTRA_OPTIONS]...

Arguments:
  [PATH_AND_EXTRA_OPTIONS]...  Path to the Rust crate, and extra options to pass to `cargo test`

% wasm-pack test --chrome --headless --test-threads=1 
[INFO]: 🎯  Checking for the Wasm target...
error: unexpected argument '--test-threads' found

  tip: a similar argument exists: '--test'

Usage: cargo build --tests --target <TRIPLE> --test [<NAME>]

For more information, try '--help'.
Error: Compilation of your program failed
Caused by: Compilation of your program failed
Caused by: failed to execute `cargo build`: exited with exit status: 1
  full command: cd "/Users/user/Documents/Code/app" && "cargo" "build" "--tests" "--target" "wasm32-unknown-unknown" "--test-threads=1"

gitmalong avatar Aug 26 '23 07:08 gitmalong

I have the exact same question. Why hasn't this been answered yet?

pemistahl avatar Jul 03 '24 07:07 pemistahl

It's is pretty frustrating given both the docs and wasm-pack's error messages claim this works.

Looking at the code, the problem is that is that step_build_tests passes extra_options to cargo build which is intolerant of anything it doesn't understand. There appears to be an undocumented effort to fix this so it does not pass anything past a second --

If the user has run wasm-pack test -- --features "f1" -- test_name, then we want to only pass through --features "f1" to cargo build

But I still can't get the test arguments to work.

e.g.

wasm-pack test --chrome --headless => runs tests

wasm-pack test --chrome --headless --nocapture => breaks cargo build

wasm-pack test --chrome --headless -- --nocapture => still breaks cargo build

wasm-pack test --chrome --headless -- -- --nocapture => cargo build ok but tests no-longer run.

The runner just sticks on:

Running headless tests in Chrome on http://127.0.0.1:39571/

This is also the same behaviour if executing the runner directly

cargo test --target wasm32-unknown-unknown -- --nocapture

So I think the next issue is that cargo test does not process these arguments, they are instead passed to the runner and in this case, wasm-bindgen-test-runner doesn't support any extra args at all:

https://github.com/rustwasm/wasm-bindgen/blob/12f560acbd6320c45385cedfce8c869dc93596f1/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs

So, to fix this, any argument to be passed will need to be implemented.

duncanawoods avatar Jul 31 '24 09:07 duncanawoods

same, can't supply --nocapture to cargo...

Madoshakalaka avatar Feb 23 '25 06:02 Madoshakalaka