From 7b862d9dae42bb5b447b944da5640ed1f8b52eea Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Mon, 12 Jan 2026 11:01:35 -0600 Subject: [PATCH] tests --- cli/src/flags.rs | 40 ++++++++++++++++++++++++++++++++++++++++ src/browser.test.ts | 10 ++++++++++ 2 files changed, 50 insertions(+) diff --git a/cli/src/flags.rs b/cli/src/flags.rs index bd1da0d..54534c8 100644 --- a/cli/src/flags.rs +++ b/cli/src/flags.rs @@ -71,3 +71,43 @@ pub fn clean_args(args: &[String]) -> Vec { } result } + +#[cfg(test)] +mod tests { + use super::*; + + fn args(s: &str) -> Vec { + s.split_whitespace().map(String::from).collect() + } + + #[test] + fn test_parse_executable_path_flag() { + let flags = parse_flags(&args("--executable-path /path/to/chromium open example.com")); + assert_eq!(flags.executable_path, Some("/path/to/chromium".to_string())); + } + + #[test] + fn test_parse_executable_path_flag_no_value() { + let flags = parse_flags(&args("--executable-path")); + assert_eq!(flags.executable_path, None); + } + + #[test] + fn test_clean_args_removes_executable_path() { + let cleaned = clean_args(&args("--executable-path /path/to/chromium open example.com")); + assert_eq!(cleaned, vec!["open", "example.com"]); + } + + #[test] + fn test_clean_args_removes_executable_path_with_other_flags() { + let cleaned = clean_args(&args("--json --executable-path /path/to/chromium --headed open example.com")); + assert_eq!(cleaned, vec!["open", "example.com"]); + } + + #[test] + fn test_parse_flags_with_session_and_executable_path() { + let flags = parse_flags(&args("--session test --executable-path /custom/chrome open example.com")); + assert_eq!(flags.session, "test"); + assert_eq!(flags.executable_path, Some("/custom/chrome".to_string())); + } +} diff --git a/src/browser.test.ts b/src/browser.test.ts index 9d40926..6de7daf 100644 --- a/src/browser.test.ts +++ b/src/browser.test.ts @@ -22,6 +22,16 @@ describe('BrowserManager', () => { const page = browser.getPage(); expect(page).toBeDefined(); }); + + it('should reject invalid executablePath', async () => { + const testBrowser = new BrowserManager(); + await expect( + testBrowser.launch({ + headless: true, + executablePath: '/nonexistent/path/to/chromium', + }) + ).rejects.toThrow(); + }); }); describe('navigation', () => {