Skip to content

Commit 3f6e7aa

Browse files
committed
debug ci failures
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent c39a177 commit 3f6e7aa

File tree

6 files changed

+1173
-116
lines changed

6 files changed

+1173
-116
lines changed

.github/workflows/ci.yml

Lines changed: 157 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,49 @@ jobs:
113113
- name: Test plotly and plotly_static
114114
shell: bash
115115
run: |
116+
echo "=== Platform Information ==="
117+
echo "OS: $(uname -a)"
118+
echo "Architecture: $(uname -m)"
119+
echo "Current directory: $(pwd)"
120+
121+
echo "=== Checking for existing processes ==="
122+
ps aux | grep -E "(chromedriver|geckodriver|firefox|chrome)" || echo "No browser processes found"
123+
124+
echo "=== Checking port availability ==="
125+
netstat -an | grep -E ":(4444|4445|4446|4447|4448|4449|4450)" || echo "No WebDriver ports in use"
126+
127+
echo "=== Running tests ==="
116128
if [ "${{ matrix.browser }}" = "firefox" ]; then
117-
cargo test -p plotly --features static_export_default --lib
118-
cargo test -p plotly_static --features geckodriver,webdriver_download
129+
echo "Testing with Firefox/geckodriver..."
130+
echo "=== Firefox Environment Check ==="
131+
echo "Firefox version: $(firefox --version 2>/dev/null || echo 'Firefox not found in PATH')"
132+
echo "geckodriver version: $(geckodriver --version 2>/dev/null || echo 'geckodriver not found in PATH')"
133+
echo "Available memory: $(free -h 2>/dev/null || echo 'free command not available')"
134+
echo "Available disk space: $(df -h . 2>/dev/null || echo 'df command not available')"
135+
136+
echo "=== Testing plotly with Firefox ==="
137+
cargo test -p plotly --features static_export_default --lib -- --nocapture
138+
139+
echo "=== Testing plotly_static with Firefox ==="
140+
cargo test -p plotly_static --features geckodriver,webdriver_download -- --nocapture
119141
else
120-
cargo test -p plotly --features static_export_chromedriver,static_export_downloader --lib
121-
cargo test -p plotly_static --features chromedriver,webdriver_download
142+
echo "Testing with Chrome/chromedriver..."
143+
echo "=== Chrome Environment Check ==="
144+
echo "Chrome version: $(google-chrome --version 2>/dev/null || echo 'Chrome not found in PATH')"
145+
echo "chromedriver version: $(chromedriver --version 2>/dev/null || echo 'chromedriver not found in PATH')"
146+
147+
echo "=== Testing plotly with Chrome ==="
148+
cargo test -p plotly --features static_export_chromedriver,static_export_downloader --lib -- --nocapture
149+
150+
echo "=== Testing plotly_static with Chrome ==="
151+
cargo test -p plotly_static --features chromedriver,webdriver_download -- --nocapture
122152
fi
153+
154+
echo "=== Cleanup after tests ==="
155+
pkill -f chromedriver || echo "No chromedriver processes to kill"
156+
pkill -f geckodriver || echo "No geckodriver processes to kill"
157+
pkill -f firefox || echo "No firefox processes to kill"
158+
pkill -f chrome || echo "No chrome processes to kill"
123159
124160
test-macos-compatibility:
125161
name: Test macOS Compatibility
@@ -170,22 +206,31 @@ jobs:
170206
set -x # Enable debug mode
171207
172208
echo "=== Testing Chrome installation ==="
173-
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_chrome_installation -- --nocapture || echo "Chrome installation test failed"
209+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_chrome_installation || echo "Chrome installation test failed"
174210
175211
echo "=== Testing chromedriver installation ==="
176-
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_chromedriver_installation -- --nocapture || echo "chromedriver installation test failed"
212+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_chromedriver_installation || echo "chromedriver installation test failed"
177213
178214
echo "=== Testing static exporter creation ==="
179-
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_static_exporter_creation_macos -- --nocapture || echo "Static exporter creation test failed"
215+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_static_exporter_creation_macos || echo "Static exporter creation test failed"
180216
181217
echo "=== Testing basic PNG export ==="
182-
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_basic_png_export_macos -- --nocapture || echo "Basic PNG export test failed"
218+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_basic_png_export_macos || echo "Basic PNG export test failed"
183219
184220
echo "=== Testing macOS Chrome flags ==="
185-
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_macos_chrome_flags -- --nocapture || echo "macOS Chrome flags test failed"
221+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_macos_chrome_flags || echo "macOS Chrome flags test failed"
186222
187223
echo "=== Testing user data directory management ==="
188-
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_user_data_directory_management -- --nocapture || echo "User data directory management test failed"
224+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_user_data_directory_management || echo "User data directory management test failed"
225+
226+
echo "=== Testing PDF debugging ==="
227+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_pdf_debugging_macos || echo "PDF debugging test failed"
228+
229+
echo "=== Testing PDF with alternative flags ==="
230+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_pdf_with_alternative_flags || echo "PDF alternative flags test failed"
231+
232+
echo "=== Testing html2pdf library availability ==="
233+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib macos_tests::macos_tests::test_html2pdf_library_loading || echo "html2pdf library test failed"
189234
190235
- name: Run all plotly_static tests on macOS
191236
run: |
@@ -194,7 +239,7 @@ jobs:
194239
ps aux | grep chromedriver || echo "No chromedriver processes found"
195240
196241
# Run tests with timeout to prevent hanging
197-
timeout 300 cargo test -p plotly_static --features chromedriver,webdriver_download --lib -- --nocapture || echo "Tests timed out or failed"
242+
timeout 300 cargo test -p plotly_static --features chromedriver,webdriver_download --lib || echo "Tests timed out or failed"
198243
199244
echo "Checking for chromedriver processes after tests..."
200245
ps aux | grep chromedriver || echo "No chromedriver processes found"
@@ -208,12 +253,112 @@ jobs:
208253
lsof -i :4446 || echo "Port 4446 is free"
209254
lsof -i :4447 || echo "Port 4447 is free"
210255
211-
cargo test -p plotly --features static_export_chromedriver,static_export_downloader --lib -- --nocapture || echo "plotly static export tests failed"
256+
cargo test -p plotly --features static_export_chromedriver,static_export_downloader --lib || echo "plotly static export tests failed"
212257
213258
echo "Cleaning up after tests..."
214259
pkill -f chromedriver || echo "No chromedriver processes to kill"
215260
pkill -f "Google Chrome" || echo "No Chrome processes to kill"
216261
262+
test-windows-compatibility:
263+
name: Test Windows Compatibility
264+
runs-on: windows-latest
265+
steps:
266+
- uses: actions/checkout@v4
267+
268+
- name: Setup Chrome
269+
uses: browser-actions/setup-chrome@v1
270+
with:
271+
chrome-version: 'latest'
272+
install-chromedriver: true
273+
274+
- uses: dtolnay/rust-toolchain@stable
275+
276+
- name: Test Chrome and chromedriver installation
277+
shell: cmd
278+
run: |
279+
echo "=== System Information ==="
280+
echo "OS: %OS%"
281+
echo "Architecture: %PROCESSOR_ARCHITECTURE%"
282+
echo "PATH: %PATH%"
283+
echo "Current user: %USERNAME%"
284+
echo "Home directory: %USERPROFILE%"
285+
286+
echo "=== Chrome Installation Check ==="
287+
dir "C:\Program Files\Google\Chrome\Application\chrome.exe" 2>nul || echo "Chrome not found in Program Files"
288+
where google-chrome 2>nul || echo "Chrome not found in PATH"
289+
google-chrome --version 2>nul || echo "Chrome version check failed"
290+
291+
echo "=== chromedriver Installation Check ==="
292+
chromedriver --version 2>nul || echo "chromedriver not found in PATH"
293+
dir "C:\Program Files\Google\Chrome\Application\chromedriver.exe" 2>nul || echo "chromedriver not found in Program Files"
294+
295+
echo "=== Environment Variables ==="
296+
echo "WEBDRIVER_PATH: %WEBDRIVER_PATH%"
297+
echo "CHROMEDRIVER_PATH: %CHROMEDRIVER_PATH%"
298+
echo "CHROME_PATH: %CHROME_PATH%"
299+
300+
- name: Run Windows-specific tests
301+
shell: cmd
302+
run: |
303+
echo "Running Windows compatibility tests..."
304+
echo "Current directory: %CD%"
305+
echo "Rust version: %RUST_VERSION%"
306+
echo "Cargo version: %CARGO_VERSION%"
307+
308+
echo "=== Testing Chrome installation ==="
309+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_chrome_installation_windows
310+
311+
echo "=== Testing chromedriver installation ==="
312+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_chromedriver_installation_windows
313+
314+
echo "=== Testing static exporter creation ==="
315+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_static_exporter_creation_windows
316+
317+
echo "=== Testing basic PNG export ==="
318+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_basic_png_export_windows
319+
320+
echo "=== Testing Windows Chrome flags ==="
321+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_windows_chrome_flags
322+
323+
echo "=== Testing user data directory management ==="
324+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_user_data_directory_management_windows
325+
326+
echo "=== Testing Windows process management ==="
327+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_windows_process_management
328+
329+
echo "=== Testing Windows port availability ==="
330+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib windows_tests::windows_tests::test_windows_port_availability
331+
332+
- name: Run all plotly_static tests on Windows
333+
shell: cmd
334+
run: |
335+
echo "Running all plotly_static tests on Windows..."
336+
echo "Checking for existing chromedriver processes before tests..."
337+
tasklist /FI "IMAGENAME eq chromedriver.exe" 2>nul || echo "No chromedriver processes found"
338+
339+
echo "=== Running tests ==="
340+
cargo test -p plotly_static --features chromedriver,webdriver_download --lib
341+
342+
echo "Checking for chromedriver processes after tests..."
343+
tasklist /FI "IMAGENAME eq chromedriver.exe" 2>nul || echo "No chromedriver processes found"
344+
345+
- name: Test plotly with static export on Windows
346+
shell: cmd
347+
run: |
348+
echo "Testing plotly with static export on Windows..."
349+
echo "Checking for port conflicts before tests..."
350+
netstat -an | findstr ":4444" || echo "Port 4444 is free"
351+
netstat -an | findstr ":4445" || echo "Port 4445 is free"
352+
netstat -an | findstr ":4446" || echo "Port 4446 is free"
353+
netstat -an | findstr ":4447" || echo "Port 4447 is free"
354+
355+
echo "=== Running plotly static export tests ==="
356+
cargo test -p plotly --features static_export_chromedriver,static_export_downloader --lib
357+
358+
echo "Cleaning up after tests..."
359+
taskkill /F /IM chromedriver.exe 2>nul || echo "No chromedriver processes to kill"
360+
taskkill /F /IM chrome.exe 2>nul || echo "No Chrome processes to kill"
361+
217362
code-coverage:
218363
name: Code Coverage
219364
runs-on: ubuntu-latest

plotly_static/src/lib.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ use webdriver::WebDriver;
261261

262262
use crate::template::{IMAGE_EXPORT_JS_SCRIPT, PDF_EXPORT_JS_SCRIPT};
263263

264-
const DEFAULT_CAPS_ARRAY: [&str; 20] = [
264+
#[cfg(feature = "chromedriver")]
265+
const CHROME_DEFAULT_CAPS: [&str; 23] = [
265266
"--headless",
266267
"--no-sandbox",
267268
"--disable-gpu-sandbox",
@@ -280,9 +281,19 @@ const DEFAULT_CAPS_ARRAY: [&str; 20] = [
280281
"--password-store=basic",
281282
"--disable-web-security",
282283
"--disable-breakpad",
283-
"--allow-file-access-from-files",
284284
"--no-first-run",
285285
"--no-default-browser-check",
286+
// Additional flags for better PDF generation support
287+
"--disable-backgrounding-occluded-windows",
288+
"--disable-ipc-flooding-protection",
289+
"--enable-logging",
290+
"--v=1",
291+
];
292+
293+
#[cfg(feature = "geckodriver")]
294+
const FIREFOX_DEFAULT_CAPS: [&str; 2] = [
295+
"-headless", // Essential for headless operation (single dash for Firefox)
296+
"--no-remote", // Prevents connecting to existing Firefox instances
286297
];
287298

288299
mod template;
@@ -292,6 +303,10 @@ mod webdriver;
292303
#[cfg(target_os = "macos")]
293304
mod macos_tests;
294305

306+
#[cfg(test)]
307+
#[cfg(target_os = "windows")]
308+
mod windows_tests;
309+
295310
/// Supported image formats for static image export.
296311
///
297312
/// This enum defines all the image formats that can be exported from Plotly
@@ -438,7 +453,20 @@ impl Default for StaticExporterBuilder {
438453
webdriver_url: webdriver::WEBDRIVER_URL.to_string(),
439454
spawn_webdriver: true,
440455
offline_mode: false,
441-
webdriver_browser_caps: DEFAULT_CAPS_ARRAY.iter().map(|s| s.to_string()).collect(),
456+
webdriver_browser_caps: {
457+
#[cfg(feature = "chromedriver")]
458+
{
459+
CHROME_DEFAULT_CAPS.iter().map(|s| s.to_string()).collect()
460+
}
461+
#[cfg(feature = "geckodriver")]
462+
{
463+
FIREFOX_DEFAULT_CAPS.iter().map(|s| s.to_string()).collect()
464+
}
465+
#[cfg(not(any(feature = "chromedriver", feature = "geckodriver")))]
466+
{
467+
Vec::new()
468+
}
469+
},
442470
}
443471
}
444472
}
@@ -988,14 +1016,7 @@ impl StaticExporter {
9881016
// Define browser capabilities
9891017
let mut caps = JsonMap::new();
9901018
let mut browser_opts = JsonMap::new();
991-
992-
// Use the already-generated user data directory
993-
let user_data_dir = self
994-
.user_data_dir
995-
.as_ref()
996-
.expect("user_data_dir should be set");
997-
let mut browser_args = self.webdriver_browser_caps.clone();
998-
browser_args.push(format!("--user-data-dir={}", user_data_dir.display()));
1019+
let browser_args = self.webdriver_browser_caps.clone();
9991020

10001021
browser_opts.insert("args".to_string(), serde_json::json!(browser_args));
10011022

0 commit comments

Comments
 (0)