Skip to content

Commit bf49c88

Browse files
authored
fix test lifespan on prod (#6027)
* fix test lifespan on prod * add the fix
1 parent f693de0 commit bf49c88

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

reflex/compiler/templates.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,6 @@ def vite_config_template(
581581
enableNativePlugin: false,
582582
hmr: {"true" if experimental_hmr else "false"},
583583
}},
584-
legacy: {{
585-
inconsistentCjsInterop: true,
586-
}},
587584
server: {{
588585
port: process.env.PORT,
589586
hmr: {"true" if hmr else "false"},

reflex/components/component.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,9 +2263,9 @@ def _get_dynamic_imports(self) -> str:
22632263
library_import = f"import('{import_name}')"
22642264
mod_import = (
22652265
# https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#with-named-exports
2266-
f".then((mod) => ({{default: mod.{self.tag}}}))"
2266+
f".then((mod) => mod.{self.tag})"
22672267
if not self.is_default
2268-
else ""
2268+
else ".then((mod) => mod.default)"
22692269
)
22702270
return (
22712271
f"const {self.alias or self.tag} = ClientSide(lazy(() => "

reflex/testing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from typing import TYPE_CHECKING, Any, Literal, TypeVar
2727

2828
import uvicorn
29+
from typing_extensions import Self
2930

3031
import reflex
3132
import reflex.reflex
@@ -131,7 +132,7 @@ def create(
131132
Callable[[], None] | types.ModuleType | str | functools.partial[Any] | None
132133
) = None,
133134
app_name: str | None = None,
134-
) -> AppHarness:
135+
) -> Self:
135136
"""Create an AppHarness instance at root.
136137
137138
Args:
@@ -453,7 +454,7 @@ def consume_frontend_output():
453454
self.frontend_output_thread = threading.Thread(target=consume_frontend_output)
454455
self.frontend_output_thread.start()
455456

456-
def start(self) -> AppHarness:
457+
def start(self) -> Self:
457458
"""Start the backend in a new thread and dev frontend as a separate process.
458459
459460
Returns:
@@ -482,7 +483,7 @@ def get_app_global_source(key: str, value: Any):
482483
return f"{key} = {value!r}"
483484
return inspect.getsource(value)
484485

485-
def __enter__(self) -> AppHarness:
486+
def __enter__(self) -> Self:
486487
"""Contextmanager protocol for `start()`.
487488
488489
Returns:

tests/integration/test_lifespan.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def index():
9999

100100

101101
@pytest.fixture(
102-
params=[False, True], ids=["no_api_transformer", "mount_api_transformer"]
102+
scope="session",
103+
params=[False, True],
104+
ids=["no_api_transformer", "mount_api_transformer"],
103105
)
104106
def mount_api_transformer(request: pytest.FixtureRequest) -> bool:
105107
"""Whether to use api_transformer in the app.
@@ -113,7 +115,9 @@ def mount_api_transformer(request: pytest.FixtureRequest) -> bool:
113115
return request.param
114116

115117

116-
@pytest.fixture(params=[False, True], ids=["no_fastapi", "mount_cached_fastapi"])
118+
@pytest.fixture(
119+
scope="session", params=[False, True], ids=["no_fastapi", "mount_cached_fastapi"]
120+
)
117121
def mount_cached_fastapi(request: pytest.FixtureRequest) -> bool:
118122
"""Whether to use cached FastAPI in the app (app.api).
119123
@@ -126,22 +130,26 @@ def mount_cached_fastapi(request: pytest.FixtureRequest) -> bool:
126130
return request.param
127131

128132

129-
@pytest.fixture
133+
@pytest.fixture(scope="session")
130134
def lifespan_app(
131-
tmp_path, mount_api_transformer: bool, mount_cached_fastapi: bool
135+
tmp_path_factory: pytest.TempPathFactory,
136+
app_harness_env: type[AppHarness],
137+
mount_api_transformer: bool,
138+
mount_cached_fastapi: bool,
132139
) -> Generator[AppHarness, None, None]:
133140
"""Start LifespanApp app at tmp_path via AppHarness.
134141
135142
Args:
136-
tmp_path: pytest tmp_path fixture
143+
tmp_path_factory: pytest tmp_path_factory fixture
144+
app_harness_env: AppHarness environment
137145
mount_api_transformer: Whether to mount the API transformer.
138146
mount_cached_fastapi: Whether to mount the cached FastAPI app.
139147
140148
Yields:
141149
running AppHarness instance
142150
"""
143-
with AppHarness.create(
144-
root=tmp_path,
151+
with app_harness_env.create(
152+
root=tmp_path_factory.mktemp("lifespan_app"),
145153
app_source=functools.partial(
146154
LifespanApp,
147155
mount_cached_fastapi=mount_cached_fastapi,

0 commit comments

Comments
 (0)