ssr

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ssr provides first public SSR and hydration test helpers.

It focuses on HTML snapshotting, typed bootstrap-payload assertions, and a lightweight hydration smoke harness for js/wasm tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequirePayload

func RequirePayload[T any](parseTb testing.TB, parseBootstrap ui.SSRBootstrap, parseKey string) ui.SSRPayloadValue[T]

RequirePayload reads one typed bootstrap payload entry and fails the test if it is missing.

Types

type ExportedRoute

type ExportedRoute struct {
	Path          string
	HTMLFile      string
	BootstrapFile string
	Snapshot      Snapshot
	Bootstrap     []byte
}

type HydrationHarness

type HydrationHarness struct{}

HydrationHarness wraps one hydration smoke run.

func RoundTripHydrate

func RoundTripHydrate(parseTb testing.TB, parseRoot any, parseOptions ...HydrationOptions) *HydrationHarness

RoundTripHydrate requires a js/wasm test environment.

func RoundTripHydrateMismatch

func RoundTripHydrateMismatch(parseTb testing.TB, parseRoot any, buildMutate func(string) string, parseOptions ...HydrationOptions) *HydrationHarness

RoundTripHydrateMismatch requires a js/wasm test environment.

func SmokeHydrate

func SmokeHydrate(parseTb testing.TB, parseRoot any, parseOptions ...HydrationOptions) *HydrationHarness

SmokeHydrate requires a js/wasm test environment.

type HydrationOptions

type HydrationOptions struct{}

HydrationOptions configures the hydration smoke harness.

type LinkTag

type LinkTag struct {
	Rel        string
	Href       string
	HrefLang   string
	As         string
	Attributes map[string]string
}

type MetaTag

type MetaTag struct {
	Name       string
	Property   string
	Content    string
	Attributes map[string]string
}

type ScriptTag

type ScriptTag struct {
	ID         string
	Type       string
	Content    string
	Attributes map[string]string
}

type Snapshot

type Snapshot struct {
	HTML string
}

Snapshot captures one server-rendered HTML result.

func Render

func Render(parseTb testing.TB, parseRoot ui.Node) Snapshot

Render snapshots one UI tree through the public SSR surface.

func (Snapshot) Contains

func (parseS Snapshot) Contains(parseSubstring string) bool

Contains reports whether the rendered HTML contains the expected substring.

func (Snapshot) Structured

func (parseS Snapshot) Structured(parseTb testing.TB) StructuredSnapshot

Structured parses the snapshot into typed head-friendly structures.

type StaticExport

type StaticExport struct {
	Root      string
	HTMLFiles map[string]Snapshot
	Bootstrap map[string][]byte
}

func LoadStaticExport

func LoadStaticExport(parseTb testing.TB, parseOutputDir string) StaticExport

LoadStaticExport reads one prerendered output directory into structured HTML and bootstrap maps.

func (StaticExport) Route

func (parseE StaticExport) Route(parseRoutePath string) (ExportedRoute, error)

Route resolves one route path into its emitted HTML file and optional bootstrap sidecar.

type StructuredSnapshot

type StructuredSnapshot struct {
	Title          string
	MetaByName     map[string][]MetaTag
	MetaByProperty map[string][]MetaTag
	LinksByRel     map[string][]LinkTag
	ScriptsByID    map[string]ScriptTag
	ScriptsByType  map[string][]ScriptTag
}

func (StructuredSnapshot) ApplyStructuredCanonicalURL

func (parseS StructuredSnapshot) ApplyStructuredCanonicalURL(parseTb testing.TB, parseExpected string)

ApplyStructuredCanonicalURL asserts one parsed canonical URL value.

func (StructuredSnapshot) ApplyStructuredJSONLDType

func (parseS StructuredSnapshot) ApplyStructuredJSONLDType(parseTb testing.TB, parseId string, parseExpected string)

ApplyStructuredJSONLDType asserts one JSON-LD script has the expected `@type` value.

func (StructuredSnapshot) ApplyStructuredMetaName

func (parseS StructuredSnapshot) ApplyStructuredMetaName(parseTb testing.TB, parseName string, parseExpected string)

ApplyStructuredMetaName asserts one parsed meta-name value.

func (StructuredSnapshot) ApplyStructuredMetaProperty

func (parseS StructuredSnapshot) ApplyStructuredMetaProperty(parseTb testing.TB, parseProperty string, parseExpected string)

ApplyStructuredMetaProperty asserts one parsed meta-property value.

func (StructuredSnapshot) ApplyStructuredScriptID

func (parseS StructuredSnapshot) ApplyStructuredScriptID(parseTb testing.TB, parseId string) ScriptTag

ApplyStructuredScriptID asserts one parsed script id is present and returns that script.

func (StructuredSnapshot) ApplyStructuredTitle

func (parseS StructuredSnapshot) ApplyStructuredTitle(parseTb testing.TB, parseExpected string)

ApplyStructuredTitle asserts one parsed title value.

func (StructuredSnapshot) CanonicalURL

func (parseS StructuredSnapshot) CanonicalURL() string

func (StructuredSnapshot) JSONLD

func (parseS StructuredSnapshot) JSONLD(parseId string) string

func (StructuredSnapshot) MetaName

func (parseS StructuredSnapshot) MetaName(parseName string) string

func (StructuredSnapshot) MetaProperty

func (parseS StructuredSnapshot) MetaProperty(parseProperty string) string

func (StructuredSnapshot) ParseStructuredBootstrapScript

func (parseS StructuredSnapshot) ParseStructuredBootstrapScript(parseTb testing.TB, parseId string) map[string]any

ParseStructuredBootstrapScript decodes one inline bootstrap script into a typed map.

func (StructuredSnapshot) ParseStructuredJSONLD

func (parseS StructuredSnapshot) ParseStructuredJSONLD(parseTb testing.TB, parseId string) map[string]any

ParseStructuredJSONLD decodes one JSON-LD script into a typed map.

Jump to

Keyboard shortcuts

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