Skip to content

Commit fd3adae

Browse files
committed
fix old tests
1 parent c92079a commit fd3adae

File tree

8 files changed

+39
-46
lines changed

8 files changed

+39
-46
lines changed

pyproject.toml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies = [
3737
"asgiref >=3",
3838
"lxml >=4",
3939
"servestatic >=3.0.0",
40+
"orjson >=3",
4041
]
4142
dynamic = ["version"]
4243
urls.Changelog = "https://reactpy.dev/docs/about/changelog.html"
@@ -94,26 +95,28 @@ extra-dependencies = [
9495
"playwright",
9596
"jsonpointer",
9697
"uvicorn[standard]",
98+
"jinja2-simple-tags",
99+
"jinja2 >=3",
100+
"starlette",
97101
]
98102

99103
[[tool.hatch.envs.hatch-test.matrix]]
100104
python = ["3.9", "3.10", "3.11", "3.12"]
101105

102106
[tool.pytest.ini_options]
103107
addopts = """\
104-
--strict-config
105-
--strict-markers
106-
"""
108+
--strict-config
109+
--strict-markers
110+
"""
111+
filterwarnings = """
112+
ignore::DeprecationWarning:uvicorn.*
113+
ignore::DeprecationWarning:websockets.*
114+
"""
107115
testpaths = "tests"
108116
xfail_strict = true
109117
asyncio_mode = "auto"
110118
log_cli_level = "INFO"
111119

112-
[tool.hatch.envs.default.scripts]
113-
test-cov = "playwright install && coverage run -m pytest {args:tests}"
114-
cov-report = ["coverage report"]
115-
cov = ["test-cov {args}", "cov-report"]
116-
117120
[tool.hatch.envs.default.env-vars]
118121
REACTPY_DEBUG_MODE = "1"
119122

src/js/packages/@reactpy/client/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ export class ReactPyClient
7878
}
7979

8080
loadModule(moduleName: string): Promise<ReactPyModule> {
81-
return import(`${this.urls.jsModulesPath}/${moduleName}`);
81+
return import(`${this.urls.jsModulesPath}${moduleName}`);
8282
}
8383
}

src/reactpy/asgi/standalone.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from __future__ import annotations
2+
13
import hashlib
24
import re
35
from collections.abc import Coroutine
46
from dataclasses import dataclass
57
from datetime import datetime
68
from email.utils import formatdate
79
from logging import getLogger
8-
from pathlib import Path
910
from typing import Any, Callable
1011

1112
from typing_extensions import Unpack

tests/conftest.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@
2020
)
2121

2222
REACTPY_ASYNC_RENDERING.current = True
23+
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS", "False") in {
24+
"y",
25+
"yes",
26+
"t",
27+
"true",
28+
"on",
29+
"1",
30+
}
2331

2432

2533
def pytest_addoption(parser: Parser) -> None:
2634
parser.addoption(
27-
"--headed",
28-
dest="headed",
35+
"--headless",
36+
dest="headless",
2937
action="store_true",
30-
help="Open a browser window when running web-based tests",
38+
help="Don't open a browser window when running web-based tests",
3139
)
3240

3341

@@ -37,8 +45,8 @@ def install_playwright():
3745

3846

3947
@pytest.fixture(autouse=True, scope="session")
40-
def rebuild_javascript():
41-
subprocess.run(["hatch", "run", "javascript:build"], check=True) # noqa: S607, S603
48+
def rebuild():
49+
subprocess.run(["hatch", "build", "-t", "wheel"], check=True) # noqa: S607, S603
4250

4351

4452
@pytest.fixture
@@ -68,7 +76,9 @@ async def browser(pytestconfig: Config):
6876
from playwright.async_api import async_playwright
6977

7078
async with async_playwright() as pw:
71-
yield await pw.chromium.launch(headless=not bool(pytestconfig.option.headed))
79+
yield await pw.chromium.launch(
80+
headless=bool(pytestconfig.option.headless) or GITHUB_ACTIONS
81+
)
7282

7383

7484
@pytest.fixture(scope="session")

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from playwright.async_api import Browser
66

77
import reactpy
8-
from reactpy.asgi.utils import find_available_port
98
from reactpy.testing import BackendFixture, DisplayFixture, poll
9+
from reactpy.testing.utils import find_available_port
1010
from tests.tooling.common import DEFAULT_TYPE_DELAY
1111
from tests.tooling.hooks import use_counter
1212

tests/test_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def HasScript():
4646
html.div({"id": "run-count", "data_value": 0}),
4747
html.script(
4848
{
49-
"src": f"/_reactpy/modules/{file_name_template.format(src_id=src_id)}"
49+
"src": f"/reactpy/modules/{file_name_template.format(src_id=src_id)}"
5050
}
5151
),
5252
)

tests/test_testing.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
from reactpy import Ref, component, html, testing
7-
from reactpy.asgi import starlette as starlette_implementation
87
from reactpy.logging import ROOT_LOGGER
98
from reactpy.testing.backend import _hotswap
109
from reactpy.testing.display import DisplayFixture
@@ -144,19 +143,6 @@ async def test_simple_display_fixture():
144143
await display.page.wait_for_selector("#sample")
145144

146145

147-
def test_if_app_is_given_implementation_must_be_too():
148-
with pytest.raises(
149-
ValueError,
150-
match=r"If an application instance its corresponding server implementation must be provided too",
151-
):
152-
testing.BackendFixture(app=starlette_implementation.create_development_app())
153-
154-
testing.BackendFixture(
155-
app=starlette_implementation.create_development_app(),
156-
implementation=starlette_implementation,
157-
)
158-
159-
160146
def test_list_logged_excptions():
161147
the_error = None
162148
with testing.capture_reactpy_logs() as records:

tests/test_web/test_module.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from pathlib import Path
22

33
import pytest
4-
from sanic import Sanic
4+
from servestatic import ServeStaticASGI
55

66
import reactpy
7-
from reactpy.asgi import sanic as sanic_implementation
7+
from reactpy.asgi.standalone import ReactPy
88
from reactpy.testing import (
99
BackendFixture,
1010
DisplayFixture,
@@ -50,27 +50,20 @@ def ShowCurrentComponent():
5050
await display.page.wait_for_selector("#unmount-flag", state="attached")
5151

5252

53-
@pytest.mark.flaky(reruns=3)
5453
async def test_module_from_url(browser):
55-
app = Sanic("test_module_from_url")
56-
57-
# instead of directing the URL to a CDN, we just point it to this static file
58-
app.static(
59-
"/simple-button.js",
60-
str(JS_FIXTURES_DIR / "simple-button.js"),
61-
content_type="text/javascript",
62-
)
63-
6454
SimpleButton = reactpy.web.export(
65-
reactpy.web.module_from_url("/simple-button.js", resolve_exports=False),
55+
reactpy.web.module_from_url("/static/simple-button.js", resolve_exports=False),
6656
"SimpleButton",
6757
)
6858

6959
@reactpy.component
7060
def ShowSimpleButton():
7161
return SimpleButton({"id": "my-button"})
7262

73-
async with BackendFixture(app=app, implementation=sanic_implementation) as server:
63+
app = ReactPy(ShowSimpleButton)
64+
app = ServeStaticASGI(app, JS_FIXTURES_DIR, "/static/")
65+
66+
async with BackendFixture(app) as server:
7467
async with DisplayFixture(server, browser) as display:
7568
await display.show(ShowSimpleButton)
7669

0 commit comments

Comments
 (0)