render

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package render provides a first public component-fixture harness for js/wasm tests built on the framework's public UI surface.

The initial slice focuses on mounting a component tree into a controlled mock DOM fixture, rerendering it, and querying rendered output without reaching into repo-local runtime test helpers. On js/wasm builds the fixture runtime is process-global, so fixture-owning tests must run sequentially.

Index

Constants

View Source
const (
	FailureCodeHydrationMismatch = "hydration_mismatch"
	FailureCodeLoaderFailure     = "loader_failure"
	FailureCodeRouteGuardFailure = "route_guard_failure"
	FailureCodeCacheConflict     = "cache_conflict"
	FailureCodeOfflineReplay     = "offline_replay"
)

Variables

This section is empty.

Functions

func BuildCacheConflictError

func BuildCacheConflictError(parseEntity string) error

BuildCacheConflictError constructs one cache-conflict failure error.

func BuildFailureError

func BuildFailureError(parseCode string, parseMessage string) error

BuildFailureError constructs one typed failure-injection error.

func BuildHydrationMismatchError

func BuildHydrationMismatchError(parsePath string, parseReason string) error

BuildHydrationMismatchError constructs one hydration mismatch failure error.

func BuildLoaderFailureError

func BuildLoaderFailureError(parsePath string, parseReason string) error

BuildLoaderFailureError constructs one loader failure error.

func BuildOfflineReplayError

func BuildOfflineReplayError(parseEntity string, parseReason string) error

BuildOfflineReplayError constructs one offline-replay failure error.

func BuildRouteGuardFailureError

func BuildRouteGuardFailureError(parsePath string, parseReason string) error

BuildRouteGuardFailureError constructs one route-guard failure error.

func ParallelSafetyContract

func ParallelSafetyContract() string

ParallelSafetyContract returns the explicit js/wasm fixture parallel-safety contract.

Types

type DiagnosticSignal

type DiagnosticSignal struct {
	Source         string
	Severity       string
	Classification string
	Code           string
	Message        string
	Count          int
	Path           string
	Recoverable    bool
	TopFrame       string
	Consequence    string
	ComponentStack []string
	Fields         map[string]string
}

DiagnosticSignal describes one runtime diagnostic entry exposed by the fixture.

type Event

type Event struct {
	Value   string
	Checked bool
	Key     string
	KeyCode int
}

Event describes one synthetic event payload for fixture dispatch helpers.

type FailureError

type FailureError struct {
	Code    string
	Message string
}

FailureError represents one deterministic failure-injection error payload.

func (FailureError) Error

func (parseE FailureError) Error() string

Error returns the printable failure-injection error message.

type Fixture

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

Fixture owns one mock DOM container, scheduler, and configured global runtime.

The current harness serializes fixture ownership because the runtime hook surface is global on js/wasm builds.

func New

func New(parseTb testing.TB, parseOptions ...Option) *Fixture

New creates a controlled render fixture for js/wasm tests.

func (*Fixture) AllByRole

func (parseF *Fixture) AllByRole(parseRole string) []*QueryNode

AllByRole returns all nodes whose computed role matches.

func (*Fixture) AllByTag

func (parseF *Fixture) AllByTag(parseTag string) []*QueryNode

AllByTag returns all nodes matching the requested tag name.

func (*Fixture) ApplyByDescription

func (parseF *Fixture) ApplyByDescription(parseDescription string) *QueryNode

ApplyByDescription asserts one description query match and returns the node.

func (*Fixture) ApplyByLabel

func (parseF *Fixture) ApplyByLabel(parseLabel string) *QueryNode

ApplyByLabel asserts one label query match and returns the node.

func (*Fixture) ApplyByLiveRegion

func (parseF *Fixture) ApplyByLiveRegion(parsePoliteness string, parseText string) *QueryNode

ApplyByLiveRegion asserts one live-region query match and returns the node.

func (*Fixture) ApplyByRole

func (parseF *Fixture) ApplyByRole(parseRole string, parseName string) *QueryNode

ApplyByRole asserts one role query match and returns the node.

func (*Fixture) ApplyDiagnosticCode

func (parseF *Fixture) ApplyDiagnosticCode(parseCode string) DiagnosticSignal

ApplyDiagnosticCode asserts that one diagnostic with the requested code exists.

func (*Fixture) ApplyDiagnosticMessage

func (parseF *Fixture) ApplyDiagnosticMessage(parseFragment string) DiagnosticSignal

ApplyDiagnosticMessage asserts that one diagnostic message contains the provided fragment.

func (*Fixture) ApplyLogCode

func (parseF *Fixture) ApplyLogCode(parseCode string) LogSignal

ApplyLogCode asserts that one buffered log with the requested code exists.

func (*Fixture) ApplyLogMessage

func (parseF *Fixture) ApplyLogMessage(parseFragment string) LogSignal

ApplyLogMessage asserts that one buffered log message contains the provided fragment.

func (*Fixture) ApplyRenderCountMax

func (parseF *Fixture) ApplyRenderCountMax(parseComponent string, parseMax int) RenderCountSignal

ApplyRenderCountMax asserts one component's render count does not exceed max.

func (*Fixture) ApplyRenderRerenderMax

func (parseF *Fixture) ApplyRenderRerenderMax(parseComponent string, parseMax int) RenderCountSignal

ApplyRenderRerenderMax asserts one component's rerender count does not exceed max.

func (*Fixture) ApplyWarningCountMax

func (parseF *Fixture) ApplyWarningCountMax(parseMax int)

ApplyWarningCountMax asserts warnings across diagnostics and logs do not exceed max.

func (*Fixture) ApplyWarningNone

func (parseF *Fixture) ApplyWarningNone()

ApplyWarningNone asserts no warning diagnostics or warn-level logs were emitted.

func (*Fixture) BuildDiagnostics

func (parseF *Fixture) BuildDiagnostics() []DiagnosticSignal

BuildDiagnostics returns structured runtime diagnostics captured for this fixture run.

func (*Fixture) BuildLogs

func (parseF *Fixture) BuildLogs() []LogSignal

BuildLogs returns buffered runtime logs captured for this fixture run.

func (*Fixture) BuildOverlayBodyOverflow

func (parseF *Fixture) BuildOverlayBodyOverflow() string

BuildOverlayBodyOverflow reports the current browser document body overflow style.

func (*Fixture) BuildOverlayEscapeSurfaceID

func (parseF *Fixture) BuildOverlayEscapeSurfaceID() string

BuildOverlayEscapeSurfaceID returns the topmost escape-handling overlay surface id.

func (*Fixture) BuildOverlayFocusSurfaceID

func (parseF *Fixture) BuildOverlayFocusSurfaceID() string

BuildOverlayFocusSurfaceID returns the topmost trap-focus owner overlay surface id.

func (*Fixture) BuildOverlayOutsideSurfaceID

func (parseF *Fixture) BuildOverlayOutsideSurfaceID() string

BuildOverlayOutsideSurfaceID returns the topmost outside-click-handling overlay surface id.

func (*Fixture) BuildOverlayPortalTargetID

func (parseF *Fixture) BuildOverlayPortalTargetID(parseSurfaceID string) string

BuildOverlayPortalTargetID resolves one overlay surface to the nearest ancestor id.

func (*Fixture) BuildOverlayScrollLockActive

func (parseF *Fixture) BuildOverlayScrollLockActive() bool

BuildOverlayScrollLockActive reports whether overlay-driven scroll lock is active.

func (*Fixture) BuildOverlaySurfaces

func (parseF *Fixture) BuildOverlaySurfaces() []OverlaySurface

BuildOverlaySurfaces returns all rendered overlay surfaces sorted by depth.

func (*Fixture) BuildRenderCounts

func (parseF *Fixture) BuildRenderCounts() []RenderCountSignal

BuildRenderCounts returns structured component render-count signals from profiling snapshots.

func (*Fixture) BuildWarningDiagnostics

func (parseF *Fixture) BuildWarningDiagnostics() []DiagnosticSignal

BuildWarningDiagnostics returns diagnostics whose severity is warning.

func (*Fixture) BuildWarningLogs

func (parseF *Fixture) BuildWarningLogs() []LogSignal

BuildWarningLogs returns logs whose level is warn.

func (*Fixture) ByDescription

func (parseF *Fixture) ByDescription(parseDescription string) *QueryNode

ByDescription returns the first interactive node whose accessible description matches.

func (*Fixture) ByID

func (parseF *Fixture) ByID(parseId string) *QueryNode

ByID returns the first node with the requested id attribute.

func (*Fixture) ByLabel

func (parseF *Fixture) ByLabel(parseLabel string) *QueryNode

ByLabel returns the first interactive node whose accessible label matches.

func (*Fixture) ByLiveRegion

func (parseF *Fixture) ByLiveRegion(parsePoliteness string, parseText string) *QueryNode

ByLiveRegion returns the first live-region node matching politeness and optional text.

func (*Fixture) ByRole

func (parseF *Fixture) ByRole(parseRole string, parseName string) *QueryNode

ByRole returns the first node whose computed role matches, optionally filtered by accessible name.

func (*Fixture) ByText

func (parseF *Fixture) ByText(parseText string) *QueryNode

ByText returns the first node whose full text content matches the provided text.

func (*Fixture) ChangeByID

func (parseF *Fixture) ChangeByID(parseId string, parseValue string)

ChangeByID updates the matched node value, invokes `onchange`, and settles the fixture.

func (*Fixture) Cleanup

func (parseF *Fixture) Cleanup()

Cleanup releases fixture ownership and clears buffered diagnostics.

func (*Fixture) ClickByID

func (parseF *Fixture) ClickByID(parseId string)

ClickByID invokes the matched node's `onclick` handler and settles the fixture.

func (*Fixture) Container

func (parseF *Fixture) Container() *QueryNode

Container returns the fixture root container.

func (*Fixture) DispatchByID

func (parseF *Fixture) DispatchByID(parseId string, parseProperty string, parseEvent Event)

DispatchByID invokes one handler property on the matched node and settles the fixture.

func (*Fixture) Flush

func (parseF *Fixture) Flush()

Flush drains queued scheduler work until the fixture settles.

func (*Fixture) FlushTimers

func (parseF *Fixture) FlushTimers()

FlushTimers drains queued timeout work and any follow-up render work.

func (*Fixture) HandleOverlayOutsideClick

func (parseF *Fixture) HandleOverlayOutsideClick(parseSurfaceID string) bool

HandleOverlayOutsideClick dispatches one outside-click dismissal through the overlay backdrop.

func (*Fixture) InputByID

func (parseF *Fixture) InputByID(parseId string, parseValue string)

InputByID updates the matched node value, invokes `oninput`, and settles the fixture.

func (*Fixture) Render

func (parseF *Fixture) Render(parseRoot ui.Node)

Render mounts a UI tree into the fixture container.

func (*Fixture) Rerender

func (parseF *Fixture) Rerender(parseRoot ui.Node)

Rerender replaces the current tree with a new root.

func (*Fixture) SeedHTML

func (parseF *Fixture) SeedHTML(parseMarkup string) SeededMarkup

SeedHTML replaces the fixture container children with parsed server markup.

func (*Fixture) Stabilize

func (parseF *Fixture) Stabilize()

Stabilize drains pending scheduled work until the fixture settles.

func (*Fixture) SubmitByID

func (parseF *Fixture) SubmitByID(parseId string)

SubmitByID invokes the matched node's `onsubmit` handler and settles the fixture.

func (*Fixture) Target

func (parseF *Fixture) Target() any

Target returns the explicit DOM target owned by the fixture.

func (*Fixture) Text

func (parseF *Fixture) Text() string

Text returns the full fixture container text.

type LogSignal

type LogSignal struct {
	Domain         string
	Level          string
	Classification string
	Code           string
	Message        string
	Timestamp      string
	CorrelationID  string
	Recoverable    bool
	TopFrame       string
	Consequence    string
	Fields         map[string]string
}

LogSignal describes one buffered runtime log entry exposed by the fixture.

type Option

type Option func(*config)

Option configures the render fixture.

func WithQueuedScheduler

func WithQueuedScheduler() Option

WithQueuedScheduler configures the harness to queue work until Flush is called.

type OverlaySurface

type OverlaySurface struct {
	SurfaceID           string
	Kind                string
	Depth               int
	HandlesEscape       bool
	HandlesOutsideClick bool
	TrapFocusOwner      bool
	IsModal             bool
	PortalTargetID      string
}

OverlaySurface describes one rendered overlay surface snapshot.

type QueryNode

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

QueryNode wraps one matched rendered node.

func (*QueryNode) Attr

func (parseN *QueryNode) Attr(parseName string) string

Attr returns one attribute value.

func (*QueryNode) Change

func (parseN *QueryNode) Change(parseValue string)

Change updates the current node value, invokes `onchange`, and settles the fixture.

func (*QueryNode) Children

func (parseN *QueryNode) Children() []*QueryNode

Children returns wrapped child nodes.

func (*QueryNode) Click

func (parseN *QueryNode) Click()

Click invokes the current node's `onclick` handler and settles the fixture.

func (*QueryNode) Dispatch

func (parseN *QueryNode) Dispatch(parseProperty string, parseEvent Event)

Dispatch invokes one handler property on the current node and settles the fixture.

func (*QueryNode) Exists

func (parseN *QueryNode) Exists() bool

Exists reports whether the node wrapper points at a real node.

func (*QueryNode) Input

func (parseN *QueryNode) Input(parseValue string)

Input updates the current node value, invokes `oninput`, and settles the fixture.

func (*QueryNode) Name

func (parseN *QueryNode) Name() string

Name returns the node accessible name used by role-based queries.

func (*QueryNode) NodeID

func (parseN *QueryNode) NodeID() int

NodeID returns the stable mock-DOM node id for identity-sensitive assertions.

func (*QueryNode) Property

func (parseN *QueryNode) Property(parseName string) any

Property returns one raw property value from the rendered node.

func (*QueryNode) Submit

func (parseN *QueryNode) Submit()

Submit invokes the current node's `onsubmit` handler and settles the fixture.

func (*QueryNode) Tag

func (parseN *QueryNode) Tag() string

Tag returns the node tag name.

func (*QueryNode) Text

func (parseN *QueryNode) Text() string

Text returns the full text content beneath the node.

type RenderCountSignal

type RenderCountSignal struct {
	Name                    string
	Path                    string
	RenderCount             int
	RerenderCount           int
	LastTrigger             string
	TotalRenderDurationNs   int64
	AverageRenderDurationNs int64
}

RenderCountSignal describes one component render-count profile entry.

type ResourceAttempt

type ResourceAttempt struct {
	Index     int
	Cancelled bool
}

type ResourceController

type ResourceController[T any] struct {
	// contains filtered or unexported fields
}

ResourceController provides deterministic control over one async resource loader in tests.

func NewResourceController

func NewResourceController[T any]() *ResourceController[T]

NewResourceController creates one async controller for fetch/resource tests.

func (*ResourceController[T]) AttemptCount

func (parseC *ResourceController[T]) AttemptCount() int

AttemptCount reports how many attempts have started.

func (*ResourceController[T]) Attempts

func (parseC *ResourceController[T]) Attempts() []ResourceAttempt

Attempts returns a snapshot of all started attempts.

func (*ResourceController[T]) Await

func (parseC *ResourceController[T]) Await(parseCtx context.Context) (T, error)

Await blocks until the current attempt is resolved, rejected, or cancelled.

func (*ResourceController[T]) Cancel

func (parseC *ResourceController[T]) Cancel()

Cancel completes the current pending attempt with context cancellation.

func (*ResourceController[T]) Loader

func (parseC *ResourceController[T]) Loader() func(context.Context) (T, error)

Loader returns a loader function compatible with fetch.UseResource or fetch.UseCachedResource.

func (*ResourceController[T]) Pending

func (parseC *ResourceController[T]) Pending() bool

Pending reports whether one attempt is currently stalled.

func (*ResourceController[T]) Reject

func (parseC *ResourceController[T]) Reject(parseErr error)

Reject completes the current pending attempt with an error.

func (*ResourceController[T]) RejectCacheConflict

func (parseC *ResourceController[T]) RejectCacheConflict(parseEntity string)

RejectCacheConflict completes the current pending attempt with a cache-conflict failure.

func (*ResourceController[T]) RejectOfflineReplay

func (parseC *ResourceController[T]) RejectOfflineReplay(parseEntity string, parseReason string)

RejectOfflineReplay completes the current pending attempt with an offline-replay failure.

func (*ResourceController[T]) Resolve

func (parseC *ResourceController[T]) Resolve(parseValue T)

Resolve completes the current pending attempt successfully.

func (*ResourceController[T]) Started

func (parseC *ResourceController[T]) Started() <-chan int

Started returns a channel that receives each started attempt index.

type SeededMarkup

type SeededMarkup struct {
	HTML    string
	NodeIDs map[string]int
}

Jump to

Keyboard shortcuts

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