Documentation
¶
Overview ¶
Package steep provides test helpers for tea.Program and models (root and component).
Use NewHarness to run a root tea.Model in a test:
h := steep.NewHarness(t, model, steep.WithWindowSize(80, 24))
h.Type("hello").WaitSettle().AssertString("hello")
h.QuitProgram()
h.WaitFinished()
Use NewComponentHarness for components that expose View() string and an Update method through the asynchronous tea.Program runtime.
Index ¶
- Constants
- func AssertDimensions(tb testing.TB, view Viewable, width, height int, opts ...Option) bool
- func AssertHasMessage[T uv.Event](tb testing.TB, log MessageCollector, opts ...Option) bool
- func AssertHeight(tb testing.TB, view Viewable, n int, opts ...Option) bool
- func AssertMatch(tb testing.TB, view Viewable, pattern string, opts ...Option) bool
- func AssertNotMatch(tb testing.TB, view Viewable, pattern string, opts ...Option) bool
- func AssertNotString(tb testing.TB, view Viewable, content string, opts ...Option) bool
- func AssertNotStrings(tb testing.TB, view Viewable, contents []string, opts ...Option) bool
- func AssertString(tb testing.TB, view Viewable, content string, opts ...Option) bool
- func AssertStrings(tb testing.TB, view Viewable, contents []string, opts ...Option) bool
- func AssertWidth(tb testing.TB, view Viewable, n int, opts ...Option) bool
- func Dimensions(out string, opts ...Option) (w, h int)
- func FilterMessagesFunc[T uv.Event](tb testing.TB, messages iter.Seq[uv.Event], fn func(T) bool) iter.Seq[T]
- func FilterMessagesType[T uv.Event](tb testing.TB, messages iter.Seq[uv.Event]) iter.Seq[T]
- func IgnoreMessagesReflect(tb testing.TB, messages iter.Seq[uv.Event], ignore ...reflect.Type) iter.Seq[uv.Event]
- func RequireDimensions(tb testing.TB, view Viewable, width, height int, opts ...Option)
- func RequireHasMessage[T uv.Event](tb testing.TB, log MessageCollector, opts ...Option)
- func RequireHeight(tb testing.TB, view Viewable, n int, opts ...Option)
- func RequireMatch(tb testing.TB, view Viewable, pattern string, opts ...Option)
- func RequireNotMatch(tb testing.TB, view Viewable, pattern string, opts ...Option)
- func RequireNotString(tb testing.TB, view Viewable, content string, opts ...Option)
- func RequireNotStrings(tb testing.TB, view Viewable, contents []string, opts ...Option)
- func RequireString(tb testing.TB, view Viewable, content string, opts ...Option)
- func RequireStrings(tb testing.TB, view Viewable, contents []string, opts ...Option)
- func RequireWidth(tb testing.TB, view Viewable, n int, opts ...Option)
- func WaitBytes(tb testing.TB, model Viewable, contents []byte, opts ...Option) []byte
- func WaitLiveMessage[T uv.Event](tb testing.TB, log MessageCollector, opts ...Option) T
- func WaitLiveMessageWhere(tb testing.TB, log MessageCollector, fn func(uv.Event) (ok bool), ...) uv.Event
- func WaitMatch(tb testing.TB, model Viewable, pattern string, opts ...Option) string
- func WaitMessage[T uv.Event](tb testing.TB, log MessageCollector, opts ...Option) T
- func WaitMessageWhere(tb testing.TB, log MessageCollector, fn func(uv.Event) (ok bool), ...) uv.Event
- func WaitNotBytes(tb testing.TB, model Viewable, contents []byte, opts ...Option) []byte
- func WaitNotMatch(tb testing.TB, model Viewable, pattern string, opts ...Option) string
- func WaitNotString(tb testing.TB, model Viewable, contents string, opts ...Option) string
- func WaitNotStrings(tb testing.TB, model Viewable, contents []string, opts ...Option) string
- func WaitSettle(tb testing.TB, view Viewable, opts ...Option)
- func WaitSettleMessages(tb testing.TB, log MessageCollector, opts ...Option)
- func WaitString(tb testing.TB, model Viewable, contents string, opts ...Option) string
- func WaitStrings(tb testing.TB, model Viewable, contents []string, opts ...Option) string
- func WaitViewFunc[T ~string | ~[]byte](tb testing.TB, view Viewable, condition func(view T) bool, opts ...Option) T
- type Harness
- func (h *Harness) AssertDimensions(width, height int, opts ...Option) *Harness
- func (h *Harness) AssertHeight(height int, opts ...Option) *Harness
- func (h *Harness) AssertJSON(opts ...snapshot.Option) *Harness
- func (h *Harness) AssertMatch(pattern string, opts ...Option) *Harness
- func (h *Harness) AssertNotMatch(pattern string, opts ...Option) *Harness
- func (h *Harness) AssertNotString(content string, opts ...Option) *Harness
- func (h *Harness) AssertNotStrings(contents []string, opts ...Option) *Harness
- func (h *Harness) AssertSnapshot(opts ...snapshot.Option) *Harness
- func (h *Harness) AssertString(content string, opts ...Option) *Harness
- func (h *Harness) AssertStrings(contents []string, opts ...Option) *Harness
- func (h *Harness) AssertWidth(width int, opts ...Option) *Harness
- func (h *Harness) BgColor() color.Color
- func (h *Harness) Blur() *Harness
- func (h *Harness) Bounds() uv.Rectangle
- func (h *Harness) ClearScrollback() *Harness
- func (h *Harness) Close()
- func (h *Harness) CursorBlink() bool
- func (h *Harness) CursorColor() color.Color
- func (h *Harness) CursorPosition() uv.Position
- func (h *Harness) CursorStyle() vt.CursorStyle
- func (h *Harness) CursorVisible() bool
- func (h *Harness) Dimensions() (width, height int)
- func (h *Harness) FgColor() color.Color
- func (h *Harness) FinalModel(opts ...Option) tea.Model
- func (h *Harness) Focus() *Harness
- func (h *Harness) Height() int
- func (h *Harness) IsAltScreen() bool
- func (h *Harness) IsFocused() bool
- func (h *Harness) Key(key string) *Harness
- func (h *Harness) KeyBackspace() *Harness
- func (h *Harness) KeyCtrlC() *Harness
- func (h *Harness) KeyCtrlD() *Harness
- func (h *Harness) KeyDelete() *Harness
- func (h *Harness) KeyDown() *Harness
- func (h *Harness) KeyEsc() *Harness
- func (h *Harness) KeyLeft() *Harness
- func (h *Harness) KeyRight() *Harness
- func (h *Harness) KeyUp() *Harness
- func (h *Harness) LastBellAt() time.Time
- func (h *Harness) LeftClick(x, y int) *Harness
- func (h *Harness) LeftDrag(x1, y1, x2, y2 int) *Harness
- func (h *Harness) LiveMessages(ctx context.Context) iter.Seq[uv.Event]
- func (h *Harness) MessageHistory() iter.Seq[uv.Event]
- func (h *Harness) Messages(ctx context.Context) iter.Seq[uv.Event]
- func (h *Harness) MiddleClick(x, y int) *Harness
- func (h *Harness) ModeSetting(mode ansi.Mode) ansi.ModeSetting
- func (h *Harness) Mouse(m uv.MouseEvent) *Harness
- func (h *Harness) MouseClick(button uv.MouseButton, x, y int) *Harness
- func (h *Harness) MouseDrag(button uv.MouseButton, x1, y1, x2, y2 int) *Harness
- func (h *Harness) Paste(text string) *Harness
- func (h *Harness) QuitProgram() *Harness
- func (h *Harness) RequireDimensions(width, height int, opts ...Option) *Harness
- func (h *Harness) RequireHeight(height int, opts ...Option) *Harness
- func (h *Harness) RequireJSON(opts ...snapshot.Option) *Harness
- func (h *Harness) RequireMatch(pattern string, opts ...Option) *Harness
- func (h *Harness) RequireNotMatch(pattern string, opts ...Option) *Harness
- func (h *Harness) RequireNotString(content string, opts ...Option) *Harness
- func (h *Harness) RequireNotStrings(contents []string, opts ...Option) *Harness
- func (h *Harness) RequireSnapshot(opts ...snapshot.Option) *Harness
- func (h *Harness) RequireString(content string, opts ...Option) *Harness
- func (h *Harness) RequireStrings(contents []string, opts ...Option) *Harness
- func (h *Harness) RequireWidth(width int, opts ...Option) *Harness
- func (h *Harness) Resize(width, height int) *Harness
- func (h *Harness) RightClick(x, y int) *Harness
- func (h *Harness) Scrollback() []uv.Line
- func (h *Harness) ScrollbackCount() int
- func (h *Harness) SendProgram(msg uv.Event) *Harness
- func (h *Harness) SetBgColor(c color.Color) *Harness
- func (h *Harness) SetCursorColor(c color.Color) *Harness
- func (h *Harness) SetDefaultBgColor(c color.Color) *Harness
- func (h *Harness) SetDefaultCursorColor(c color.Color) *Harness
- func (h *Harness) SetDefaultFgColor(c color.Color) *Harness
- func (h *Harness) SetFgColor(c color.Color) *Harness
- func (h *Harness) SetScrollbackSize(maxLines int) *Harness
- func (h *Harness) Title() string
- func (h *Harness) Type(s string) *Harness
- func (h *Harness) View() string
- func (h *Harness) WaitBytes(contents []byte, opts ...Option) *Harness
- func (h *Harness) WaitBytesFunc(condition func(view []byte) bool, opts ...Option) *Harness
- func (h *Harness) WaitFinished(opts ...Option)
- func (h *Harness) WaitMatch(pattern string, opts ...Option) *Harness
- func (h *Harness) WaitNotBytes(contents []byte, opts ...Option) *Harness
- func (h *Harness) WaitNotMatch(pattern string, opts ...Option) *Harness
- func (h *Harness) WaitNotString(contents string, opts ...Option) *Harness
- func (h *Harness) WaitNotStrings(contents []string, opts ...Option) *Harness
- func (h *Harness) WaitSettle(opts ...Option) *Harness
- func (h *Harness) WaitSettleMessages(opts ...Option) *Harness
- func (h *Harness) WaitString(contents string, opts ...Option) *Harness
- func (h *Harness) WaitStringFunc(condition func(view string) bool, opts ...Option) *Harness
- func (h *Harness) WaitStrings(contents []string, opts ...Option) *Harness
- func (h *Harness) Width() int
- type MessageCollector
- type Option
- func WithANSI(enable bool) Option
- func WithCheck(interval time.Duration) Option
- func WithContext(ctx context.Context) Option
- func WithEnvVars(vars ...string) Option
- func WithProgramOptions(opts ...tea.ProgramOption) Option
- func WithSettle(timeout time.Duration) Option
- func WithSettleIgnoreMsgs(types ...any) Option
- func WithTimeout(timeout time.Duration) Option
- func WithWindowSize(width, height int) Option
- type Viewable
Constants ¶
const ( // DefaultTermWidth is the default terminal width for [NewHarness] and // [NewComponentHarness] (the [tea.Program] window and vt emulator). DefaultTermWidth = 80 // DefaultTermHeight is the default terminal height for [NewHarness] and // [NewComponentHarness] (the [tea.Program] window and vt emulator). DefaultTermHeight = 24 // DefaultTimeout is the default timeout used by [Harness] blocking waits. DefaultTimeout = 2 * time.Second // DefaultCheckInterval is the default polling interval used by [Harness] waits. DefaultCheckInterval = 10 * time.Millisecond // DefaultSettleTimeout is the default settle timeout used by [Harness] settle // waits. This must be less than 80% of the timeout set by [WithTimeout]. DefaultSettleTimeout = 100 * time.Millisecond )
Variables ¶
This section is empty.
Functions ¶
func AssertDimensions ¶
AssertDimensions reports an error unless output has specified dimensions.
See also Harness.AssertDimensions, AssertWidth, AssertHeight, Dimensions, RequireDimensions, and WithANSI.
func AssertHasMessage ¶
AssertHasMessage asserts that at least one message with the same concrete type as T has been observed.
func AssertHeight ¶
AssertHeight reports an error unless output has n rows. Note that this behaves differently to charm.land/lipgloss/v2.Height which always assumes a minimum height of 1. It returns whether the output matched and allows the test to continue.
See also Harness.AssertHeight, AssertDimensions, AssertWidth, Dimensions, and RequireHeight.
func AssertMatch ¶
AssertMatch reports an error unless output matches the regular expression pattern. pattern is compiled with regexp.Compile; a compile error fails the test immediately. It returns whether the output matched and allows the test to continue.
See also Harness.AssertMatch, WaitMatch, AssertNotMatch, and RequireMatch.
func AssertNotMatch ¶
AssertNotMatch reports an error if output matches the regular expression pattern. pattern is compiled with regexp.Compile; a compile error fails the test immediately. It returns whether the output matched and allows the test to continue.
See also Harness.AssertNotMatch, AssertMatch, WaitNotMatch, and RequireNotMatch.
func AssertNotString ¶
AssertNotString reports an error if content appears in output. It returns whether the output matched and allows the test to continue.
See also Harness.AssertNotString, AssertString, AssertNotStrings, and WaitNotString.
func AssertNotStrings ¶
AssertNotStrings reports an error if any substring in contents appears in output. It returns whether the output matched and allows the test to continue.
See also Harness.AssertNotStrings, AssertStrings, AssertNotString, WaitStrings, and WaitNotStrings.
func AssertString ¶
AssertString reports an error unless content appears in output. It returns whether the output matched and allows the test to continue.
See also Harness.AssertString, AssertStrings, AssertNotString, and WaitString.
func AssertStrings ¶
AssertStrings reports an error unless every substring in contents appears in output. It returns whether the output matched and allows the test to continue.
See also Harness.AssertStrings, AssertString, RequireStrings, and WaitStrings.
func AssertWidth ¶
AssertWidth reports an error unless output has n columns. It returns whether the output matched and allows the test to continue.
See also Harness.AssertWidth, AssertDimensions, Dimensions, AssertHeight, and RequireWidth.
func Dimensions ¶
Dimensions returns the width and height of the output.
See also AssertDimensions, AssertWidth, AssertHeight, and Harness.AssertDimensions.
func FilterMessagesFunc ¶
func FilterMessagesFunc[T uv.Event](tb testing.TB, messages iter.Seq[uv.Event], fn func(T) bool) iter.Seq[T]
FilterMessagesFunc filters an iterator of messages to only include messages that return true from the provided "fn" function.
func FilterMessagesType ¶
FilterMessagesType filters an iterator of messages to only include messages with the same concrete type as T.
func IgnoreMessagesReflect ¶
func IgnoreMessagesReflect(tb testing.TB, messages iter.Seq[uv.Event], ignore ...reflect.Type) iter.Seq[uv.Event]
IgnoreMessagesReflect filters an iterator of messages to exclude messages with the same concrete type as any of the provided reflect.Types.
func RequireDimensions ¶
RequireDimensions fails the test immediately unless output has specified dimensions.
See also Harness.RequireDimensions, AssertDimensions, RequireHeight, RequireWidth, and Harness.AssertSnapshot.
func RequireHasMessage ¶
RequireHasMessage requires that at least one message with the same concrete type as T has been observed.
func RequireHeight ¶
RequireHeight fails the test immediately unless output has n rows.
See also Harness.RequireHeight, AssertHeight, and RequireDimensions.
func RequireMatch ¶
RequireMatch fails the test immediately unless output matches the regular expression pattern.
See also Harness.RequireMatch, AssertMatch, RequireNotMatch, and WaitMatch.
func RequireNotMatch ¶
RequireNotMatch fails the test immediately if output matches the regular expression pattern.
See also Harness.RequireNotMatch, AssertNotMatch, and RequireMatch.
func RequireNotString ¶
RequireNotString fails the test immediately if content appears in output.
See also Harness.RequireNotString, AssertNotString, RequireString, AssertNotStrings, and RequireNotStrings.
func RequireNotStrings ¶
RequireNotStrings fails the test immediately if any substring in contents appears in output.
See also Harness.RequireNotStrings, AssertNotStrings, RequireStrings, and RequireNotString.
func RequireString ¶
RequireString fails the test immediately unless content appears in output.
See also Harness.RequireString, AssertString, and RequireStrings.
func RequireStrings ¶
RequireStrings fails the test immediately unless every substring in contents appears in output.
See also Harness.RequireStrings, AssertStrings, and RequireString.
func RequireWidth ¶
RequireWidth fails the test immediately unless output has n columns.
See also Harness.RequireWidth, AssertWidth, and RequireDimensions.
func WaitBytes ¶
WaitBytes waits until output contains contents.
See also Harness.WaitBytes, WaitViewFunc, WaitStrings, and WaitNotBytes.
func WaitLiveMessage ¶
WaitLiveMessage waits until a NEW message (only messages received since this function was invoked) with the same concrete type as T has been observed, then returns the first match.
func WaitLiveMessageWhere ¶
func WaitLiveMessageWhere(tb testing.TB, log MessageCollector, fn func(uv.Event) (ok bool), opts ...Option) uv.Event
WaitLiveMessageWhere waits until "fn" returns true for a NEW message (only messages received since this function was invoked).
See also WaitMessageWhere.
func WaitMatch ¶
WaitMatch waits until the latest view output matches the regular expression pattern. pattern is compiled with regexp.Compile; a compile error fails the test immediately.
See also Harness.WaitMatch, AssertMatch, WaitNotMatch, and RequireMatch.
func WaitMessage ¶
WaitMessage waits until at least one message with the same concrete type as T has been observed, then returns the first match.
func WaitMessageWhere ¶
func WaitMessageWhere(tb testing.TB, log MessageCollector, fn func(uv.Event) (ok bool), opts ...Option) uv.Event
WaitMessageWhere waits until "fn" returns true for a message (across all received messages).
See also WaitLiveMessageWhere.
func WaitNotBytes ¶
WaitNotBytes waits until output contains none of the contents.
See also Harness.WaitNotBytes, WaitBytes, and WaitStrings.
func WaitNotMatch ¶
WaitNotMatch waits until the latest view output does not match the regular expression pattern. pattern is compiled with regexp.Compile; a compile error fails the test immediately.
See also Harness.WaitNotMatch, WaitMatch, AssertNotMatch, and RequireNotMatch.
func WaitNotString ¶
WaitNotString waits until output contains none of the contents.
See also Harness.WaitNotString, WaitString, and WaitNotStrings.
func WaitNotStrings ¶
WaitNotStrings waits until output contains none of the contents.
See also Harness.WaitNotStrings, WaitStrings, and WaitNotString.
func WaitSettle ¶
WaitSettle waits until the rendered view string has not changed for the configured settle timeout. The model must implement Viewable; each check calls View() and compares the string to the previous sample.
See also Harness.WaitSettle, Harness.WaitSettleMessages, WithSettle, WithCheck, and WithTimeout.
func WaitSettleMessages ¶
func WaitSettleMessages(tb testing.TB, log MessageCollector, opts ...Option)
WaitSettleMessages waits until no messages have been observed for the configured settle timeout.
See also Harness.WaitSettleMessages, WaitSettle, WithSettle, WithCheck, and WithTimeout.
func WaitString ¶
WaitString waits until output contains contents.
See also Harness.WaitString, WaitViewFunc, WaitStrings, and WaitNotString.
func WaitStrings ¶
WaitStrings waits until output contains all contents.
See also Harness.WaitStrings, WaitString, and WaitNotStrings.
func WaitViewFunc ¶
func WaitViewFunc[T ~string | ~[]byte]( tb testing.TB, view Viewable, condition func(view T) bool, opts ...Option, ) T
WaitViewFunc waits until condition returns true for the latest view output.
See also Harness.WaitBytesFunc, Harness.WaitStringFunc, WaitBytes, WaitMatch, and WaitStrings.
Types ¶
type Harness ¶
type Harness struct {
// contains filtered or unexported fields
}
Harness is a test harness for a tea.Program.
func Mutate ¶
Mutate applies fn to the current underlying model from within the tea.Program's Update handling. This should be used sparingly, and only when necessary to test a specific scenario that is otherwise not possible or would pollute your model with unnecessary state. It uses the testing.TB from NewHarness or NewComponentHarness (generics cannot be expressed as a method on Harness).
fn should use the same model type originally passed to NewHarness or NewComponentHarness, such as func(Model) Model or func(*Model) *Model.
func NewComponentHarness ¶
NewComponentHarness creates a test harness for a component model by wrapping it in a root tea.Model and running it inside a tea.Program.
func NewHarness ¶
NewHarness creates a test harness by running the root tea.Model in a tea.Program. The harness captures rendered terminal output and exposes helpers for driving and asserting on runtime behavior.
func (*Harness) AssertDimensions ¶
AssertDimensions reports an error unless view output has width columns and height rows. It allows the test to continue.
See also AssertDimensions, Harness.RequireDimensions, Harness.AssertWidth, Harness.AssertHeight, Harness.RequireSnapshot, and Dimensions.
func (*Harness) AssertHeight ¶
AssertHeight reports an error unless view output has height rows. It allows the test to continue.
See also AssertHeight, Harness.RequireHeight, Harness.AssertDimensions, Harness.AssertWidth, AssertDimensions, and Dimensions.
func (*Harness) AssertJSON ¶
AssertJSON compares the current terminal screen buffer in JSON format against a previously captured snapshot. It allows the test to continue.
See also Harness.AssertSnapshot.
func (*Harness) AssertMatch ¶
AssertMatch reports an error unless view output matches the regular expression pattern.
See also AssertMatch, Harness.RequireMatch, Harness.WaitMatch, Harness.AssertNotMatch, Harness.RequireNotMatch, and Harness.WaitNotMatch.
func (*Harness) AssertNotMatch ¶
AssertNotMatch reports an error if view output matches the regular expression pattern.
See also AssertNotMatch, Harness.RequireNotMatch, Harness.AssertMatch, Harness.RequireMatch, and Harness.WaitNotMatch.
func (*Harness) AssertNotString ¶
AssertNotString reports an error if content appears in view output. It allows the test to continue.
See also AssertNotString, Harness.AssertString, Harness.AssertNotStrings, and Harness.WaitNotString.
func (*Harness) AssertNotStrings ¶
AssertNotStrings reports an error if any substring in contents appears in view output. It allows the test to continue.
See also AssertNotStrings, Harness.AssertStrings, AssertNotString, and WaitNotStrings.
func (*Harness) AssertSnapshot ¶
AssertSnapshot compares the current terminal screen buffer against a snapshot file. It allows the test to continue.
See also Harness.RequireSnapshot.
func (*Harness) AssertString ¶
AssertString reports an error unless content appears in view output. It allows the test to continue.
See also AssertString, Harness.RequireString, Harness.AssertStrings, and Harness.WaitString.
func (*Harness) AssertStrings ¶
AssertStrings reports an error unless every substring in contents appears in view output. It allows the test to continue.
See also AssertStrings, Harness.AssertString, Harness.RequireStrings, and WaitStrings.
func (*Harness) AssertWidth ¶
AssertWidth reports an error unless view output has width columns. It allows the test to continue.
See also AssertWidth, Harness.RequireWidth, Harness.AssertDimensions, Harness.AssertHeight, AssertDimensions, and Dimensions.
func (*Harness) Blur ¶
Blur sends the terminal a blur event if focus events mode is enabled. This is the opposite of Harness.Focus.
func (*Harness) ClearScrollback ¶
ClearScrollback clears all scrollback history on the screen buffer.
func (*Harness) CursorBlink ¶
CursorBlink reports whether blinking is enabled for the tracked cursor style.
func (*Harness) CursorColor ¶
CursorColor returns the terminal emulator's cursor color.
func (*Harness) CursorPosition ¶
CursorPosition returns the terminal emulator cursor position.
func (*Harness) CursorStyle ¶
func (h *Harness) CursorStyle() vt.CursorStyle
CursorStyle returns the tracked VT cursor shape.
func (*Harness) CursorVisible ¶
CursorVisible reports whether the cursor is visible per the last vt.Callbacks.CursorVisibility update (driven by DECTCEM and related screen switches).
func (*Harness) Dimensions ¶
Dimensions returns the terminals width and height in cells.
func (*Harness) FinalModel ¶
FinalModel waits for the tea.Program to finish and returns the latest underlying root model.
func (*Harness) Focus ¶
Focus sends the terminal a focus event if focus events mode is enabled. This is the opposite of Harness.Blur.
func (*Harness) Height ¶
Height returns the terminals current height in cells (matches Harness.View row count).
func (*Harness) IsAltScreen ¶
IsAltScreen returns true if the terminal is in alt screen mode.
func (*Harness) Key ¶
Key sends a single key press message to the terminal emulator itself, e.g. "ctrl+a", "enter", "space", etc.
Note that as this sends through the emulator, if paired with Harness.SendProgram, The order of events that the tea.Program receives may not be the same as order of invocation.
func (*Harness) KeyBackspace ¶
KeyBackspace sends a backspace key press to the terminal emulator.
func (*Harness) KeyDelete ¶
KeyDelete sends a delete (forward-delete) key press to the terminal emulator.
func (*Harness) LastBellAt ¶
LastBellAt returns the wall clock time of the most recent bell (ansi.BEL) processed by the VT emulator. It is the zero time.Time until the first bell.
func (*Harness) LeftClick ¶
LeftClick is Harness.MouseClick with the left mouse button.
func (*Harness) LeftDrag ¶
LeftDrag is Harness.MouseDrag with the left mouse button.
func (*Harness) LiveMessages ¶
LiveMessages returns a new iterator to live messages observed by the underlying model, starting from the first message observed after the call returns.
func (*Harness) MessageHistory ¶
MessageHistory returns a copy of all messages observed by the underlying model.
func (*Harness) Messages ¶
Messages returns a iterator to all (historical and live) messages observed by the underlying model.
func (*Harness) MiddleClick ¶
MiddleClick is Harness.MouseClick with the middle mouse button.
func (*Harness) ModeSetting ¶
func (h *Harness) ModeSetting(mode ansi.Mode) ansi.ModeSetting
ModeSetting returns the tracked ANSI mode setting. An absent mode yields ansi.ModeNotRecognized.
func (*Harness) Mouse ¶
func (h *Harness) Mouse(m uv.MouseEvent) *Harness
Mouse forwards a mouse event through the terminal emulator. The running tea.Program must have enabled a mouse tracking mode and (typically) SGR mouse encoding; otherwise events are discarded by the emulator, matching real terminal behavior.
func (*Harness) MouseClick ¶
func (h *Harness) MouseClick(button uv.MouseButton, x, y int) *Harness
MouseClick simulates a full press and release at (x, y).
func (*Harness) MouseDrag ¶
func (h *Harness) MouseDrag(button uv.MouseButton, x1, y1, x2, y2 int) *Harness
MouseDrag simulates a drag from (x1, y1) to (x2, y2).
func (*Harness) Paste ¶
Paste paste text into the terminal. If bracketed paste mode is enabled, the text is bracketed with the appropriate escape sequences.
func (*Harness) QuitProgram ¶
QuitProgram requests a graceful shutdown of the tea.Program.
func (*Harness) RequireDimensions ¶
RequireDimensions fails the test immediately unless view output has width columns and height rows.
See also RequireDimensions, Harness.AssertDimensions, Harness.RequireHeight, Harness.RequireWidth, and Harness.RequireSnapshot.
func (*Harness) RequireHeight ¶
RequireHeight fails the test immediately unless view output has height rows.
See also RequireHeight, Harness.AssertHeight, Harness.RequireDimensions, and AssertDimensions.
func (*Harness) RequireJSON ¶
RequireJSON compares the current terminal screen buffer in JSON format against a previously captured snapshot. It fails the test immediately if the snapshot does not match.
See also Harness.AssertJSON.
func (*Harness) RequireMatch ¶
RequireMatch fails the test immediately unless view output matches the regular expression pattern.
See also RequireMatch, Harness.AssertMatch, Harness.RequireNotMatch, and Harness.WaitMatch.
func (*Harness) RequireNotMatch ¶
RequireNotMatch fails the test immediately if view output matches the regular expression pattern.
See also RequireNotMatch, Harness.AssertNotMatch, Harness.AssertMatch, Harness.RequireMatch, and Harness.WaitNotMatch.
func (*Harness) RequireNotString ¶
RequireNotString fails the test immediately if content appears in view output.
See also RequireNotString, Harness.RequireString, AssertNotString, Harness.RequireNotStrings, and Harness.WaitNotStrings.
func (*Harness) RequireNotStrings ¶
RequireNotStrings fails the test immediately if any substring in contents appears in view output.
See also RequireNotStrings, Harness.RequireStrings, AssertNotStrings, Harness.RequireNotString, and WaitStrings.
func (*Harness) RequireSnapshot ¶
RequireSnapshot compares the current terminal screen buffer against a snapshot file. It fails the test immediately if the snapshot does not match.
See also Harness.AssertSnapshot.
func (*Harness) RequireString ¶
RequireString fails the test immediately unless content appears in view output.
See also RequireString, Harness.AssertString, Harness.RequireStrings, and WaitString.
func (*Harness) RequireStrings ¶
RequireStrings fails the test immediately unless every substring in contents appears in view output.
See also RequireStrings, Harness.RequireString, AssertStrings, and WaitStrings.
func (*Harness) RequireWidth ¶
RequireWidth fails the test immediately unless view output has width columns.
See also RequireWidth, Harness.AssertWidth, Harness.RequireDimensions, and AssertDimensions.
func (*Harness) Resize ¶
Resize resizes the terminal to the given width and height. This should result in a tea.WindowSizeMsg being sent to the tea.Program.
func (*Harness) RightClick ¶
RightClick is Harness.MouseClick with the right mouse button.
func (*Harness) Scrollback ¶
Scrollback returns a copy of the terminals scrollback lines (oldest first). It is nil in alternate screen mode. An empty non-nil slice means the scrollback buffer exists but has no lines yet.
func (*Harness) ScrollbackCount ¶
ScrollbackCount returns the count of scrollback lines.
func (*Harness) SendProgram ¶
SendProgram sends msg (tea.Msg or uv.Event, either works) to the tea.Program.
func (*Harness) SetBgColor ¶
SetBgColor sets the terminal emulator background color.
func (*Harness) SetCursorColor ¶
SetCursorColor sets the terminal emulator cursor color.
func (*Harness) SetDefaultBgColor ¶
SetDefaultBgColor sets default background color used when none is specified.
func (*Harness) SetDefaultCursorColor ¶
SetDefaultCursorColor sets default cursor color used when none is specified.
func (*Harness) SetDefaultFgColor ¶
SetDefaultFgColor sets default foreground color used when none is specified.
func (*Harness) SetFgColor ¶
SetFgColor sets the terminal emulator foreground color.
func (*Harness) SetScrollbackSize ¶
SetScrollbackSize sets maximum scrollback lines retained on the terminals screen buffer.
func (*Harness) Type ¶
Type sends a sequence of key press messages to the terminal emulator itself. This is designed for providing regular text input, not more complex key combinations (ctrl-key, alt-key, etc).
Note that as this sends through the emulator, if paired with Harness.SendProgram, The order of events that the tea.Program receives may not be the same as order of invocation.
func (*Harness) View ¶
View returns the current VT screen buffer (vt.Emulator.Render). Harness wait, assert, and snapshot helpers sample this rendered output. Match the terminal dimensions (WithWindowSize, Harness.Resize) to the layout under test so output has no unused rows or columns beyond what the renderer emits for that window size.
func (*Harness) WaitBytes ¶
WaitBytes waits until view output contains contents.
See also WaitBytes, Harness.WaitString, Harness.WaitStrings, and Harness.WaitBytesFunc.
func (*Harness) WaitBytesFunc ¶
WaitBytesFunc waits until condition returns true for the latest view output. It wraps WaitViewFunc with a byte-slice predicate.
See also Harness.WaitStringFunc, WaitBytes, WaitNotBytes, and WaitStrings.
func (*Harness) WaitFinished ¶
WaitFinished waits for the tea.Program to finish.
See also Harness.FinalModel and Harness.WaitSettleMessages.
func (*Harness) WaitMatch ¶
WaitMatch waits until the latest view output matches the regular expression pattern.
See also WaitMatch, Harness.WaitNotMatch, Harness.AssertMatch, and Harness.RequireMatch.
func (*Harness) WaitNotBytes ¶
WaitNotBytes waits until view output contains none of the contents.
See also WaitNotBytes, Harness.WaitBytes, Harness.WaitNotStrings, and Harness.WaitBytesFunc.
func (*Harness) WaitNotMatch ¶
WaitNotMatch waits until the latest view output does not match the regular expression pattern.
See also WaitNotMatch, Harness.WaitMatch, Harness.AssertNotMatch, and Harness.RequireNotMatch.
func (*Harness) WaitNotString ¶
WaitNotString waits until view output contains none of the contents.
See also WaitNotString, Harness.WaitString, Harness.WaitStrings, and Harness.WaitNotStrings.
func (*Harness) WaitNotStrings ¶
WaitNotStrings waits until view output contains none of the contents.
See also WaitNotStrings, Harness.WaitStrings, and Harness.WaitNotString.
func (*Harness) WaitSettle ¶
WaitSettle waits until the rendered view string from Harness.View has not changed for the configured settle timeout. It polls this harness's Harness.View and compares each result to the previous sample.
See also Harness.WaitSettleMessages, WaitSettle, WithSettle, WithCheck, and WithTimeout.
func (*Harness) WaitSettleMessages ¶
WaitSettleMessages waits until no messages have been observed for the configured settle timeout.
See also WaitSettleMessages, Harness.WaitSettle, WaitSettle, WithSettle, WithCheck, and WithTimeout.
func (*Harness) WaitString ¶
WaitString waits until view output contains contents.
See also WaitString, Harness.WaitStrings, Harness.WaitNotString, Harness.WaitMatch, and Harness.WaitStringFunc.
func (*Harness) WaitStringFunc ¶
WaitStringFunc waits until condition returns true for the latest view output. It wraps WaitViewFunc with a string predicate.
See also Harness.WaitBytesFunc, WaitString, WaitNotString, and WaitStrings.
func (*Harness) WaitStrings ¶
WaitStrings waits until view output contains all contents.
See also WaitStrings, Harness.WaitString, and Harness.WaitNotStrings.
func (*Harness) Width ¶
Width returns the terminals current width in cells (matches Harness.View output width).
type MessageCollector ¶
type MessageCollector interface {
MessageHistory() iter.Seq[uv.Event]
Messages(ctx context.Context) iter.Seq[uv.Event]
LiveMessages(ctx context.Context) iter.Seq[uv.Event]
}
MessageCollector exposes messages observed by a test harness. Harness implements this interface.
type Option ¶
type Option func(*options)
Option configures a Harness or assertion helper. NewHarness and NewComponentHarness store these options and merge them (before per-call options) on any Harness method that accepts more options, so a harness can be configured with defaults once and overridden per call.
func WithANSI ¶
WithANSI determines whether ANSI sequences should be kept. When false, ANSI sequences are stripped, which will often make it easier to visually and programmatically compare snapshots, output, etc. This would apply to strings/regex comparisons in AssertString, AssertMatch, WaitString, WaitStrings, etc.
func WithContext ¶
WithContext sets the parent context for blocking waits (WaitString, WaitMessageWhere, Harness wait helpers, etc.) and for the running tea.Program. Defaults to a notify context through signal.NotifyContext when invoked through Harness, else context.Background.
func WithEnvVars ¶
WithEnvVars sets extra environment variables for the tea.Program, in the form of "key=value". Defaults:
- TERM=xterm-256color
- TERM_PROGRAM=Apple_Terminal
func WithProgramOptions ¶
func WithProgramOptions(opts ...tea.ProgramOption) Option
WithProgramOptions appends tea.ProgramOption values for NewHarness and NewComponentHarness. The harness always sets environment, context (see WithContext), input and output (via the internal vt emulator), tea.WithoutSignals, and tea.WithWindowSize; those cannot be replaced by options passed here. It has no effect elsewhere.
func WithSettle ¶
WithSettle configures how long to wait for the tea.Program to satisfy settle waits. See Harness.WaitSettleMessages, Harness.WaitSettle and WaitSettle for more details.
See also DefaultSettleTimeout.
func WithSettleIgnoreMsgs ¶
WithSettleIgnoreMsgs marks message types that do not reset the quiet period used by Harness.WaitSettleMessages. Pass a value of each type to ignore (for example a zero value of your periodic tick type). The dynamic type of each observed message is compared with reflect.TypeOf on those samples; nil samples are skipped.
See also [DefaultSettleIgnoreMsgs].
func WithWindowSize ¶
WithWindowSize configures the starting terminal size.
See also DefaultTermWidth and DefaultTermHeight.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
broker
Package broker provides a generic in-memory event broker: publishers push events without waiting for slow subscribers; history is optionally retained up to a max size; subscribers receive only events after registration, or may opt into replay of stored history followed by live delivery.
|
Package broker provides a generic in-memory event broker: publishers push events without waiting for slow subscribers; history is optionally retained up to a max size; subscribers receive only events after registration, or may opt into replay of stored history followed by live delivery. |
|
vtpipe
Package vtpipe bridges a program's sequential stdin/stdout to blocking reader and writer halves (such as vt.Emulator) using background pumps and buffered I/O.
|
Package vtpipe bridges a program's sequential stdin/stdout to blocking reader and writer halves (such as vt.Emulator) using background pumps and buffered I/O. |
|
xansi
Package xansi normalizes terminal output for stable snapshots and assertions: stripping ANSI, spinner glyphs, and private-use code points, normalizing newlines, and escaping ESC for readable diffs.
|
Package xansi normalizes terminal output for stable snapshots and assertions: stripping ANSI, spinner glyphs, and private-use code points, normalizing newlines, and escaping ESC for readable diffs. |
|
Package snapshot provides snapshot assertions for tests.
|
Package snapshot provides snapshot assertions for tests. |