Skip to content

Commit 8a3bdbd

Browse files
authored
Allow changing the wasm-bindgen-test-runner timeout via an env variable (#2036)
* Add WASM_BINDGEN_TEST_TIMEOUT * Formatting
1 parent 035902a commit 8a3bdbd

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct LegacyNewSessionParameters {
5555
/// binary, controlling it, running tests, scraping output, displaying output,
5656
/// etc. It will return `Ok` if all tests finish successfully, and otherwise it
5757
/// will return an error if some tests failed.
58-
pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
58+
pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error> {
5959
let driver = Driver::find()?;
6060
let mut drop_log: Box<dyn FnMut()> = Box::new(|| ());
6161
let driver_url = match driver.location() {
@@ -145,7 +145,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
145145
// information.
146146
shell.status("Waiting for test to finish...");
147147
let start = Instant::now();
148-
let max = Duration::new(20, 0);
148+
let max = Duration::new(timeout, 0);
149149
while start.elapsed() < max {
150150
if client.text(&id, &output)?.contains("test result: ") {
151151
break;
@@ -170,7 +170,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
170170
// output, so we shouldn't need the driver logs to get printed.
171171
drop_log();
172172
} else {
173-
println!("failed to detect test as having been run");
173+
println!("Failed to detect test as having been run. It might have timed out.");
174174
if output.len() > 0 {
175175
println!("output div contained:\n{}", tab(&output));
176176
}

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ integration test.\
116116
}
117117
}
118118

119+
let timeout = env::var("WASM_BINDGEN_TEST_TIMEOUT")
120+
.map(|timeout| {
121+
timeout
122+
.parse()
123+
.expect("Could not parse 'WASM_BINDGEN_TEST_TIMEOUT'")
124+
})
125+
.unwrap_or(20);
126+
127+
if debug {
128+
println!("Set timeout to {} seconds...", timeout);
129+
}
130+
119131
// Make the generated bindings available for the tests to execute against.
120132
shell.status("Executing bindgen...");
121133
let mut b = Bindgen::new();
@@ -167,6 +179,6 @@ integration test.\
167179
}
168180

169181
thread::spawn(|| srv.run());
170-
headless::run(&addr, &shell)?;
182+
headless::run(&addr, &shell, timeout)?;
171183
Ok(())
172184
}

0 commit comments

Comments
 (0)