summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_hook_ordering.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/tests/test_hook_ordering.py')
-rw-r--r--packages/meshbay-hub/tests/test_hook_ordering.py41
1 files changed, 31 insertions, 10 deletions
diff --git a/packages/meshbay-hub/tests/test_hook_ordering.py b/packages/meshbay-hub/tests/test_hook_ordering.py
index cd9a11e..dac1357 100644
--- a/packages/meshbay-hub/tests/test_hook_ordering.py
+++ b/packages/meshbay-hub/tests/test_hook_ordering.py
@@ -26,6 +26,17 @@ import pytest
STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"
APP = STATIC / "app.js"
+# One monolithic app.js used to hold every component; the group-page refactor
+# split it into one file per "application" (chat-app.js, files-app.js,
+# video-player.js, group-settings.js) plus the group shell (group-page.js).
+# A future Videos/Music/Photos app lands in its own file the same way — add it
+# here so this test keeps seeing it, since `_all_components` below only walks
+# the files named in this list.
+STATIC_FILES = [
+ "app.js", "group-page.js", "chat-app.js", "files-app.js",
+ "video-player.js", "group-settings.js",
+]
+
pytestmark = pytest.mark.skipif(not APP.exists(), reason="SPA sources unavailable")
# `const NAME = useCallback(` / `useMemo(` — the declarations that both define a
@@ -40,18 +51,28 @@ def app():
return APP.read_text()
-def _components(app: str):
- """Each top-level component, with the offset it starts at."""
- for m in re.finditer(r"^function ([A-Z]\w*)\(", app, re.M):
+def _components(src: str):
+ """Each top-level component in one file, with the offset it starts at."""
+ for m in re.finditer(r"^function ([A-Z]\w*)\(", src, re.M):
start = m.start()
- nxt = app.find("\nfunction ", start + 1)
- yield m.group(1), app[start:nxt if nxt > 0 else len(app)]
+ nxt = src.find("\nfunction ", start + 1)
+ yield m.group(1), src[start:nxt if nxt > 0 else len(src)]
+
+
+def _all_components():
+ """Every top-level component across every static file that can hold one."""
+ for name in STATIC_FILES:
+ path = STATIC / name
+ if not path.exists():
+ continue
+ for cname, body in _components(path.read_text()):
+ yield f"{name}:{cname}", body
-def test_no_hook_depends_on_something_declared_below_it(app):
- """The whole file, not just the player that was broken by it."""
+def test_no_hook_depends_on_something_declared_below_it():
+ """Every static file that can hold a component, not just app.js."""
problems = []
- for name, body in _components(app):
+ for name, body in _all_components():
# Where each hook binding becomes usable.
declared_at = {m.group(1): m.start() for m in DECL.finditer(body)}
for deps in DEPS.finditer(body):
@@ -68,13 +89,13 @@ def test_no_hook_depends_on_something_declared_below_it(app):
+ "\n ".join(problems))
-def test_the_check_would_notice(app):
+def test_the_check_would_notice():
"""A test that cannot fail proves nothing — so make it fail on purpose.
Swaps two declarations in the real file and confirms the rule fires. If
this stops working the rule above has quietly become decoration.
"""
- body = next(b for n, b in _components(app) if n == "VideoPlayer")
+ body = next(b for n, b in _all_components() if n == "video-player.js:VideoPlayer")
decls = list(DECL.finditer(body))
assert len(decls) >= 2, "VideoPlayer has too few hooks to test the check"