serial_test icon indicating copy to clipboard operation
serial_test copied to clipboard

WASM support

Open cryptoquick opened this issue 3 years ago • 4 comments

Was trying to do something like this:

#[wasm_bindgen_test]
#[serial]
async fn my_func() {
    // ...
}

But received this compile-time error:

custom attribute panicked
message: async testing attempted with async feature disabled in serial_test!

It's strange, since async should be enabled by default according to the docs. Am I missing something, or is using this in a WASM context not yet possible?

cryptoquick avatar Oct 07 '22 00:10 cryptoquick

Not sure. Haven't tested this with WASM before, so I'm guessing some weird interaction is going on...

palfrey avatar Oct 07 '22 06:10 palfrey

I'll say! Would you like me to provide you with an MRE?

Or, even better than an MRE, maybe contributing a check for that in your GitHub actions? I can open a PR.

cryptoquick avatar Oct 07 '22 07:10 cryptoquick

I'm unlikely to get around to fixing this any time in the next few weeks, given other personal stuff. If OTOH, you've got a PR that both demos the error and fixes things, I'd be interested and able to review that a lot sooner.

palfrey avatar Oct 09 '22 13:10 palfrey

I'm not sure I could fix it, but I could certainly provide a test. And no need to prioritize this over personal stuff.

cryptoquick avatar Oct 09 '22 15:10 cryptoquick

Having just read wasm_bindgen_test I think a chunk of the problem is that it strips the async attribute from the test it spits out.

Although so does tokio so I'm a bit confused. OTOH, there does appear to be a bug here where serial_test_derive didn't have a async feature, so that warning should trigger on everything async, but it doesn't for some reason!

For reference, once I fix that (PR to come once I'm able to reproduce this in something that isn't wasm_bindgen_test) you then get the new error:

error[E0277]: `[closure@serial_test_test/src/lib.rs:347:5: 347:14]` is not a future
   --> serial_test_test/src/lib.rs:347:5
    |
347 |     #[serial]
    |     ^^^^^^^^^
    |     |
    |     `[closure@serial_test_test/src/lib.rs:347:5: 347:14]` is not a future
    |     consider calling this closure
    |
    = help: the trait `Future` is not implemented for closure `[closure@serial_test_test/src/lib.rs:347:5: 347:14]`
    = note: [closure@serial_test_test/src/lib.rs:347:5: 347:14] must be a future or must implement `IntoFuture` to be awaited
note: required by a bound in `local_async_serial_core`
   --> /home/palfrey/src/serial_test/serial_test/src/serial_code_lock.rs:50:15
    |
50  |     fut: impl std::future::Future<Output = ()>,
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `local_async_serial_core`
    = note: this error originates in the attribute macro `serial` (in Nightly builds, run with -Z macro-backtrace for more info)

palfrey avatar Dec 10 '22 23:12 palfrey

https://github.com/palfrey/serial_test/pull/82 should fix this. @cryptoquick Can you test that branch against your use case please?

palfrey avatar Dec 11 '22 20:12 palfrey

I've merged https://github.com/palfrey/serial_test/pull/82 and so closing this. Please re-open if there's still an issue with your use case.

palfrey avatar Dec 14 '22 11:12 palfrey