diff --git a/tests/test_app/components.py b/tests/test_app/components.py index 9500f01a..433bd9e4 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -1,6 +1,5 @@ import asyncio import inspect -from datetime import datetime from pathlib import Path from channels.db import database_sync_to_async @@ -25,23 +24,6 @@ from .types import TestObject -@component -def test_runner(): - start_time, _ = hooks.use_state(datetime.now()) - count, set_count = hooks.use_state(0) - seconds_elapsed = (datetime.now() - start_time).total_seconds() - - @hooks.use_effect - def run_tests(): - set_count(count + 1) - - return html.div( - {"id": "test-runner"}, - html.div(f"Total renders: {count}"), - html.div(f"Renders Per Second: {count / (seconds_elapsed or 0.01)}"), - ) - - @component def hello_world(): return html._(html.div({"id": "hello-world"}, "Hello World!")) diff --git a/tests/test_app/performance/__init__.py b/tests/test_app/performance/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_app/performance/components.py b/tests/test_app/performance/components.py new file mode 100644 index 00000000..9ee28afb --- /dev/null +++ b/tests/test_app/performance/components.py @@ -0,0 +1,23 @@ +from datetime import datetime + +from reactpy import component, hooks, html + + +@component +def renders_per_second(): + start_time, _ = hooks.use_state(datetime.now()) + count, set_count = hooks.use_state(0) + seconds_elapsed = (datetime.now() - start_time).total_seconds() + + @hooks.use_effect + def run_tests(): + set_count(count + 1) + + return html.div( + {"id": "test-runner"}, + html.div(f"Total renders: {count}"), + html.div( + {"class_name": "rps"}, + f"Renders Per Second: {count / (seconds_elapsed or 0.01)}", + ), + ) diff --git a/tests/test_app/performance/urls.py b/tests/test_app/performance/urls.py new file mode 100644 index 00000000..64ea8892 --- /dev/null +++ b/tests/test_app/performance/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from .views import renders_per_second + +urlpatterns = [ + path("rps/", renders_per_second), +] diff --git a/tests/test_app/performance/views.py b/tests/test_app/performance/views.py new file mode 100644 index 00000000..ff9ca6e5 --- /dev/null +++ b/tests/test_app/performance/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + + +def renders_per_second(request): + return render(request, "renders_per_second.html", {}) diff --git a/tests/test_app/templates/base.html b/tests/test_app/templates/base.html index 4da6dd78..10eaac27 100644 --- a/tests/test_app/templates/base.html +++ b/tests/test_app/templates/base.html @@ -19,7 +19,76 @@

ReactPy Test Page


- {% component "test_app.components.test_runner" %} + {% component "test_app.components.hello_world" class="hello-world" %} +
+ {% component "test_app.components.button" class="button" %} +
+ {% component "test_app.components.parameterized_component" class="parametarized-component" x=123 y=456 %} +
+ {% component "test_app.components.object_in_templatetag" my_object %} +
+ {% component "test_app.components.simple_button" %} +
+ {% component "test_app.components.use_connection" %} +
+ {% component "test_app.components.use_scope" %} +
+ {% component "test_app.components.use_location" %} +
+ {% component "test_app.components.use_origin" %} +
+ {% component "test_app.components.django_css" %} +
+ {% component "test_app.components.django_js" %} +
+ {% component "test_app.components.unauthorized_user" %} +
+ {% component "test_app.components.authorized_user" %} +
+ {% component "test_app.components.relational_query" %} +
+ {% component "test_app.components.async_relational_query" %} +
+ {% component "test_app.components.todo_list" %} +
+ {% component "test_app.components.async_todo_list" %} +
+ {% component "test_app.components.view_to_component_sync_func" %} +
+ {% component "test_app.components.view_to_component_async_func" %} +
+ {% component "test_app.components.view_to_component_sync_class" %} +
+ {% component "test_app.components.view_to_component_async_class" %} +
+ {% component "test_app.components.view_to_component_template_view_class" %} +
+ {% component "test_app.components.view_to_component_script" %} +
+ {% component "test_app.components.view_to_component_request" %} +
+ {% component "test_app.components.view_to_component_args" %} +
+ {% component "test_app.components.view_to_component_kwargs" %} +
+ {% component "test_app.components.view_to_component_sync_func_compatibility" %} +
+ {% component "test_app.components.view_to_component_async_func_compatibility" %} +
+ {% component "test_app.components.view_to_component_sync_class_compatibility" %} +
+ {% component "test_app.components.view_to_component_async_class_compatibility" %} +
+ {% component "test_app.components.view_to_component_template_view_class_compatibility" %} +
+ {% component "test_app.components.view_to_component_decorator" %} +
+ {% component "test_app.components.view_to_component_decorator_args" %} +
+
{% component "test_app.components.does_not_exist" %}
+
+
{% component "test_app.components.hello_world" invalid_param="random_value" %}
+
diff --git a/tests/test_app/templates/renders_per_second.html b/tests/test_app/templates/renders_per_second.html new file mode 100644 index 00000000..65fea49b --- /dev/null +++ b/tests/test_app/templates/renders_per_second.html @@ -0,0 +1,25 @@ +{% load static %} {% load reactpy %} + + + + + + + + + ReactPy + + + + +

ReactPy Renders Per Second Test Page

+
+ {% component "test_app.performance.components.renders_per_second" %} + + + diff --git a/tests/test_app/urls.py b/tests/test_app/urls.py index 145a8a20..611f1be4 100644 --- a/tests/test_app/urls.py +++ b/tests/test_app/urls.py @@ -31,6 +31,7 @@ class AccessUser: urlpatterns = [ path("", base_template), + path("performance/", include("test_app.performance.urls")), path("reactpy/", include("reactpy_django.http.urls")), path("admin/", admin.site.urls), ]