On WASM tests in CI #4068
Replies: 3 comments 2 replies
-
Option 1: Correctly feature-gate codeThe most correct approach would be to add the necessary feature-gates to the code. This could be done with #![cfg(not(target_arch = "wasm32"))] at the top of an integration test file for example or with #[cfg(not(target_arch = "wasm32"))]
mod native_tests {
} In the [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
async-std = "..." This will feature-gate dependencies to the correct target. If we strictly follow this approach across the library, we can at the end run all tests using: export CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner
cargo test --target wasm32-unknown-unknown Pros
Cons
|
Beta Was this translation helpful? Give feedback.
-
Option 2: Manually list crates that have wasm testsGiven that most of our crates don't have WASM-specific tests, it is worth considering doing the feature-gating only for the specific crates that have them. The feature-gating approach would be the same but we would have a list of crates in a CI script that get tested, something like: - run: wasm-pack test transports/webtransport-websys
- run: wasm-pack test protocols/gossipsub
# ... Pros
Cons
|
Beta Was this translation helpful? Give feedback.
-
Option 3: Have a dedicated WASM-test crateWe could also add a dedicated crate, similar to Pros
Cons
|
Beta Was this translation helpful? Give feedback.
-
In #4015 the topic of running WASM tests in CI came again. #3987 is another instance where this would be useful.
Writing tests isn't too difficult, one simply needs to add
#[wasm_bindgen_test]
as an attribute to a test. The problem lies in configuring all dependencies correctly, such that the test cases compile for wasm.Unless explicitly gated with a
cfg
, all code will be compiled for a certain target. Thus, if we for example referenceasync-std
anywhere in a test,cargo test --target wasm32-unknown-unknown
will attempt to compile this dependency for this target (and fail).In this discussion, I want to lay out some options on how we could tackle this.
Beta Was this translation helpful? Give feedback.
All reactions