Files
webterm/tests/test_local_server.py
T
GitHub Copilot 3f6cfd4e96 Replace xterm.js with ghostty-web
Migrate from xterm.js to ghostty-web (Ghostty WASM terminal emulator).

Benefits:
- WASM-compiled parser from Ghostty (same code as native app)
- Better Unicode/complex script handling
- Simpler initialization (no viewport.scrollBarWidth issues)
- ~400KB WASM bundle

Changes:
- Update package.json: remove @xterm/* deps, add ghostty-web
- Rewrite terminal.ts using ghostty-web API
- Use built-in FitAddon with observeResize()
- Remove WebGL/Canvas/Unicode11/WebLinks/Clipboard addons
- Remove xterm.css (ghostty uses canvas renderer)
- Add ghostty-vt.wasm to static assets
- Update HTML template and tests

BREAKING: Major version bump to 0.4.0
2026-01-28 00:54:50 +00:00

82 lines
2.6 KiB
Python

"""Tests for LocalServer."""
from __future__ import annotations
from textual_webterm.config import App, Config
from textual_webterm.local_server import WEBTERM_STATIC_PATH, LocalServer
class TestLocalServer:
"""Tests for LocalServer."""
def test_static_path_exists(self) -> None:
"""Test that static path exists."""
assert WEBTERM_STATIC_PATH is not None
assert WEBTERM_STATIC_PATH.exists()
def test_static_path_has_required_files(self) -> None:
"""Test that static path contains required assets."""
assert WEBTERM_STATIC_PATH is not None
assert (WEBTERM_STATIC_PATH / "js" / "terminal.js").exists()
assert (WEBTERM_STATIC_PATH / "js" / "ghostty-vt.wasm").exists()
def test_create_server(self, tmp_path) -> None:
"""Test creating a LocalServer instance."""
app = App(name="Test", slug="test", terminal=True, command="echo test")
config = Config(apps=[app])
server = LocalServer(
str(tmp_path),
config,
host="127.0.0.1",
port=8080,
)
assert server.host == "127.0.0.1"
assert server.port == 8080
assert server.app_count == 1
def test_add_app(self, tmp_path) -> None:
"""Test adding an app to the server."""
config = Config(apps=[])
server = LocalServer(str(tmp_path), config, host="127.0.0.1", port=8080)
assert server.app_count == 0
server.add_app("New App", "echo hello", slug="new-app")
assert server.app_count == 1
class TestWebSocketProtocol:
"""Tests for WebSocket protocol handling."""
def test_stdin_message_format(self) -> None:
"""Test that stdin messages use correct format."""
import json
msg = json.dumps(["stdin", "hello"])
parsed = json.loads(msg)
assert parsed[0] == "stdin"
assert parsed[1] == "hello"
def test_resize_message_format(self) -> None:
"""Test that resize messages use correct format."""
import json
msg = json.dumps(["resize", {"width": 80, "height": 24}])
parsed = json.loads(msg)
assert parsed[0] == "resize"
assert parsed[1]["width"] == 80
assert parsed[1]["height"] == 24
def test_ping_pong_format(self) -> None:
"""Test ping/pong message format."""
import json
ping = json.dumps(["ping", "12345"])
parsed = json.loads(ping)
assert parsed[0] == "ping"
pong = json.dumps(["pong", "12345"])
parsed = json.loads(pong)
assert parsed[0] == "pong"