aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_spa_imports.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-25 10:47:37 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-25 10:47:37 +0200
commit0bdce359c0bf19fa98f1b7f9975be32704abe1f0 (patch)
treec67c24b9751c3d8063fc9806a5d6650a3b8c03fb /packages/meshbay-hub/tests/test_spa_imports.py
parent950f4aa6d107e127fb6dc0579beedbff0e6f1af5 (diff)
downloadmeshbay-0bdce359c0bf19fa98f1b7f9975be32704abe1f0.tar.gz
feat(client): fetch the media apps, the player, settings and search on first use
apps.js registers Videos, Music, Photos and every settings pane through lazy.js; the group page does the same for the video player and the settings panel, and the shell for the search page. The first download goes from 49 modules / 386 KB gzip to 37 / 289 KB; opening Music now fetches music-app.js and media-tiles.js and nothing of Videos. test_first_load_is_lean holds the eager graph; test_spa_imports checks that every on-demand load names an export that exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/tests/test_spa_imports.py')
-rw-r--r--packages/meshbay-hub/tests/test_spa_imports.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/packages/meshbay-hub/tests/test_spa_imports.py b/packages/meshbay-hub/tests/test_spa_imports.py
index 230f33f..8be70cb 100644
--- a/packages/meshbay-hub/tests/test_spa_imports.py
+++ b/packages/meshbay-hub/tests/test_spa_imports.py
@@ -79,9 +79,36 @@ def test_the_check_can_see_a_real_module():
finding imports would make the test above pass over an empty set, which
looks exactly like success.
"""
- source = (STATIC / "apps.js").read_text(encoding="utf-8")
+ source = (STATIC / "group-page.js").read_text(encoding="utf-8")
found = IMPORT.findall(source)
assert len(found) >= 5, (
- "the import pattern no longer matches apps.js — this test is then "
+ "the import pattern no longer matches group-page.js — this test is then "
"checking nothing")
- assert "configurableApps" in _exported(source)
+ assert "GroupPage" in _exported(source)
+
+
+# `lazy(() => import('./x.js'), 'Name')` (lazy.js), and the hand-written form
+# `import('./x.js').then(m => { _Page = m.Name; ...`.
+LAZY = re.compile(r"lazy\(\s*\(\)\s*=>\s*import\('\./([^']+)'\),\s*'(\w+)'")
+THEN = re.compile(r"import\('\./([^']+)'\)\.then\(\s*m\s*=>\s*\{\s*\w+\s*=\s*m\.(\w+)")
+
+
+def test_every_module_loaded_on_demand_exports_what_is_asked_for():
+ """
+ The same fault as above, one step later: a component fetched on demand
+ under a name its module does not export renders a spinner that never
+ ends — no error, since the fetch itself succeeded.
+ """
+ problems, seen = [], 0
+ for path in sorted(STATIC.glob("*.js")):
+ source = path.read_text(encoding="utf-8")
+ for spec, name in LAZY.findall(source) + THEN.findall(source):
+ seen += 1
+ target = STATIC / spec
+ if not target.exists():
+ problems.append(f"{path.name}: loads ./{spec} — no such file")
+ elif name not in _exported(target.read_text(encoding="utf-8")):
+ problems.append(f"{path.name}: loads {{{name}}} from ./{spec}, "
+ f"which does not export it")
+ assert seen >= 15, f"only {seen} on-demand loads found — is the pattern stale?"
+ assert not problems, "unresolved on-demand loads:\n" + "\n".join(problems)