Unable to provide -- cargo test. I would like to enable --nocapture option
1) wasm-pack test --node -- -- --nocapture
2) cargo test --target wasm32-unknown-unknown -- --nocapture
should work
RUST_LOG=debug wasm-pack test --node -- -- --nocapture
...
...
...
INFO 2019-10-22T08:02:11Z: wasm_pack::child: Running "cargo" "test" "--target" "wasm32-unknown-unknown" "--" "--nocapture"
...
... Many rows as
...
[2019-10-22T08:05:55Z DEBUG wasm_bindgen_test_runner::headless] got: {"sessionId":"4ed1104cecc6b096a79986b263afd0d8","status":0,"value":""}
[2019-10-22T08:05:55Z DEBUG wasm_bindgen_test_runner::headless] GET /session/4ed1104cecc6b096a79986b263afd0d8/element/0.3679790180116995-1/text
...
...
...
console.log div contained:
panicked at 'flag --nocapture not supported', /home/jiojiajiu/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-test-0.2.50/src/rt/mod.rs:245:17
Stack:
Error
at imports.wbg.__wbg_new_59cb74e423758ede (http://127.0.0.1:32875/wasm-bindgen-test:619:25)
at console_error_panic_hook::Error::new::h6aa3687b2b3032a1 (wasm-function[1970]:22)
at console_error_panic_hook::hook_impl::hdd0b278833ceb748 (wasm-function[352]:100)
at console_error_panic_hook::hook::h5012e72fd095acd0 (wasm-function[2160]:38)
at core::ops::function::Fn::call::hc91957a95ce14190 (wasm-function[1975]:45)
at std::panicking::rust_panic_with_hook::hcd61bc6e24640181 (wasm-function[579]:262)
at std::panicking::continue_panic_fmt::h358c0389c012d946 (wasm-function[1307]:116)
at std::panicking::begin_panic_fmt::hed4424a2ecf0fbfc (wasm-function[1550]:92)
at wasm_bindgen_test::__rt::Context::args::h7f708709ae0a3169 (wasm-function[89]:990)
at wasmbindgentestcontext_args (wasm-function[557]:243)
wasm-pack version: 0.8.1
rustc version: 1.40.0-nightly (7979016af 2019-10-20)
Hey! You have two โ, you should only have one. Try removing one of the โ and that should work
As in try this:
wasm-pack test --node -- --nocapture
Hello @chinedufn , --nocapture isn't option of cargo but test binary argument
I need to get
cargo test -- --nocapture
as I did with
cargo test --target wasm32-unknown-unknown -- --nocapture
but the behavior is the same
The wasm tests don't use the native test runner, they use wasm-bindgen-test-runner which doesn't support --nocapture IIRC. But I think it just always prints everything anyways... Can't remember if wasm-pack does any log filtering for tests or not.
Oh, thank you @fitzgen , now I've got the point!
I think the problem was in my understanding how the tests(and wasm_bindgen) works - I used println! and wanted to have an output in a linux console not matter how I launch my test (--node, --chrome). console.log works fine and looks it's only the way to output something cause code is invoked in javascript vm. Maybe it has sense to convert println to console.log on compilation. Hence my issue(related logs) is closed, what about passing additional properties to test binary - looks like its irrelevant also at this point (if there is option for support). Fill free to close my bug report then
(A little off-topic, but maybe we should create a crate similar to console_error_panic_hook, except what it does is it uses set_print to make println! work)
I don't think there is a std hook that we can replace, like there is for panicking.
I think the way forward for println! working by default on wasm is to use wasi (with a wasi polyfill if running on the Web).
FWIW, in addition to console.log, the log crate also works well with the console_log backend.
I'm going to close this issue because I think everything mentioned in the OP is resolved. If I'm mistaken feel free to reopen!
@fitzgen There actually is a hook: https://doc.rust-lang.org/nightly/src/std/io/stdio.rs.html#746
Of course it's unstable, but I think that's okay. Wasm in general is unstable.
I agree that long-term we will want to build on top of Wasi, but the hook works now, rather than months (or years) in the future.
Seems fine to create a crate for that then, that is very upfront about being nightly-only :+1:
Most helpful comment
Seems fine to create a crate for that then, that is very upfront about being nightly-only :+1: