refactor: extract shared find_chrome_for_testing_binary into common module
This commit is contained in:
parent
08255a8515
commit
dc31f3a0cb
4 changed files with 33 additions and 58 deletions
|
|
@ -43,33 +43,5 @@ impl BrowserSession {
|
|||
}
|
||||
|
||||
fn find_chrome_binary() -> String {
|
||||
find_chrome_for_testing_binary("chrome", "chrome-linux64/chrome")
|
||||
}
|
||||
|
||||
fn find_chrome_for_testing_binary(subdir: &str, binary: &str) -> String {
|
||||
let base = std::env::var("CHROME_FOR_TESTING_DIR").unwrap_or_else(|_| {
|
||||
format!(
|
||||
"{}/chrome-for-testing",
|
||||
std::env::var("MISE_DATA_DIR").unwrap_or_else(|_| {
|
||||
format!(
|
||||
"{}/.local/share/mise",
|
||||
std::env::var("HOME").unwrap_or_default()
|
||||
)
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
let base_path = std::path::Path::new(&base).join(subdir);
|
||||
if let Ok(entries) = std::fs::read_dir(&base_path) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path().join(binary);
|
||||
if path.exists() {
|
||||
return path.to_string_lossy().to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
panic!(
|
||||
"Chrome for Testing binary not found at {base_path:?}. Run `mise run install-e2e` to install it."
|
||||
);
|
||||
super::chrome_for_testing::find_chrome_for_testing_binary("chrome", "chrome-linux64/chrome")
|
||||
}
|
||||
|
|
|
|||
27
tests/e2e/helpers/chrome_for_testing.rs
Normal file
27
tests/e2e/helpers/chrome_for_testing.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
pub fn find_chrome_for_testing_binary(subdir: &str, binary: &str) -> String {
|
||||
let base = std::env::var("CHROME_FOR_TESTING_DIR").unwrap_or_else(|_| {
|
||||
format!(
|
||||
"{}/chrome-for-testing",
|
||||
std::env::var("MISE_DATA_DIR").unwrap_or_else(|_| {
|
||||
format!(
|
||||
"{}/.local/share/mise",
|
||||
std::env::var("HOME").unwrap_or_default()
|
||||
)
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
let base_path = std::path::Path::new(&base).join(subdir);
|
||||
if let Ok(entries) = std::fs::read_dir(&base_path) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path().join(binary);
|
||||
if path.exists() {
|
||||
return path.to_string_lossy().to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
panic!(
|
||||
"Chrome for Testing binary not found at {base_path:?}. Run `mise run install-e2e` to install it."
|
||||
);
|
||||
}
|
||||
|
|
@ -112,33 +112,8 @@ pub fn ensure_chromedriver() -> u16 {
|
|||
}
|
||||
|
||||
fn find_chromedriver_binary() -> String {
|
||||
find_chrome_for_testing_binary("chromedriver", "chromedriver-linux64/chromedriver")
|
||||
}
|
||||
|
||||
fn find_chrome_for_testing_binary(subdir: &str, binary: &str) -> String {
|
||||
let base = std::env::var("CHROME_FOR_TESTING_DIR").unwrap_or_else(|_| {
|
||||
format!(
|
||||
"{}/chrome-for-testing",
|
||||
std::env::var("MISE_DATA_DIR").unwrap_or_else(|_| {
|
||||
format!(
|
||||
"{}/.local/share/mise",
|
||||
std::env::var("HOME").unwrap_or_default()
|
||||
super::chrome_for_testing::find_chrome_for_testing_binary(
|
||||
"chromedriver",
|
||||
"chromedriver-linux64/chromedriver",
|
||||
)
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
let base_path = std::path::Path::new(&base).join(subdir);
|
||||
if let Ok(entries) = std::fs::read_dir(&base_path) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path().join(binary);
|
||||
if path.exists() {
|
||||
return path.to_string_lossy().to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
panic!(
|
||||
"ChromeDriver binary not found at {base_path:?}. Run `mise run install-e2e` to install it."
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ pub mod server_helpers;
|
|||
|
||||
pub mod auth;
|
||||
pub mod browser;
|
||||
pub mod chrome_for_testing;
|
||||
pub mod chromedriver;
|
||||
pub mod forms;
|
||||
pub mod wait;
|
||||
|
|
|
|||
Loading…
Reference in a new issue