hlive-testing
/hlive-testing
Write browser tests for HLive pages using the hlivetest package (github.com/SamHennessy/hlive/hlivetest) and Playwright. Use when testing HLive UI behavior end-to-end — spinning up a test server, driving a real browser (Click/ClickAndWait, TextContent, GetAttribute), and asserting with hlivetest.Diff. Use when an HLive task mentions tests, Playwright, or verifying interactive behavior.
- Author
- SamHennessy ↗
- Repository
- hlive ↗
- Licence
- MIT
- Last repository change
- 02.07.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 02.07.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Write browser tests for HLive pages using the hlivetest package (github.com/SamHennessy/hlive/hlivetest) and Playwright. Use when testing HLive UI behavior end-to-end — spinning up a test server, driving a real browser (Click/ClickAndWait, TextContent, GetAttribute), and asserting with hlivetest.Diff. Use when an HLive task mentions tests, Playwright, or verifying interactive behavior.
Original author description
Write browser tests for HLive pages using the hlivetest package (github.com/SamHennessy/hlive/hlivetest) and Playwright. Use when testing HLive UI behavior end-to-end — spinning up a test server, driving a real browser (Click/ClickAndWait, TextContent, GetAttribute), and asserting with hlivetest.Diff. Use when an HLive task mentions tests, Playwright, or verifying interactive behavior.
How it works
- Setup
- The harness pattern
- Writing a test
- hlivetest helpers
- Running
- Reference
SKILL.md preview
---
name: hlive-testing
description: >-
Write browser tests for HLive pages using the hlivetest package
(github.com/SamHennessy/hlive/hlivetest) and Playwright. Use when testing
HLive UI behavior end-to-end — spinning up a test server, driving a real
browser (Click/ClickAndWait, TextContent, GetAttribute), and asserting with
hlivetest.Diff. Use when an HLive task mentions tests, Playwright, or
verifying interactive behavior.
---
# HLive Testing
HLive's behavior lives in the browser round-trip, so it's tested by driving a
real browser with Playwright via the `hlivetest` package. Tests boot an HLive
server, open a browser page against it, interact, and assert on the resulting
DOM.
## Setup
Tests need Playwright browsers installed:
```shell
make install-test
# or: go run github.com/playwright-community/playwright-go/cmd/playwright install --with-deps
```
Because these are heavy browser tests, guard them so `go test -short` skips them
(the harness below does this).
## The harness pattern
HLive's own suite (`hlivetest/pages/`) uses a small per-package harness. Copy it
into your test package:
```go
package pages_test
import (
"testing"
l "github.com/SamHennessy/hlive"
"github.com/SamHennessy/hlive/hlivetest"
"github.com/playwright-community/playwright-go"
)
type harness struct {
server *hlivetest.Server
pwpage playwright.Page
teardown func()
}
func setup(t *testing.T, pageFn func() *l.Page) harness {
t.Helper()
if testing.Short() {
t.Skip("skipping test in short mode.")
}
h := harness{
server: hlivetest.NewServer(pageFn),
pwpage: hlivetest.NewBrowserPage(),
}
h.teardown = func() {
if err := h.pwpage.Close(); err != nil {
t.Error(err)
}
}
if _, err := h.pwpage.Goto(h.server.HTTPServer.URL); err != nil {
t.Fatal("goto page:", err)
}
return h
}
```
`NewServer` takes a page **factory** (`func() *l.Page`) — the same kind of
function you hand to `l.NewPageServer`. In a structured app (see the
**hlive-project** skill) that's an exported factory from your `page` package, so
a test imports it and passes it straight in: `setup(t, page.Home)`.
Give the elements you select stable ids. With hhtml use the `Id(...)` attribute:
```go
import (
l "github.com/SamHennessy/hlive"
. "github.com/SamHennessy/hlive/hhtml"
)
func Counter() *l.Page {
count := l.Box(0)
page := l.NewPage()
page.DOM().Body().Add(
Button(Id("btn"), l.On("click", func(_ context.Context, _ l.Event) {
count.Lock(func(v int) int { return v + 1 })
}), "+"),
Div(Id("count"), count),
)
return page
}
```
## Writing a test
```go
func TestClick_OneClick(t *testing.T) {
t.Parallel()
h := setup(t, pages.Click()) // pages.Click() returns the page factory
defer h.teardown()
hlivetest.Diff(t, "0", hlivetest.TextContent(t, h.pwpage, "#count"))
hlivetest.ClickAndWait(t, h.pwpage, "#btn") // click, then wait for the diff
hlivetest.Diff(t, "1", hlivetest.TextContent(t, h.pwpage, "#count"))
}
```
Use `ClickAndWait` before an assertion (it waits for HLive's diff to apply). Use
plain `Click` for intermediate clicks where you'll assert only at the end:
```go
for i := 0; i < 9; i++ {
hlivetest.Click(t, h.pwpage, "#btn")
}
hlivetest.ClickAndWait(t, h.pwpage, "#btn")
hlivetest.Diff(t, "10", hlivetest.TextContent(t, h.pwpage, "#count"))
```
## hlivetest helpers
All take `(t, pwpage, ...)` unless noted:
- `Click(selector)` — click without waiting for the diff.
- `ClickAndWait(selector)` — click, then block until the diff is applied.
- `TextContent(selector) string` — element text.
- `GetAttribute(selector, attribute) string` — an attribute value.
- `GetID(selector) string` — the element's HLive id.
- `Title(pwpage) string` — page title.
- `Diff(want, got any)` — assert equal, reporting a diff on failure (`t.Error`).
- `DiffFatal(want, got any)` — same but `t.Fatal`.
- `FatalOnErr(err)` — fail fast on an error.
- `NewServer(pageFn) *Server` / `NewBrowserPage() playwright.Page` — fixtures.
For interactions hlivetest doesn't wrap (typing, hover, selects), use the
`playwright.Page` directly (`h.pwpage.Fill(...)`, `.Hover(...)`), then assert with
`hlivetest.Diff`.
## Running
```shell
go test ./... # full run (needs browsers)
go test -short ./... # skips the browser tests
```
## Reference
`hlivetest/hlivetest.go`, `hlivetest/server.go`, `hlivetest/browser.go`, and the
examples `hlivetest/pages/harness_test.go`, `hlivetest/pages/click_test.go`,
`hlivetest/pages/click.go`. Larger suites live under `systemtests/`.
Versions
The database has no other skills named hlive-testing.
Database snapshot: 13.11.2026 · package version cda327b4a5d0 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100hlive-core
Build UIs with HLive, the server-side virtual-DOM framework for Go (github.com/SamHennessy/hlive). Use when working with HLive code — the `l "github.com/SamHennessy/hlive"` import, builders like l.T / l.C / l.CM, NewPage / NewPageServer, On(...) event bindings, l.Box reactive… - 95hlive-hhtml
Build HLive page markup with the hhtml package (github.com/SamHennessy/hlive/hhtml) — typed, autocompleting Go builders for HTML5 tags and attributes (Div, Button, A, Input, Class, Href, ...). Use when writing or editing HLive page/component markup, when you see the `.… - 95playwright-test
Creates Playwright browser-based end-to-end tests for Next.js pages covering complete user journeys from start to finish. Use when the user asks to "write Playwright tests", "create e2e tests", "write integration tests", "test in the browser", or mentions end-to-end testing,… - 100playwright-testing
UI/E2E test automation with Playwright MCP. Use when the user asks to "test the UI", "automate browser tests", "check the page", "take a screenshot", "run Playwright", "write E2E tests", or anything about browser-based testing. - 95memstack-development-webapp-testing
Use when the user says 'write browser tests', 'test this page', 'playwright test', 'e2e test', 'end to end test', 'browser test', 'test the UI', or needs Playwright-based browser testing for a web application. Do NOT use for unit tests, API tests, or non-browser testing. - 100v1-e2e-testing
Use when implementing or debugging browser end-to-end tests, especially Playwright or flaky tests. Triggers on "E2E test", "Playwright", or "flaky browser test".