service

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InspectFormatBundle       = "bundle"
	InspectFormatPNG          = "png"
	InspectFormatHTML         = "html"
	InspectFormatCSSJSON      = "css-json"
	InspectFormatCSSMarkdown  = "css-md"
	InspectFormatInspectJSON  = "inspect-json"
	InspectFormatMetadataJSON = "metadata-json"
)
View Source
const CatalogSchemaVersion = "css-visual-diff.catalog.v1"
View Source
const DefaultPrepareAfterWait = 500 * time.Millisecond
View Source
const DefaultPrepareWaitTimeout = 30 * time.Second

Variables

This section is empty.

Functions

func BuildDirectReactGlobalScript

func BuildDirectReactGlobalScript(prepare *config.PrepareSpec) (string, error)

func CanonicalInspectFormat

func CanonicalInspectFormat(format string) (string, error)

func CleanCatalogRelativePath

func CleanCatalogRelativePath(path string) string

func CloneJSON

func CloneJSON[T any](value T) (T, error)

func EnsureInspectSelectorExists

func EnsureInspectSelectorExists(page *driver.Page, req InspectRequest) error

func InspectFormatRequiresExistingSelector

func InspectFormatRequiresExistingSelector(format string) bool

func LoadAndPreparePage

func LoadAndPreparePage(page *driver.Page, target config.Target) error

func LocatorAttributes

func LocatorAttributes(page *driver.Page, locator LocatorSpec, attrs []string) (map[string]string, error)

func LocatorComputedStyle

func LocatorComputedStyle(page *driver.Page, locator LocatorSpec, props []string) (map[string]string, error)

func LocatorText

func LocatorText(page *driver.Page, locator LocatorSpec, opts TextOptions) (string, error)

func PrepareTarget

func PrepareTarget(page *driver.Page, target config.Target) error

func RenderDiffMarkdown

func RenderDiffMarkdown(diff SnapshotDiff) string

func RootSelectorForTarget

func RootSelectorForTarget(target config.Target) string

func RunDirectReactGlobalPrepare

func RunDirectReactGlobalPrepare(page *driver.Page, prepare *config.PrepareSpec) error

func RunScriptPrepare

func RunScriptPrepare(page *driver.Page, prepare *config.PrepareSpec) error

func SanitizeCatalogSlug

func SanitizeCatalogSlug(slug string) string

func SanitizeName

func SanitizeName(name string) string

func WriteInspectCSSMarkdown

func WriteInspectCSSMarkdown(path string, req InspectRequest, style StyleSnapshot) error

func WriteInspectIndex

func WriteInspectIndex(outDir string, result InspectResult) error

func WriteInspectJSON

func WriteInspectJSON(page *driver.Page, selector, path string) error

func WriteJSON

func WriteJSON(path string, data any) error

func WritePreparedHTML

func WritePreparedHTML(page *driver.Page, selector, path string) error

Types

type Bounds

type Bounds struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

func LocatorBounds

func LocatorBounds(page *driver.Page, locator LocatorSpec) (*Bounds, error)

type BrowserService

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

func NewBrowserService

func NewBrowserService(ctx context.Context) (*BrowserService, error)

func (*BrowserService) Browser

func (s *BrowserService) Browser() *driver.Browser

func (*BrowserService) Close

func (s *BrowserService) Close()

func (*BrowserService) NewPage

func (s *BrowserService) NewPage() (*PageService, error)

type Catalog

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

func NewCatalog

func NewCatalog(opts CatalogOptions) (*Catalog, error)

func (*Catalog) AddFailure

func (*Catalog) AddResult

func (c *Catalog) AddResult(target CatalogTargetRecord, result InspectResult) CatalogResultRecord

func (*Catalog) AddTarget

func (c *Catalog) AddTarget(target CatalogTargetRecord) CatalogTargetRecord

func (*Catalog) ArtifactDir

func (c *Catalog) ArtifactDir(slug string) string

func (*Catalog) Manifest

func (c *Catalog) Manifest() CatalogManifest

func (*Catalog) Options

func (c *Catalog) Options() CatalogOptions

func (*Catalog) RecordPreflight

func (c *Catalog) RecordPreflight(target CatalogTargetRecord, statuses []SelectorStatus) CatalogPreflightRecord

func (*Catalog) Summary

func (c *Catalog) Summary() CatalogSummary

func (*Catalog) WriteIndex

func (c *Catalog) WriteIndex() (string, error)

func (*Catalog) WriteManifest

func (c *Catalog) WriteManifest() (string, error)

type CatalogFailureRecord

type CatalogFailureRecord struct {
	Target     CatalogTargetRecord `json:"target"`
	Name       string              `json:"name,omitempty"`
	Code       string              `json:"code,omitempty"`
	Operation  string              `json:"operation,omitempty"`
	Message    string              `json:"message"`
	RecordedAt time.Time           `json:"recorded_at"`
}

type CatalogManifest

type CatalogManifest struct {
	SchemaVersion string                   `json:"schema_version"`
	Title         string                   `json:"title"`
	OutDir        string                   `json:"out_dir"`
	ArtifactRoot  string                   `json:"artifact_root"`
	CreatedAt     time.Time                `json:"created_at"`
	UpdatedAt     time.Time                `json:"updated_at"`
	Targets       []CatalogTargetRecord    `json:"targets"`
	Preflights    []CatalogPreflightRecord `json:"preflights,omitempty"`
	Results       []CatalogResultRecord    `json:"results,omitempty"`
	Failures      []CatalogFailureRecord   `json:"failures,omitempty"`
	Summary       CatalogSummary           `json:"summary"`
}

type CatalogOptions

type CatalogOptions struct {
	Title        string
	OutDir       string
	ArtifactRoot string
	IndexName    string
}

type CatalogPreflightRecord

type CatalogPreflightRecord struct {
	Target     CatalogTargetRecord `json:"target"`
	Statuses   []SelectorStatus    `json:"statuses"`
	RecordedAt time.Time           `json:"recorded_at"`
}

type CatalogResultRecord

type CatalogResultRecord struct {
	Target     CatalogTargetRecord `json:"target"`
	Result     InspectResult       `json:"result"`
	RecordedAt time.Time           `json:"recorded_at"`
}

type CatalogSummary

type CatalogSummary struct {
	TargetCount    int `json:"target_count"`
	PreflightCount int `json:"preflight_count"`
	ResultCount    int `json:"result_count"`
	FailureCount   int `json:"failure_count"`
	ArtifactCount  int `json:"artifact_count"`
}

type CatalogTargetRecord

type CatalogTargetRecord struct {
	Slug        string          `json:"slug"`
	Name        string          `json:"name,omitempty"`
	URL         string          `json:"url,omitempty"`
	Selector    string          `json:"selector,omitempty"`
	Viewport    config.Viewport `json:"viewport,omitempty"`
	Description string          `json:"description,omitempty"`
	Metadata    map[string]any  `json:"metadata,omitempty"`
}

func NormalizeCatalogTarget

func NormalizeCatalogTarget(target CatalogTargetRecord) CatalogTargetRecord

type DiffChange

type DiffChange struct {
	Path   string `json:"path"`
	Before any    `json:"before,omitempty"`
	After  any    `json:"after,omitempty"`
}

type DiffOptions

type DiffOptions struct {
	IgnorePaths []string `json:"ignorePaths,omitempty"`
}

type DirectReactGlobalPrepareResult

type DirectReactGlobalPrepareResult struct {
	OK            bool               `json:"ok"`
	ComponentName string             `json:"component_name"`
	RootSelector  string             `json:"root_selector"`
	Props         map[string]any     `json:"props"`
	Bounds        map[string]float64 `json:"bounds"`
}

type ElementHTML

type ElementHTML struct {
	Exists bool   `json:"exists"`
	HTML   string `json:"html"`
}

func LocatorHTML

func LocatorHTML(page *driver.Page, locator LocatorSpec, outer bool) (ElementHTML, error)

type ElementSnapshot

type ElementSnapshot struct {
	Selector   string            `json:"selector"`
	Exists     *bool             `json:"exists,omitempty"`
	Visible    *bool             `json:"visible,omitempty"`
	Text       string            `json:"text,omitempty"`
	Bounds     *Bounds           `json:"bounds,omitempty"`
	Computed   map[string]string `json:"computed,omitempty"`
	Attributes map[string]string `json:"attributes,omitempty"`
}

func ExtractElement

func ExtractElement(page *driver.Page, locator LocatorSpec, extractors []ExtractorSpec) (ElementSnapshot, error)

type ExtractorKind

type ExtractorKind string
const (
	ExtractorExists        ExtractorKind = "exists"
	ExtractorVisible       ExtractorKind = "visible"
	ExtractorText          ExtractorKind = "text"
	ExtractorBounds        ExtractorKind = "bounds"
	ExtractorComputedStyle ExtractorKind = "computedStyle"
	ExtractorAttributes    ExtractorKind = "attributes"
)

type ExtractorSpec

type ExtractorSpec struct {
	Kind       ExtractorKind `json:"kind"`
	Props      []string      `json:"props,omitempty"`
	Attributes []string      `json:"attributes,omitempty"`
	Text       TextOptions   `json:"text,omitempty"`
}

type InspectAllOptions

type InspectAllOptions struct {
	OutDir     string
	Format     string
	OutputFile string
}

type InspectArtifactResult

type InspectArtifactResult struct {
	Metadata    InspectMetadata `json:"metadata"`
	Style       *StyleSnapshot  `json:"style,omitempty"`
	Screenshot  string          `json:"screenshot,omitempty"`
	HTML        string          `json:"html,omitempty"`
	InspectJSON string          `json:"inspect_json,omitempty"`
}

func WriteInspectArtifacts

func WriteInspectArtifacts(page *driver.Page, target config.Target, side string, req InspectRequest, format, outDir, outputFile string) (InspectArtifactResult, error)

func WriteSingleInspectArtifact

func WriteSingleInspectArtifact(page *driver.Page, req InspectRequest, metadata InspectMetadata, format, path string) (InspectArtifactResult, error)

type InspectMetadata

type InspectMetadata struct {
	Side           string          `json:"side"`
	TargetName     string          `json:"target_name"`
	URL            string          `json:"url"`
	Viewport       config.Viewport `json:"viewport"`
	Name           string          `json:"name"`
	Selector       string          `json:"selector"`
	SelectorSource string          `json:"selector_source"`
	RootSelector   string          `json:"root_selector,omitempty"`
	PrepareType    string          `json:"prepare_type,omitempty"`
	Format         string          `json:"format"`
	CreatedAt      time.Time       `json:"created_at"`
}

type InspectRequest

type InspectRequest struct {
	Name       string   `json:"name"`
	Selector   string   `json:"selector"`
	Props      []string `json:"props,omitempty"`
	Attributes []string `json:"attributes,omitempty"`
	Source     string   `json:"source"`
}

type InspectResult

type InspectResult struct {
	OutputDir string                  `json:"output_dir,omitempty"`
	Results   []InspectArtifactResult `json:"results"`
}

func InspectPreparedPage

func InspectPreparedPage(page *driver.Page, target config.Target, side string, requests []InspectRequest, opts InspectAllOptions) (InspectResult, error)

type LocatorSpec

type LocatorSpec struct {
	Name     string `json:"name,omitempty"`
	Selector string `json:"selector"`
	Source   string `json:"source,omitempty"`
}

LocatorSpec identifies one element on a loaded page.

type PageService

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

func (*PageService) Close

func (p *PageService) Close()

func (*PageService) LoadAndPrepareTarget

func (p *PageService) LoadAndPrepareTarget(target config.Target) error

func (*PageService) Page

func (p *PageService) Page() *driver.Page

type PageSnapshot

type PageSnapshot struct {
	Results []ProbeSnapshot `json:"results"`
}

func SnapshotPage

func SnapshotPage(page *driver.Page, probes []SnapshotProbeSpec) (PageSnapshot, error)

type ProbeSnapshot

type ProbeSnapshot struct {
	Name     string          `json:"name"`
	Selector string          `json:"selector"`
	Source   string          `json:"source,omitempty"`
	Snapshot ElementSnapshot `json:"snapshot"`
	Error    string          `json:"error,omitempty"`
}

type ProbeSpec

type ProbeSpec struct {
	Name       string   `json:"name"`
	Selector   string   `json:"selector"`
	Props      []string `json:"props,omitempty"`
	Attributes []string `json:"attributes,omitempty"`
	Source     string   `json:"source,omitempty"`
	Required   bool     `json:"required,omitempty"`
}

type SelectorStatus

type SelectorStatus struct {
	Name      string  `json:"name,omitempty"`
	Selector  string  `json:"selector"`
	Source    string  `json:"source,omitempty"`
	Exists    bool    `json:"exists"`
	Visible   bool    `json:"visible"`
	Bounds    *Bounds `json:"bounds,omitempty"`
	TextStart string  `json:"text_start,omitempty"`
	Error     string  `json:"error,omitempty"`
}

func LocatorStatus

func LocatorStatus(page *driver.Page, locator LocatorSpec) (SelectorStatus, error)

func PreflightProbes

func PreflightProbes(page *driver.Page, probes []ProbeSpec) ([]SelectorStatus, error)

type SnapshotDiff

type SnapshotDiff struct {
	Equal       bool         `json:"equal"`
	ChangeCount int          `json:"change_count"`
	Changes     []DiffChange `json:"changes"`
}

func DiffValues

func DiffValues(before, after any, opts DiffOptions) (SnapshotDiff, error)

type SnapshotProbeSpec

type SnapshotProbeSpec struct {
	Name       string          `json:"name"`
	Selector   string          `json:"selector"`
	Source     string          `json:"source,omitempty"`
	Required   bool            `json:"required,omitempty"`
	Extractors []ExtractorSpec `json:"extractors"`
}

type StyleSnapshot

type StyleSnapshot struct {
	Exists     bool              `json:"exists"`
	Computed   map[string]string `json:"computed"`
	Bounds     *Bounds           `json:"bounds,omitempty"`
	Attributes map[string]string `json:"attributes,omitempty"`
}

func EvaluateStyle

func EvaluateStyle(page *driver.Page, spec config.StyleSpec) (StyleSnapshot, error)

type TextOptions

type TextOptions struct {
	NormalizeWhitespace bool `json:"normalizeWhitespace,omitempty"`
	Trim                bool `json:"trim,omitempty"`
}

Jump to

Keyboard shortcuts

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