Skip to content

Commit 4f7feb7

Browse files
author
User
committed
Add test confirming one WebSocket per page
- Add Playwright test that navigates to the base page and asserts only one unique WebSocket URL is used across all component mounts. - Update changelog with brief entry under Changed.
1 parent fc3163d commit 4f7feb7

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Don't forget to remove deprecated code on each major release!
2525

2626
### Changed
2727

28+
- Use one WebSocket per client webpage.
2829
- Updated dependencies: `reactpy>=2.0.0, <3.0.0` and `reactpy-router>=3.0.0, <4.0.0`.
2930
- Updated Python support to 3.11–3.14.
3031
- Replaced PyScript `<py-script>` tags with standard `<script type="py">` tags.

tests/test_app/tests/test_components.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ class ComponentTests(PlaywrightTestCase):
2121
# Generic Component Tests #
2222
###########################
2323

24+
def test_one_websocket_per_page(self):
25+
"""Confirm that all components on a page share a single WebSocket."""
26+
websocket_urls: list[str] = []
27+
28+
def track_ws(ws):
29+
websocket_urls.append(ws.url)
30+
31+
self.page.on("websocket", track_ws)
32+
try:
33+
self.page.goto(f"http://{self.host}:{self._port_0}/")
34+
self.page.wait_for_selector("#hello-world")
35+
self.page.wait_for_selector("#button")
36+
self.page.wait_for_selector("#parametarized-component")
37+
unique_urls = set(websocket_urls)
38+
assert len(unique_urls) == 1, (
39+
f"Expected 1 unique WebSocket URL, got {len(unique_urls)}: {unique_urls}"
40+
)
41+
finally:
42+
self.page.remove_listener("websocket", track_ws)
43+
2444
@navigate_to_page("/")
2545
def test_component_hello_world(self):
2646
self.page.wait_for_selector("#hello-world")

0 commit comments

Comments
 (0)