Skip to content

Commit

Permalink
Handle empty coverage report (#4063)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Aug 11, 2024
1 parent 031fe89 commit d3872f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
11 changes: 7 additions & 4 deletions crates/cli/src/bin/wasm-bindgen-test-runner/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ pub(crate) fn spawn(
let cov_dump = r#"
// Dump the coverage data collected during the tests
const coverage = __wbgtest_cov_dump();
await fetch("/__wasm_bindgen/coverage", {
method: "POST",
body: coverage
});
if (coverage !== undefined) {
await fetch("/__wasm_bindgen/coverage", {
method: "POST",
body: coverage
});
}
"#;

let wbg_import_script = if test_mode.no_modules() {
Expand Down
48 changes: 24 additions & 24 deletions crates/cli/tests/reference/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@ export function __wbg_set_wasm(val) {
}


const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);

function getObject(idx) { return heap[idx]; }

let heap_next = heap.length;

function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}

function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}

const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
Expand All @@ -45,6 +25,26 @@ function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);

function getObject(idx) { return heap[idx]; }

let heap_next = heap.length;

function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}

function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
/**
* @param {number} test
* @returns {number}
Expand Down Expand Up @@ -110,11 +110,11 @@ export function __wbg_test2_39fe629b9aa739cf() {
return addHeapObject(ret);
};

export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};

export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};

export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};

8 changes: 4 additions & 4 deletions crates/test/src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use wasm_bindgen::prelude::wasm_bindgen;

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

#[cfg(not(wasm_bindgen_unstable_test_coverage))]
#[wasm_bindgen]
pub fn __wbgtest_cov_dump() -> Vec<u8> {
Vec::new()
pub fn __wbgtest_cov_dump() -> Option<Vec<u8>> {
None
}

0 comments on commit d3872f1

Please sign in to comment.