Files
iris/host/livereload_test.go
Hugo Nijhuis 89efc9b41d Add hot reload for development
Implement automatic rebuild and browser reload during development:

- File watcher monitors .go files for changes with configurable extensions
- Builder compiles Go source to WASM on file changes
- LiveReload WebSocket server notifies connected browsers to reload
- DevServer combines all components for easy development setup
- HTML injection adds reload script automatically

Usage:
  dev := host.NewDevServer("public", "index.html", ".", "public/app.wasm")
  dev.ListenAndServe(":8080")

Closes #9

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 16:34:16 +00:00

75 lines
1.6 KiB
Go

package host
import (
"testing"
)
func TestLiveReload_ClientCount(t *testing.T) {
lr := NewLiveReload()
if count := lr.ClientCount(); count != 0 {
t.Errorf("Expected 0 clients, got %d", count)
}
}
func TestMakeFrame_SmallPayload(t *testing.T) {
data := []byte("reload")
frame := makeFrame(1, data)
// First byte: FIN + opcode
if frame[0] != 0x81 {
t.Errorf("Expected first byte 0x81, got 0x%02x", frame[0])
}
// Second byte: length (no mask, small payload)
if frame[1] != byte(len(data)) {
t.Errorf("Expected length %d, got %d", len(data), frame[1])
}
// Payload
payload := frame[2:]
if string(payload) != string(data) {
t.Errorf("Expected payload %q, got %q", data, payload)
}
}
func TestMakeFrame_MediumPayload(t *testing.T) {
// Create payload between 126 and 65535 bytes
data := make([]byte, 200)
for i := range data {
data[i] = byte(i % 256)
}
frame := makeFrame(1, data)
// First byte: FIN + opcode
if frame[0] != 0x81 {
t.Errorf("Expected first byte 0x81, got 0x%02x", frame[0])
}
// Second byte: 126 indicates extended length
if frame[1] != 126 {
t.Errorf("Expected length indicator 126, got %d", frame[1])
}
// Extended length (2 bytes, big endian)
extLen := int(frame[2])<<8 | int(frame[3])
if extLen != len(data) {
t.Errorf("Expected extended length %d, got %d", len(data), extLen)
}
}
func TestMakeFrame_CloseFrame(t *testing.T) {
frame := makeFrame(8, nil)
// First byte: FIN + close opcode
if frame[0] != 0x88 {
t.Errorf("Expected first byte 0x88, got 0x%02x", frame[0])
}
// Second byte: 0 length
if frame[1] != 0 {
t.Errorf("Expected length 0, got %d", frame[1])
}
}