Skip to content

Commit 29affcc

Browse files
committed
fix tests
1 parent de8e165 commit 29affcc

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

docs/source/_custom_js/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/about/changelog.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ Unreleased
2929
implementation specific and are now available as top-level imports. Instead of each
3030
backend defining these hooks, backends establish a ``ConnectionContext`` with this
3131
information.
32+
- :pull:`824` - IDOM's built-in backend server now expose the following routes:
33+
34+
- ``/_idom/assets/<file-path>``
35+
- ``/_idom/stream/<path>``
36+
- ``/_idom/modules/<file-path>``
37+
- ``/<prefix>/<path>``
38+
39+
This should allow the browser to cache static resources. Even if your ``url_prefix``
40+
is ``/_idom``, your app should still work as expected. Though if you're using
41+
``idom-router``, IDOM's server routes will always take priority.
3242

3343
**Added**
3444

src/idom/testing/display.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from contextlib import AsyncExitStack
44
from types import TracebackType
55
from typing import Any
6+
from urllib.parse import urljoin
67

78
from playwright.async_api import (
89
Browser,
@@ -27,6 +28,7 @@ def __init__(
2728
self,
2829
backend: BackendFixture | None = None,
2930
driver: Browser | BrowserContext | Page | None = None,
31+
url_prefix: str = "",
3032
) -> None:
3133
if backend is not None:
3234
self.backend = backend
@@ -35,6 +37,7 @@ def __init__(
3537
self.page = driver
3638
else:
3739
self._browser = driver
40+
self.url_prefix = url_prefix
3841

3942
async def show(
4043
self,
@@ -44,8 +47,14 @@ async def show(
4447
await self.goto("/")
4548
await self.root_element() # check that root element is attached
4649

47-
async def goto(self, path: str, query: Any | None = None) -> None:
48-
await self.page.goto(self.backend.url(path, query))
50+
async def goto(
51+
self, path: str, query: Any | None = None, add_url_prefix: bool = True
52+
) -> None:
53+
await self.page.goto(
54+
self.backend.url(
55+
f"{self.url_prefix}{path}" if add_url_prefix else path, query
56+
)
57+
)
4958

5059
async def root_element(self) -> ElementHandle:
5160
element = await self.page.wait_for_selector("#app", state="attached")

tests/test_backend/test_common.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dataclasses import dataclass
1+
from dataclasses import dataclass, replace
22
from typing import MutableMapping
33

44
import pytest
@@ -19,12 +19,21 @@
1919
)
2020
async def display(page, request):
2121
imp: BackendImplementation = request.param
22-
async with BackendFixture(
23-
implementation=imp,
24-
# we do this to check that route priorities for each backend are correct
25-
options=imp.Options(url_prefix=str(PATH_PREFIX)),
26-
) as server:
27-
async with DisplayFixture(backend=server, driver=page) as display:
22+
23+
# we do this to check that route priorities for each backend are correct
24+
if imp is default_implementation:
25+
url_prefix = ""
26+
opts = None
27+
else:
28+
url_prefix = str(PATH_PREFIX)
29+
opts = imp.Options(url_prefix=url_prefix)
30+
31+
async with BackendFixture(implementation=imp, options=opts) as server:
32+
async with DisplayFixture(
33+
backend=server,
34+
driver=page,
35+
url_prefix=url_prefix,
36+
) as display:
2837
yield display
2938

3039

@@ -114,7 +123,7 @@ def ShowRoute():
114123

115124
await display.show(ShowRoute)
116125

117-
await poll_location.until_equals(Location("/", ""))
126+
await poll_location.until_equals(Location(display.url_prefix or "/", ""))
118127

119128
for loc in [
120129
Location("/something"),
@@ -124,7 +133,8 @@ def ShowRoute():
124133
Location("/another/something/file.txt", "?key=value"),
125134
Location("/another/something/file.txt", "?key1=value1&key2=value2"),
126135
]:
127-
await display.goto(loc.pathname + loc.search)
136+
loc = replace(loc, pathname=f"{display.url_prefix}{loc.pathname}")
137+
await display.goto(loc.pathname + loc.search, add_url_prefix=False)
128138
await poll_location.until_equals(loc)
129139

130140

0 commit comments

Comments
 (0)