From dc31f3a0cb971f3805d30f64139111aada60efee Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Fri, 22 May 2026 14:23:52 +0000 Subject: [PATCH] refactor: extract shared find_chrome_for_testing_binary into common module --- tests/e2e/helpers/browser.rs | 30 +--------------------- tests/e2e/helpers/chrome_for_testing.rs | 27 ++++++++++++++++++++ tests/e2e/helpers/chromedriver.rs | 33 +++---------------------- tests/e2e/helpers/mod.rs | 1 + 4 files changed, 33 insertions(+), 58 deletions(-) create mode 100644 tests/e2e/helpers/chrome_for_testing.rs diff --git a/tests/e2e/helpers/browser.rs b/tests/e2e/helpers/browser.rs index 247c916..85896f3 100644 --- a/tests/e2e/helpers/browser.rs +++ b/tests/e2e/helpers/browser.rs @@ -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") } diff --git a/tests/e2e/helpers/chrome_for_testing.rs b/tests/e2e/helpers/chrome_for_testing.rs new file mode 100644 index 0000000..2607043 --- /dev/null +++ b/tests/e2e/helpers/chrome_for_testing.rs @@ -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." + ); +} diff --git a/tests/e2e/helpers/chromedriver.rs b/tests/e2e/helpers/chromedriver.rs index e307e9b..2525c9a 100644 --- a/tests/e2e/helpers/chromedriver.rs +++ b/tests/e2e/helpers/chromedriver.rs @@ -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() - ) - }) - ) - }); - - 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." - ); + super::chrome_for_testing::find_chrome_for_testing_binary( + "chromedriver", + "chromedriver-linux64/chromedriver", + ) } diff --git a/tests/e2e/helpers/mod.rs b/tests/e2e/helpers/mod.rs index ec5ca84..2739437 100644 --- a/tests/e2e/helpers/mod.rs +++ b/tests/e2e/helpers/mod.rs @@ -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;