snapshot

package
v0.12.21 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Baseline

type Baseline struct {
	Name      string      `json:"name"`
	Timestamp time.Time   `json:"timestamp"`
	GitCommit string      `json:"git_commit,omitempty"`
	GitBranch string      `json:"git_branch,omitempty"`
	Pages     []PageState `json:"pages"`
	Config    Config      `json:"config"`
}

Baseline represents a saved set of screenshots for comparison

type CompareResult

type CompareResult struct {
	BaselineName string           `json:"baseline_name"`
	Timestamp    time.Time        `json:"timestamp"`
	Pages        []PageComparison `json:"pages"`
	Summary      Summary          `json:"summary"`
}

CompareResult holds the results of a baseline comparison

type Config

type Config struct {
	DiffThreshold float64        `json:"diff_threshold"` // 0.0 - 1.0
	IgnoreRegions []IgnoreRegion `json:"ignore_regions,omitempty"`
}

Config holds snapshot configuration

type Differ

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

Differ handles image comparison

func NewDiffer

func NewDiffer(threshold float64) *Differ

NewDiffer creates a new image differ

func (*Differ) Compare

func (d *Differ) Compare(baselinePath, currentPath string) (float64, image.Image, error)

Compare compares two images and returns diff percentage and diff image

func (*Differ) HasSignificantChanges

func (d *Differ) HasSignificantChanges(diffPercentage float64) bool

HasSignificantChanges checks if diff percentage exceeds threshold

func (*Differ) SaveDiffImage

func (d *Differ) SaveDiffImage(img image.Image, path string) error

SaveDiffImage saves a diff image to disk

type IgnoreRegion

type IgnoreRegion struct {
	Selector string `json:"selector"`
	Reason   string `json:"reason"`
}

IgnoreRegion defines areas to skip during comparison

type Manager

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

Manager orchestrates snapshot operations

func NewManager

func NewManager(storagePath string, diffThreshold float64) (*Manager, error)

NewManager creates a new snapshot manager

func (*Manager) CompareToBaseline

func (m *Manager) CompareToBaseline(baselineName string, currentPages []PageCapture) (*CompareResult, error)

CompareToBaseline compares current screenshots to a baseline

func (*Manager) CreateBaseline

func (m *Manager) CreateBaseline(name string, pages []PageCapture) (*Baseline, error)

CreateBaseline captures screenshots and saves them as a baseline

func (*Manager) DeleteBaseline

func (m *Manager) DeleteBaseline(name string) error

DeleteBaseline removes a baseline

func (*Manager) GetBaseline

func (m *Manager) GetBaseline(name string) (*Baseline, error)

GetBaseline loads a specific baseline

func (*Manager) ListBaselines

func (m *Manager) ListBaselines() ([]*Baseline, error)

ListBaselines returns all available baselines

type PageCapture

type PageCapture struct {
	URL            string   `json:"url"`
	Viewport       Viewport `json:"viewport"`
	ScreenshotData string   `json:"screenshot_data"` // Base64 encoded PNG
}

PageCapture represents a page to capture or that was captured

type PageComparison

type PageComparison struct {
	URL               string  `json:"url"`
	DiffPercentage    float64 `json:"diff_percentage"`
	DiffImagePath     string  `json:"diff_image_path"`
	BaselineImagePath string  `json:"baseline_image_path"`
	CurrentImagePath  string  `json:"current_image_path"`
	HasChanges        bool    `json:"has_changes"`
	Description       string  `json:"description,omitempty"`
}

PageComparison holds diff results for a single page

type PageState

type PageState struct {
	URL        string            `json:"url"`
	Viewport   Viewport          `json:"viewport"`
	Screenshot string            `json:"screenshot"` // Filename
	Timestamp  time.Time         `json:"timestamp"`
	Metadata   map[string]string `json:"metadata,omitempty"`
}

PageState represents the captured state of a single page

type Storage

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

Storage handles baseline persistence

func NewStorage

func NewStorage(basePath string) (*Storage, error)

NewStorage creates a new storage manager

func (*Storage) DeleteBaseline

func (s *Storage) DeleteBaseline(name string) error

DeleteBaseline removes a baseline from disk

func (*Storage) GetBaselinePath

func (s *Storage) GetBaselinePath(name string) (string, error)

GetBaselinePath returns the directory path for a baseline. Returns an error if the name would escape the base directory.

func (*Storage) GetDiffsPath

func (s *Storage) GetDiffsPath() string

GetDiffsPath returns the diffs directory path

func (*Storage) GetScreenshotPath

func (s *Storage) GetScreenshotPath(baselineName, filename string) (string, error)

GetScreenshotPath returns the path to a screenshot file. Returns an error if the path would escape the base directory.

func (*Storage) ListBaselines

func (s *Storage) ListBaselines() ([]*Baseline, error)

ListBaselines returns all available baselines

func (*Storage) LoadBaseline

func (s *Storage) LoadBaseline(name string) (*Baseline, error)

LoadBaseline loads a baseline from disk

func (*Storage) SaveBaseline

func (s *Storage) SaveBaseline(baseline *Baseline) error

SaveBaseline persists a baseline to disk

func (*Storage) SaveDiff

func (s *Storage) SaveDiff(result *CompareResult) error

SaveDiff saves comparison results to disk

func (*Storage) SaveScreenshot

func (s *Storage) SaveScreenshot(baselineName, filename string, data []byte) error

SaveScreenshot saves a screenshot file to a baseline

type Summary

type Summary struct {
	TotalPages     int     `json:"total_pages"`
	PagesChanged   int     `json:"pages_changed"`
	PagesUnchanged int     `json:"pages_unchanged"`
	AverageDiff    float64 `json:"average_diff"`
	HasRegressions bool    `json:"has_regressions"`
}

Summary provides high-level comparison statistics

type Viewport

type Viewport struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Viewport represents screen dimensions

Jump to

Keyboard shortcuts

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