Skip to content

Commit c2cba34

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

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
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/cli/tests/reference/raw.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,6 @@ export function __wbg_set_wasm(val) {
66
}
77

88

9-
const heap = new Array(128).fill(undefined);
10-
11-
heap.push(undefined, null, true, false);
12-
13-
function getObject(idx) { return heap[idx]; }
14-
15-
let heap_next = heap.length;
16-
17-
function dropObject(idx) {
18-
if (idx < 132) return;
19-
heap[idx] = heap_next;
20-
heap_next = idx;
21-
}
22-
23-
function takeObject(idx) {
24-
const ret = getObject(idx);
25-
dropObject(idx);
26-
return ret;
27-
}
28-
299
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
3010

3111
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
@@ -45,6 +25,26 @@ function getStringFromWasm0(ptr, len) {
4525
ptr = ptr >>> 0;
4626
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
4727
}
28+
29+
const heap = new Array(128).fill(undefined);
30+
31+
heap.push(undefined, null, true, false);
32+
33+
function getObject(idx) { return heap[idx]; }
34+
35+
let heap_next = heap.length;
36+
37+
function dropObject(idx) {
38+
if (idx < 132) return;
39+
heap[idx] = heap_next;
40+
heap_next = idx;
41+
}
42+
43+
function takeObject(idx) {
44+
const ret = getObject(idx);
45+
dropObject(idx);
46+
return ret;
47+
}
4848
/**
4949
* @param {number} test
5050
* @returns {number}
@@ -110,11 +110,11 @@ export function __wbg_test2_39fe629b9aa739cf() {
110110
return addHeapObject(ret);
111111
};
112112

113-
export function __wbindgen_object_drop_ref(arg0) {
114-
takeObject(arg0);
115-
};
116-
117113
export function __wbindgen_throw(arg0, arg1) {
118114
throw new Error(getStringFromWasm0(arg0, arg1));
119115
};
120116

117+
export function __wbindgen_object_drop_ref(arg0) {
118+
takeObject(arg0);
119+
};
120+

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)