cargo-llvm-cov
cargo-llvm-cov copied to clipboard
Add initial support for wasm-pack
Fixes https://github.com/taiki-e/cargo-llvm-cov/issues/337. Fixes https://github.com/taiki-e/cargo-llvm-cov/issues/221.
Requires https://github.com/rustwasm/wasm-bindgen/pull/3782.
Will also require a follow-up PR in wasm-pack but that will have trivial changes.
The changes made in this PR are still in a very rough state.
Before I turn this into a non-draft I'm mainly looking to get feedback about whether this is something you would be willing to include here.
Usage
Enable the unstable-coverage
feature in the wasm-bindgen-test
dependency.
cargo llvm-cov test --wasm --chrome --headless
Mixing WASM and non-WASM
Doing the following works:
cargo llvm-cov --no-report
cargo llvm-cov --no-report test --wasm --chrome --headless
cargo llvm-cov report
However, you need to do the following:
pub fn bool_to_str(b: bool) -> &'static str {
if b {
"true"
} else {
"false"
}
}
pub fn bar(x: u32) -> u32 {
if x == 0 {
1
} else {
42
}
}
fn main() {}
#[cfg(all(test, target_arch = "wasm32"))]
mod test {
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
use super::*;
#[wasm_bindgen_test::wasm_bindgen_test]
async fn test_foo() {
assert_eq!(bool_to_str(true), "true");
}
}
#[cfg(all(test, not(target_arch = "wasm32")))]
mod test {
use super::*;
#[test]
fn test_bar() {
assert_eq!(bar(0), 1);
}
}
which is unfortunate.
I'll look into a bit and see what I find out.
@njelich do you maybe have any comments on this?