Skip to content

Commit b60ed2e

Browse files
committed
Add parse a env args to invocation the browser
1 parent 732b691 commit b60ed2e

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::time::{Duration, Instant};
2020
/// etc. It will return `Ok` if all tests finish successfully, and otherwise it
2121
/// will return an error if some tests failed.
2222
pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
23-
let (driver, args) = Driver::find()?;
23+
let (driver, args, mut client_args) = Driver::find()?;
2424
println!(
2525
"Running headless tests in {} with `{}`",
2626
driver.browser(),
@@ -64,7 +64,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
6464
shell.status("Starting new webdriver session...");
6565
// Allocate a new session with the webdriver protocol, and once we've done
6666
// so schedule the browser to get closed with a call to `close_window`.
67-
let id = client.new_session(&driver)?;
67+
let id = client.new_session(&driver, &mut client_args)?;
6868
client.session = Some(id.clone());
6969

7070
// Visit our local server to open up the page that runs tests, and then get
@@ -149,17 +149,20 @@ impl Driver {
149149
/// * Env vars like `GECKODRIVER` point to the path to a binary to execute.
150150
/// * Otherwise, `PATH` is searched for an appropriate binary.
151151
///
152-
/// In both cases a list of auxiliary arguments is also returned which is
153-
/// configured through env vars like `GECKODRIVER_ARGS` to support extra
154-
/// arguments to the driver's invocation.
155-
fn find() -> Result<(Driver, Vec<String>), Error> {
156-
let env_args = |name: &str| {
157-
env::var(format!("{}_ARGS", name.to_uppercase()))
152+
/// In both cases a lists of auxiliary arguments is also returned which is
153+
/// configured through env vars like `GECKODRIVER_ARGS` and
154+
/// `GECKODRIVER_CLIENT_ARGS` to support extra arguments to invocation the
155+
/// driver and a browser respectively.
156+
fn find() -> Result<(Driver, Vec<String>, Vec<String>), Error> {
157+
let env_vars = |name: String| {
158+
env::var(name)
158159
.unwrap_or_default()
159160
.split_whitespace()
160161
.map(|s| s.to_string())
161162
.collect::<Vec<_>>()
162163
};
164+
let env_args = |name: &str| env_vars(format!("{}_ARGS", name.to_uppercase()));
165+
let env_client_args = |name: &str| env_vars(format!("{}_CLIENT_ARGS", name.to_uppercase()));
163166

164167
let drivers = [
165168
("geckodriver", Driver::Gecko as fn(PathBuf) -> Driver),
@@ -175,7 +178,7 @@ impl Driver {
175178
Some(path) => path,
176179
None => continue,
177180
};
178-
return Ok((ctor(path.into()), env_args(driver)));
181+
return Ok((ctor(path.into()), env_args(driver), env_client_args(driver)));
179182
}
180183

181184
// Next, check PATH. If we can find any supported driver, use that by
@@ -190,7 +193,7 @@ impl Driver {
190193
Some(p) => p,
191194
None => continue,
192195
};
193-
return Ok((ctor(name.into()), env_args(name)));
196+
return Ok((ctor(name.into()), env_args(name), env_client_args(name)));
194197
}
195198

196199
// TODO: download an appropriate driver? How to know which one to
@@ -255,7 +258,7 @@ enum Method<'a> {
255258
// copied the `webdriver-client` crate when writing the below bindings.
256259

257260
impl Client {
258-
fn new_session(&mut self, driver: &Driver) -> Result<String, Error> {
261+
fn new_session(&mut self, driver: &Driver, args: &mut Vec<String>) -> Result<String, Error> {
259262
match driver {
260263
Driver::Gecko(_) => {
261264
#[derive(Deserialize)]
@@ -268,11 +271,12 @@ impl Client {
268271
#[serde(rename = "sessionId")]
269272
session_id: String,
270273
}
274+
args.push("-headless".to_string());
271275
let request = json!({
272276
"capabilities": {
273277
"alwaysMatch": {
274278
"moz:firefoxOptions": {
275-
"args": ["-headless"],
279+
"args": args,
276280
}
277281
}
278282
}
@@ -316,17 +320,16 @@ impl Client {
316320
#[serde(rename = "sessionId")]
317321
session_id: String,
318322
}
323+
args.push("headless".to_string());
324+
// See https://stackoverflow.com/questions/50642308/
325+
// for what this funky `disable-dev-shm-usage`
326+
// option is
327+
args.push("disable-dev-shm-usage".to_string());
328+
args.push("no-sandbox".to_string());
319329
let request = json!({
320330
"desiredCapabilities": {
321331
"goog:chromeOptions": {
322-
"args": [
323-
"headless",
324-
// See https://stackoverflow.com/questions/50642308/
325-
// for what this funky `disable-dev-shm-usage`
326-
// option is
327-
"disable-dev-shm-usage",
328-
"no-sandbox",
329-
],
332+
"args": args,
330333
},
331334
}
332335
});

0 commit comments

Comments
 (0)