aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/spa_source.py
blob: cfeae60a2436bd7ec7f6c08ae895631636715268 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
The web client's source, for the hub tests that read it as text.

A test that lifts a function out of a file by name stops finding it the day
the function moves to another file — or, for an absence, goes on passing
without looking at it. So the tests that read the search code take it from
here, the page and whatever it has been split into.
"""

import re
from pathlib import Path

STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"


def search_files() -> list[Path]:
    """The search page, and the connection pool once it is a module of its own."""
    return [p for p in (STATIC / "search-page.js", STATIC / "connection-pool.js")
            if p.exists()]


def search_source() -> str:
    return "\n".join(p.read_text(encoding="utf-8") for p in search_files())


def search_argv() -> str:
    """The same files, as the one argument the Node harnesses take."""
    import os
    return os.pathsep.join(str(p) for p in search_files())


# ── The transport: transport.js and the classic scripts split out of it ──────

WEBAPP = STATIC.parent / "api" / "webapp.py"
CLASSIC_TAG = re.compile(r'<script src="/a/\{v\}/([^"]+)"></script>')


def classic_scripts() -> list[str]:
    """The classic (non-module) scripts of the hub's shell, in load order."""
    return CLASSIC_TAG.findall(WEBAPP.read_text(encoding="utf-8"))


def transport_files() -> list[Path]:
    """Every file of the transport, in the order the shell loads them: the
    classic scripts named `transport*.js`. Derived from the shell, so a part
    added there is read here without anybody having to list it."""
    files = [STATIC / n for n in classic_scripts() if n.startswith("transport")]
    assert files and files[0].name.startswith("transport"), files
    return files


def transport_source() -> str:
    return "\n".join(p.read_text(encoding="utf-8") for p in transport_files())


def transport_argv() -> str:
    """The same files, as the one argument the Node harnesses take."""
    import os
    return os.pathsep.join(str(p) for p in transport_files())