snap

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package snap contains snapshot test functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunBubbleTeaSnapshots

func RunBubbleTeaSnapshots(
	snapshotSuite *SnapshotSuite,
	m tea.Model,
	verify bool,
	seriesID string,
	equal VerifyFunc,
)

RunBubbleTeaSnapshots runs snapshots for bubbletea TUIs.

func ToSafeFilename

func ToSafeFilename(s string) string

ToSafeFilename replaces all non-safe characters with underscore.

Types

type Snapshot

type Snapshot struct {
	// Name of the test that's also the last part of the snapshot file's filepath.
	Name string
	// contains filtered or unexported fields
}

Snapshot represents a single test with a snapshot file.

func (*Snapshot) Run

func (v *Snapshot) Run(view string) error

Run the snapshot process according to parameters set in snap.SnapshotSuite.NewSnapshot. Error is returned when something unexpected fails, not when the test itself fails. Determining whether any given test fails is left for "equal" function defined in snap.SnapshotSuite.NewSnapshot.

type SnapshotSuite

type SnapshotSuite struct {
	// contains filtered or unexported fields
}

A SnapshotSuite is a suite of snapshot tests with a shared directory for the snapshot files. It is made of [snap.Snapshot]s.

func NewSnapshotSuite

func NewSnapshotSuite(rootDir string) *SnapshotSuite

NewSnapshotSuite creates a snap.SnapshotSuite with a root directory. Usually it's under "testdata".

func (*SnapshotSuite) NewSnapshot

func (v *SnapshotSuite) NewSnapshot(name string, verify bool, equal VerifyFunc) *Snapshot

NewSnapshot creates a snapshot. Name is snap.Snapshot.Name and with [snap.SnapshotSuite.rootDir], becomes the full filepath of the snapshot file. When verify is false, snapshots are written, and tests won't fail. That's how you initialize or update snapshots. When verify is true and snapshot file doesn't exist or it's empty, content produced by the tested code is written. And finally, when verify is true and the snapshot file exists, equal function is used to assert equality.

type VerifyFunc

type VerifyFunc func(expected, actual, message string)

VerifyFunc is used to assert that snapshot matches to the string that code produced. This is your standard "assertEqual" function in any unit test library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL