Skip to content

Commit 2a932db

Browse files
committed
Handle empty coverage report
1 parent 031fe89 commit 2a932db

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

crates/cli/src/bin/wasm-bindgen-test-runner/server.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ pub(crate) fn spawn(
3131
let cov_dump = r#"
3232
// Dump the coverage data collected during the tests
3333
const coverage = __wbgtest_cov_dump();
34-
await fetch("/__wasm_bindgen/coverage", {
35-
method: "POST",
36-
body: coverage
37-
});
34+
35+
if (coverage !== undefined) {
36+
await fetch("/__wasm_bindgen/coverage", {
37+
method: "POST",
38+
body: coverage
39+
});
40+
}
3841
"#;
3942

4043
let wbg_import_script = if test_mode.no_modules() {

crates/test/src/coverage.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use wasm_bindgen::prelude::wasm_bindgen;
22

33
#[cfg(wasm_bindgen_unstable_test_coverage)]
44
#[wasm_bindgen]
5-
pub fn __wbgtest_cov_dump() -> Vec<u8> {
5+
pub fn __wbgtest_cov_dump() -> Option<Vec<u8>> {
66
let mut coverage = Vec::new();
77
// SAFETY: this function is not thread-safe, but our whole test runner is running single-threaded.
88
unsafe {
@@ -14,11 +14,11 @@ pub fn __wbgtest_cov_dump() -> Vec<u8> {
1414
RUSTFLAGS=\"-Cinstrument-coverage -Zno-profile-runtime --emit=llvm-ir\"",
1515
);
1616
}
17-
coverage
17+
Some(coverage)
1818
}
1919

2020
#[cfg(not(wasm_bindgen_unstable_test_coverage))]
2121
#[wasm_bindgen]
22-
pub fn __wbgtest_cov_dump() -> Vec<u8> {
23-
Vec::new()
22+
pub fn __wbgtest_cov_dump() -> Option<Vec<u8>> {
23+
None
2424
}

0 commit comments

Comments
 (0)