Skip to content

Commit 974f894

Browse files
authored
Make tests more resilient (#124)
* feat: make tests work more consistently * fix: improve visibility detection * chore: update CI --------- Signed-off-by: Luca Foppiano <luca@foppiano.org>
1 parent b2f01e5 commit 974f894

31 files changed

Lines changed: 95 additions & 581 deletions

.github/workflows/ci-build.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Build unstable
22

3-
on: [ push, pull_request ]
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
47

58
concurrency:
69
group: unstable
@@ -18,13 +21,13 @@ jobs:
1821
runs-on: ${{ matrix.os }}
1922

2023
steps:
21-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v6
2225
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v5
26+
uses: actions/setup-python@v6
2427
with:
2528
python-version: ${{ matrix.python-version }}
2629
cache: 'pip'
27-
- uses: actions/setup-node@v4
30+
- uses: actions/setup-node@v6
2831
with:
2932
node-version: ${{matrix.node-version}}
3033
- name: build frontend

.github/workflows/ci-bump-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout the code
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@v6
2424

2525
- name: Bump version
2626
id: bump

.github/workflows/ci-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
build:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v6
1818
- name: Set up Python 3.9
19-
uses: actions/setup-python@v5
19+
uses: actions/setup-python@v6
2020
with:
2121
python-version: "3.9"
2222
cache: 'pip'
23-
- uses: actions/setup-node@v4
23+
- uses: actions/setup-node@v6
2424
with:
2525
node-version: "18"
2626
- name: build frontend

streamlit_pdf_viewer/frontend/src/PdfViewer.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ export default {
381381
382382
const handleResize = async () => {
383383
if (isRendering.value) return;
384+
// Skip render if container is hidden (e.g., inactive Streamlit tab)
385+
if (pdfContainer.value && pdfContainer.value.clientWidth === 0) return;
384386
isRendering.value = true;
385387
try {
386388
const binaryDataUrl = `data:application/pdf;base64,${props.args.binary}`;
@@ -464,15 +466,29 @@ export default {
464466
465467
const debouncedHandleResize = debounce(handleResize, 200);
466468
469+
let lastContainerWidth = 0;
470+
const resizeObserver = new ResizeObserver((entries) => {
471+
const entry = entries[0];
472+
const newWidth = entry.contentRect.width;
473+
if (lastContainerWidth === 0 && newWidth > 0) {
474+
debouncedHandleResize();
475+
}
476+
lastContainerWidth = newWidth;
477+
});
478+
467479
onMounted(() => {
468480
debouncedHandleResize();
469481
window.addEventListener("resize", debouncedHandleResize);
470482
document.addEventListener('click', handleClickOutside);
483+
if (pdfContainer.value) {
484+
resizeObserver.observe(pdfContainer.value);
485+
}
471486
});
472487
473488
onUnmounted(() => {
474489
window.removeEventListener("resize", debouncedHandleResize);
475490
document.removeEventListener('click', handleClickOutside);
491+
resizeObserver.disconnect();
476492
});
477493
478494
return {

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import pytest
1717
from pathlib import Path
1818
from typing import Generator, Any, Dict
19-
from playwright.sync_api import Browser, BrowserContext, Page
19+
from playwright.sync_api import Browser, BrowserContext, Page, expect
2020

2121
from tests import ROOT_DIRECTORY
2222
from tests.e2e_utils import StreamlitRunner
@@ -143,7 +143,7 @@ def default_go_to_app(page: Page, default_streamlit_app: StreamlitRunner):
143143
"""Navigate to the default streamlit app and wait for it to load."""
144144
page.goto(default_streamlit_app.server_url)
145145
# Wait for app to load
146-
page.get_by_role("img", name="Running...").is_hidden()
146+
expect(page.get_by_role("img", name="Running...")).not_to_be_visible()
147147

148148

149149
@pytest.fixture(autouse=True, scope="module")
@@ -164,4 +164,4 @@ def go_to_app(page: Page, streamlit_app: StreamlitRunner):
164164
"""
165165
page.goto(streamlit_app.server_url)
166166
# Wait for app to load
167-
page.get_by_role("img", name="Running...").is_hidden()
167+
expect(page.get_by_role("img", name="Running...")).not_to_be_visible()

tests/e2e_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def is_server_running(self, timeout: int = 30) -> bool:
160160
if response.text == "ok":
161161
return True
162162
time.sleep(3)
163-
if time.time() - start_time > 60 * timeout:
163+
if time.time() - start_time > timeout:
164164
return False
165165

166166
@property

tests/test_accessibility.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ def test_accessibility_high_contrast_mode(page: Page):
8383
}
8484
""")
8585

86-
page.wait_for_timeout(1000)
87-
8886
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
8987
expect(iframe_components).to_have_count(1)
90-
88+
9189
# Check that the viewer is still visible and functional in high contrast
9290
iframe_frame = page.frame_locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]').nth(0)
9391
pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]')
@@ -109,8 +107,8 @@ def test_accessibility_responsive_text_sizing(page: Page):
109107

110108
for viewport in viewports:
111109
page.set_viewport_size(viewport)
112-
page.wait_for_timeout(1000)
113-
110+
page.wait_for_timeout(500)
111+
114112
iframe_components = page.locator('iframe[title="streamlit_pdf_viewer.streamlit_pdf_viewer"]')
115113
expect(iframe_components).to_have_count(1)
116114

tests/test_alignment_center.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def streamlit_app():
3131
def go_to_app(page: Page, streamlit_app: StreamlitRunner):
3232
page.goto(streamlit_app.server_url)
3333
# Wait for app to load
34-
page.get_by_role("img", name="Running...").is_hidden()
34+
expect(page.get_by_role("img", name="Running...")).not_to_be_visible()
3535

3636

3737
def test_should_render_with_center_alignment(page: Page):

tests/test_alignment_left.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def streamlit_app():
3131
def go_to_app(page: Page, streamlit_app: StreamlitRunner):
3232
page.goto(streamlit_app.server_url)
3333
# Wait for app to load
34-
page.get_by_role("img", name="Running...").is_hidden()
34+
expect(page.get_by_role("img", name="Running...")).not_to_be_visible()
3535

3636

3737
def test_should_render_with_left_alignment(page: Page):

tests/test_alignment_right.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def streamlit_app():
3131
def go_to_app(page: Page, streamlit_app: StreamlitRunner):
3232
page.goto(streamlit_app.server_url)
3333
# Wait for app to load
34-
page.get_by_role("img", name="Running...").is_hidden()
34+
expect(page.get_by_role("img", name="Running...")).not_to_be_visible()
3535

3636

3737
def test_should_render_with_right_alignment(page: Page):

0 commit comments

Comments
 (0)