Skip to content

Commit 7a7b6b0

Browse files
committed
add firefox to ci and add feature to increase timeout pdf generation in
the CI as windows CI fails Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent d3a0cd1 commit 7a7b6b0

File tree

4 files changed

+93
-42
lines changed

4 files changed

+93
-42
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,37 @@ jobs:
7070
strategy:
7171
fail-fast: false
7272
matrix:
73-
os: [ubuntu-latest, windows-latest, macos-latest]
73+
include:
74+
- os: ubuntu-latest
75+
browser: chrome
76+
features: plotly_ndarray,plotly_image,static_export_default,ci_pdf_timeout
77+
- os: ubuntu-latest
78+
browser: firefox
79+
features: plotly_ndarray,plotly_image,static_export_geckodriver,static_export_downloader,ci_pdf_timeout
80+
- os: windows-latest
81+
browser: chrome
82+
features: plotly_ndarray,plotly_image,static_export_chromedriver,ci_pdf_timeout
83+
- os: macos-latest
84+
browser: chrome
85+
features: plotly_ndarray,plotly_image,static_export_default,ci_pdf_timeout
7486
runs-on: ${{ matrix.os }}
7587
timeout-minutes: ${{ matrix.os == 'windows-latest' && 30 || 10 }}
7688
steps:
7789
- name: Setup Chrome
90+
if: matrix.browser == 'chrome'
7891
uses: browser-actions/setup-chrome@v1
7992
with:
8093
chrome-version: 'latest'
8194
install-chromedriver: true
8295
id: setup-chrome
8396

97+
- name: Setup Firefox
98+
if: matrix.browser == 'firefox'
99+
uses: browser-actions/setup-firefox@v1
100+
with:
101+
firefox-version: 'latest'
102+
id: setup-firefox
103+
84104
- uses: actions/checkout@v4
85105

86106
- uses: dtolnay/rust-toolchain@stable
@@ -106,14 +126,34 @@ jobs:
106126
-ChromePath "${{ steps.setup-chrome.outputs.chrome-path }}" `
107127
-ChromeDriverPath "${{ steps.setup-chrome.outputs.chromedriver-path }}"
108128
109-
# Run tests on non-Windows platforms
110-
- name: Run tests (${{ matrix.os }})
111-
if: matrix.os != 'windows-latest'
112-
run: cargo test --verbose --workspace --features plotly_ndarray,plotly_image,static_export_default --exclude plotly_kaleido
129+
# Run tests on Ubuntu with Chrome
130+
- name: Run tests (${{ matrix.os }} - Chrome)
131+
if: matrix.os == 'ubuntu-latest' && matrix.browser == 'chrome'
132+
run: cargo test --verbose --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
133+
134+
# Run tests on Ubuntu with Firefox
135+
- name: Run tests (${{ matrix.os }} - Firefox)
136+
if: matrix.os == 'ubuntu-latest' && matrix.browser == 'firefox'
137+
run: |
138+
# Set environment variables for Firefox WebDriver
139+
export BROWSER_PATH="${{ steps.setup-firefox.outputs.firefox-path }}"
140+
export RUST_LOG="debug"
141+
export RUST_BACKTRACE="1"
142+
143+
echo "Environment variables set:"
144+
echo "BROWSER_PATH: $BROWSER_PATH"
145+
echo "RUST_LOG: $RUST_LOG"
146+
147+
cargo test --verbose --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
148+
149+
# Run tests on macOS with Chrome
150+
- name: Run tests (${{ matrix.os }} - Chrome)
151+
if: matrix.os == 'macos-latest' && matrix.browser == 'chrome'
152+
run: cargo test --verbose --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
113153

114154
# Run tests on Windows with Chrome WebDriver
115-
- name: Run tests (${{ matrix.os }})
116-
if: matrix.os == 'windows-latest'
155+
- name: Run tests (${{ matrix.os }} - Chrome)
156+
if: matrix.os == 'windows-latest' && matrix.browser == 'chrome'
117157
shell: pwsh
118158
run: |
119159
# Set environment variables for WebDriver
@@ -127,7 +167,7 @@ jobs:
127167
Write-Host "WEBDRIVER_PATH: $env:WEBDRIVER_PATH"
128168
Write-Host "BROWSER_PATH: $env:BROWSER_PATH"
129169
130-
cargo test --verbose --workspace --features plotly_ndarray,plotly_image,static_export_chromedriver --exclude plotly_kaleido
170+
cargo test --verbose --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
131171
132172
code-coverage:
133173
name: Code Coverage

plotly_static/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exclude = ["target/*"]
1616
webdriver_download = []
1717
geckodriver = []
1818
chromedriver = []
19+
ci_pdf_timeout = []
1920

2021
[dependencies]
2122
log = "0.4"

plotly_static/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ use serde_json::map::Map as JsonMap;
274274
use urlencoding::encode;
275275
use webdriver::WebDriver;
276276

277-
use crate::template::{IMAGE_EXPORT_JS_SCRIPT, PDF_EXPORT_JS_SCRIPT};
277+
use crate::template::{get_pdf_export_js_script, IMAGE_EXPORT_JS_SCRIPT};
278278

279279
#[cfg(all(feature = "chromedriver", not(target_os = "windows")))]
280280
fn chrome_default_caps() -> Vec<&'static str> {
@@ -969,7 +969,7 @@ impl StaticExporter {
969969
plot.scale.into(),
970970
];
971971

972-
(PDF_EXPORT_JS_SCRIPT, args)
972+
(get_pdf_export_js_script(), args)
973973
}
974974
_ => {
975975
let args = vec![
@@ -980,11 +980,11 @@ impl StaticExporter {
980980
plot.scale.into(),
981981
];
982982

983-
(IMAGE_EXPORT_JS_SCRIPT, args)
983+
(IMAGE_EXPORT_JS_SCRIPT.to_string(), args)
984984
}
985985
};
986986

987-
let data = client.execute_async(js_script, args).await?;
987+
let data = client.execute_async(&js_script, args).await?;
988988

989989
// Don't close the client - keep it for reuse
990990
// client.close().await?;

plotly_static/src/template.rs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ pub(crate) const IMAGE_EXPORT_JS_SCRIPT: &str = r#"
3535
});
3636
"#;
3737

38-
pub(crate) const PDF_EXPORT_JS_SCRIPT: &str = r##"
38+
pub(crate) fn get_pdf_export_js_script() -> String {
39+
let timeout_ms = if cfg!(feature = "ci_pdf_timeout") {
40+
500
41+
} else {
42+
250
43+
};
44+
45+
format!(
46+
r##"
3947
const plot = arguments[0];
4048
const format = arguments[1];
4149
const width = arguments[2];
@@ -45,26 +53,26 @@ pub(crate) const PDF_EXPORT_JS_SCRIPT: &str = r##"
4553
4654
const graph_div = document.getElementById('plotly-html-element');
4755
48-
if (typeof html2pdf === 'undefined') {
56+
if (typeof html2pdf === 'undefined') {{
4957
callback('ERROR:html2pdf library not loaded');
5058
return;
51-
}
59+
}}
5260
5361
let tempDiv = null;
5462
55-
const cleanup = () => {
56-
if (tempDiv) {
63+
const cleanup = () => {{
64+
if (tempDiv) {{
5765
document.body.removeChild(tempDiv);
58-
}
59-
};
66+
}}
67+
}};
6068
61-
Plotly.newPlot(graph_div, plot).then(function() {
62-
return Plotly.toImage(graph_div, {
69+
Plotly.newPlot(graph_div, plot).then(function() {{
70+
return Plotly.toImage(graph_div, {{
6371
format: format,
6472
width: width,
6573
height: height,
66-
});
67-
}).then(function(dataUrl) {
74+
}});
75+
}}).then(function(dataUrl) {{
6876
tempDiv = document.createElement('div');
6977
tempDiv.style.width = width + 'px';
7078
tempDiv.style.height = height + 'px';
@@ -88,22 +96,22 @@ pub(crate) const PDF_EXPORT_JS_SCRIPT: &str = r##"
8896
img.style.boxSizing = 'border-box';
8997
tempDiv.appendChild(img);
9098
91-
return new Promise(function(resolve) {
92-
img.onload = function() {
99+
return new Promise(function(resolve) {{
100+
img.onload = function() {{
93101
// Brief delay to ensure image is fully rendered
94-
setTimeout(resolve, 250);
95-
};
96-
img.onerror = function() {
102+
setTimeout(resolve, {timeout_ms});
103+
}};
104+
img.onerror = function() {{
97105
cleanup();
98106
callback('ERROR:Failed to load image');
99-
};
100-
});
101-
}).then(function() {
102-
return html2pdf().from(tempDiv).set({
107+
}};
108+
}});
109+
}}).then(function() {{
110+
return html2pdf().from(tempDiv).set({{
103111
margin: 0,
104112
filename: 'plotly-plot.pdf',
105-
image: { type: 'jpeg', quality: 1},
106-
html2canvas: {
113+
image: {{ type: 'jpeg', quality: 1}},
114+
html2canvas: {{
107115
scale: scale,
108116
backgroundColor: '#fff',
109117
useCORS: true,
@@ -116,22 +124,24 @@ pub(crate) const PDF_EXPORT_JS_SCRIPT: &str = r##"
116124
foreignObjectRendering: false,
117125
scrollY: 0,
118126
scrollX: 0
119-
},
120-
jsPDF: {
127+
}},
128+
jsPDF: {{
121129
unit: 'px',
122130
format: [width, height],
123131
orientation: width > height ? 'landscape' : 'portrait',
124132
compress: true
125-
}
126-
}).toPdf().output('datauristring');
127-
}).then(function(dataUri) {
133+
}}
134+
}}).toPdf().output('datauristring');
135+
}}).then(function(dataUri) {{
128136
cleanup();
129137
callback(dataUri);
130-
}).catch(function(err) {
138+
}}).catch(function(err) {{
131139
cleanup();
132140
callback('ERROR:' + err.toString());
133-
});
134-
"##;
141+
}});
142+
"##
143+
)
144+
}
135145

136146
pub(crate) fn get_html_body(offline: bool) -> String {
137147
let offline_js = offline_js_sources();

0 commit comments

Comments
 (0)