Documentation
¶
Overview ¶
Package flatest is a deterministic, synchronous test harness for flat apps: it drives an App through scripted events and controlled time, exercising real async folds without goroutine races, real clocks, or a terminal.
Index ¶
- func AssertFrames(t *testing.T, path string, frames []flatte.Frame)
- func AssertGolden(t *testing.T, path string, frame string)
- func AssertGoldenFrame(t *testing.T, path string, frame flatte.Frame)
- func CleanFrame(frame string) string
- func Frames[S any](d *Driver[S], steps ...func(*Driver[S])) []flatte.Frame
- func RenderFrame(frame flatte.Frame) string
- type Driver
- type Recorder
- type Step
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFrames ¶
AssertFrames compares a frame sequence against a golden: each frame RenderFrame'd, joined by a separator line, so an interaction can be regression-tested as an ordered series of frames.
func AssertGoldenFrame ¶
AssertGoldenFrame compares a Frame against a golden: cleaned content, then metadata footer lines — only when metadata is set, so frames without cursor or title keep their existing goldens byte-identical.
func CleanFrame ¶
func Frames ¶
Frames runs the driver through a sequence of steps and returns the frame after each, for sequence goldens (see AssertFrames).
func RenderFrame ¶
RenderFrame serializes a frame for golden comparison.
Types ¶
type Driver ¶
type Driver[S any] struct { // contains filtered or unexported fields }
Driver runs a flatte.App synchronously for tests. App-triggered async (Go/Latest/Stream) is deferred to a pending queue and only runs on Settle; time-based effects (Every) are driven by a fake clock advanced with Advance. The width is fixed so frames are deterministic.
func Start ¶
Start builds a Driver, runs Init, delivers the initial ResizeEvent, and renders the first frame.
func (*Driver[S]) Advance ¶
Advance moves the fake clock, firing due Every ticks (which queue updates), then settles any async those ticks triggered.
func (*Driver[S]) Close ¶
func (d *Driver[S]) Close()
Close calls the app's OnExit hook, mirroring what Run does on loop exit. Call it at the end of a test to verify state-save callbacks.
func (*Driver[S]) Send ¶
Send delivers one event, drains the synchronous updates it produced, and returns the rendered frame. Async results triggered by the event are NOT applied here — call Settle.
func (*Driver[S]) Settle ¶
Settle runs every pending async body (to fixpoint — a body may dispatch more) and drains the updates each produces, then renders. This is where Go/Latest/Stream results land, under test control. drain runs after each body so Latest's apply-time guard sees a superseded ctx and drops the stale result.
type Recorder ¶
type Recorder struct {
Steps []Step
}
Recorder is a flatte.Tracer that captures the ordered event/update stream of a session for replay assertions. Use it as App.Tracer.
func Replay ¶
Replay re-drives the recorded EVENTS through a fresh Driver — settling after each so any async those events trigger lands — and returns the new recording. A test asserts the two update-name streams match: a regression lock on event→update determinism.
Limitations (honest): updates are closures and are not serialized, so only their names are compared. Settle/Advance cadence is NOT captured, so a session that batches several events before settling (e.g. a Latest supersede) will not reproduce identically under per-event settling — drive those with the Driver directly. ResizeEvents are skipped: the fresh Driver delivers its own initial resize at the fixed width.