Skip to content

Commit 945d0aa

Browse files
author
Ari Breitkreuz
committed
Address requested changes
1 parent 2fb8787 commit 945d0aa

File tree

6 files changed

+34
-39
lines changed

6 files changed

+34
-39
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ fn coverage_args(tmpdir: &Path) -> Option<PathBuf> {
256256
}
257257

258258
// Profraw path is ignored if coverage isn't enabled
259-
env::var_os("WASM_BINDGEN_TEST_COVERAGE")?;
260-
log::warn!("Coverage support is still considered highly experimental!");
259+
env::var_os("WASM_BINDGEN_UNSTABLE_TEST_COVERAGE")?;
261260
// TODO coverage link to wasm-bindgen book documenting correct usage
262261

263262
match env::var_os("WASM_BINDGEN_TEST_PROFRAW_OUT") {

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,24 +245,21 @@ pub fn spawn(
245245
};
246246
return set_isolate_origin_headers(Response::from_data("text/html", s));
247247
} else if request.url() == "/__coverage/dump" {
248-
let profraw_path = coverage.as_ref().expect(
249-
"Received coverage dump request but server wasn't set up to accept coverage",
250-
);
251-
// This is run after all tests are done and dumps the data received in the request
252-
// into a single profraw file
253-
let mut profraw =
254-
std::fs::File::create(profraw_path).expect("Couldn't create .profraw for coverage");
255-
let mut data = Vec::new();
256-
request
257-
.data()
258-
.expect("Expected coverage data in body")
259-
.read_to_end(&mut data)
260-
.expect("Failed to read message body");
261-
262-
profraw
263-
.write_all(&data)
264-
.expect("Couldn't dump coverage data to profraw");
265-
return Response::text("Coverage dumped");
248+
fn internal_err(s: &str) -> Response {
249+
log::error!("{s}");
250+
let mut ret = Response::text(s);
251+
ret.status_code = 500;
252+
ret
253+
}
254+
let Some(profraw_path) = &coverage else {
255+
return internal_err(
256+
"Received coverage dump request but server wasn't set up to accept coverage",
257+
);
258+
};
259+
return match handle_coverage_dump(profraw_path, request) {
260+
Ok(()) => Response::text("Coverage dumped"),
261+
Err(e) => internal_err(&format!("Failed to dump coverage: {e}")),
262+
};
266263
}
267264

268265
// Otherwise we need to find the asset here. It may either be in our
@@ -311,6 +308,21 @@ pub fn spawn(
311308
}
312309
}
313310

311+
fn handle_coverage_dump(profraw_path: &Path, request: &Request) -> anyhow::Result<()> {
312+
// This is run after all tests are done and dumps the data received in the request
313+
// into a single profraw file
314+
let mut profraw = std::fs::File::create(profraw_path)?;
315+
let mut data = Vec::new();
316+
if let Some(mut r_data) = request.data() {
317+
r_data.read_to_end(&mut data)?;
318+
}
319+
// Warnings about empty data should have already been handled by
320+
// the client
321+
322+
profraw.write_all(&data)?;
323+
Ok(())
324+
}
325+
314326
/*
315327
* Set the Cross-Origin-Opener-Policy and Cross-Origin_Embedder-Policy headers
316328
* on the Server response to enable worker context sharing, as described in:

crates/test/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ rust-version = "1.57"
1010

1111
[features]
1212
default = []
13-
experimental = ["coverage"]
14-
15-
coverage = ["minicov"]
13+
unstable-coverage = ["minicov"]
1614

1715
[dependencies]
1816
console_error_panic_hook = '0.1'

crates/test/src/coverage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use wasm_bindgen::prelude::wasm_bindgen;
22

3-
#[cfg(feature = "coverage")]
3+
#[cfg(feature = "unstable-coverage")]
44
#[wasm_bindgen]
55
pub fn __wbgtest_cov_dump() -> Vec<u8> {
66
let mut coverage = Vec::new();
@@ -19,7 +19,7 @@ pub fn __wbgtest_cov_dump() -> Vec<u8> {
1919
/// Called when setting WASM_BINDGEN_TEST_COVERAGE but coverage feature is disabled.
2020
/// Currently not being used because of issues in the interpreter regarding profiling
2121
/// information which cause an error before we get here.
22-
#[cfg(not(feature = "coverage"))]
22+
#[cfg(not(feature = "unstable-coverage"))]
2323
#[wasm_bindgen]
2424
pub fn __wbgtest_cov_dump() -> Vec<u8> {
2525
console_error!(

crates/test/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ macro_rules! console_log {
2121
)
2222
}
2323

24-
/// Helper macro which acts like `println!` only routes to `console.warn`
25-
/// instead.
26-
#[macro_export]
27-
macro_rules! console_warn {
28-
($($arg:tt)*) => (
29-
$crate::__rt::log_warn(&format_args!($($arg)*))
30-
)
31-
}
32-
3324
/// Helper macro which acts like `println!` only routes to `console.error`
3425
/// instead.
3526
#[macro_export]

crates/test/src/rt/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ pub fn log(args: &fmt::Arguments) {
251251
js_console_log(&args.to_string());
252252
}
253253

254-
/// Internal implementation detail of the `console_warn!` macro.
255-
pub fn log_warn(args: &fmt::Arguments) {
256-
js_console_warn(&args.to_string());
257-
}
258-
259254
/// Internal implementation detail of the `console_error!` macro.
260255
pub fn log_error(args: &fmt::Arguments) {
261256
js_console_error(&args.to_string());

0 commit comments

Comments
 (0)