-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(integration): use Playwright wait_for_url in poll_for_navigation #6385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """Unit tests for integration test utilities.""" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All sibling subdirectories under |
||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Callable | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.integration import utils | ||
|
|
||
|
|
||
| class _FakePage: | ||
| """Minimal page stub for testing poll_for_navigation.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| """Initialize fake page state.""" | ||
| self.url = "http://localhost:3000/" | ||
| self.wait_calls: list[tuple[Callable[[str], bool], float]] = [] | ||
|
|
||
| def wait_for_url(self, predicate: Callable[[str], bool], timeout: float) -> None: | ||
| """Record wait_for_url calls and validate the URL-change predicate. | ||
|
|
||
| Args: | ||
| predicate: URL-matcher callback passed by poll_for_navigation. | ||
| timeout: Timeout in milliseconds. | ||
| """ | ||
| self.wait_calls.append((predicate, timeout)) | ||
| assert not predicate("http://localhost:3000/") | ||
| assert predicate("http://localhost:3000/next") | ||
|
|
||
|
|
||
| def test_poll_for_navigation_uses_playwright_wait_for_url( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| """poll_for_navigation should delegate URL waiting to Playwright.""" | ||
|
|
||
| def _unexpected_expect(*_args: object, **_kwargs: object) -> None: | ||
| msg = "poll_for_navigation should not call AppHarness.expect" | ||
| raise AssertionError(msg) | ||
|
|
||
| monkeypatch.setattr(utils.AppHarness, "expect", _unexpected_expect) | ||
|
|
||
| page = _FakePage() | ||
| with utils.poll_for_navigation(page, timeout=2.5): | ||
| # The helper snapshots the current URL before yielding. | ||
| pass | ||
|
|
||
| assert len(page.wait_calls) == 1 | ||
| _, timeout_ms = page.wait_calls[0] | ||
| assert timeout_ms == pytest.approx(2500.0) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
* 1000factor converts the caller-facingtimeout(seconds) to the milliseconds unit that Playwright'swait_for_urlexpects, but there is no inline comment to document this. Per the team's convention for time-based calculations, a brief note should accompany the conversion.Rule Used: When using time-based calculations in code, includ... (source)
Learned From
reflex-dev/flexgen#2190
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!