Documentation
¶
Index ¶
- Variables
- func CheckGolden(t *testing.T, name string, actual []byte, opts ...GoldenOptions)
- func LoadFixture(t *testing.T, path string) []byte
- func LoadFixtureFile(t *testing.T, fixturePath string) []byte
- func LoadJSONFixture(t *testing.T, path string, v any)
- func NewFixtureFS(t *testing.T, fixtureDir string, rootPath string) *platform.MapFileSystem
- func RunLSPFixtures(t *testing.T, testdataDir string, testFunc func(*testing.T, *LSPFixture))
- func StripANSI(s string) string
- type GoldenOptions
- type LSPFixture
Constants ¶
This section is empty.
Variables ¶
var Update = flag.Bool("update", false, "update golden files")
Update is the global --update flag for regenerating golden files
Functions ¶
func CheckGolden ¶ added in v0.8.0
func CheckGolden(t *testing.T, name string, actual []byte, opts ...GoldenOptions)
CheckGolden compares actual output against a golden file. If --update flag is set, it updates the golden file instead of comparing.
Example:
CheckGolden(t, "output", actual, GoldenOptions{Dir: "testdata", Extension: ".html"})
CheckGolden(t, "", actual, GoldenOptions{AutoName: true, StripANSI: true})
func LoadFixture ¶ added in v0.8.0
LoadFixture loads a single fixture file, trying multiple common directories. Returns the file contents or fails the test if not found.
Example:
data := LoadFixture(t, "chrome-rendering/basic-demo.html")
func LoadFixtureFile ¶
LoadFixtureFile reads a single fixture file and returns its content. The fixturePath should be relative to serve/testdata/ (e.g., "demo-routing/manifest.json"). Go tests run from the module root, so we check both possible locations.
func LoadJSONFixture ¶ added in v0.8.0
LoadJSONFixture loads and unmarshals a JSON fixture into the provided value.
Example:
var pkg manifest.Package LoadJSONFixture(t, "custom-elements.json", &pkg)
func NewFixtureFS ¶
NewFixtureFS loads fixture files from testdata and returns a MapFileSystem with files mapped to the specified root path (usually "/test"). The fixtureDir should be relative to serve/testdata/ (e.g., "transforms/config-test"). Go tests run from the module root, so we check both possible locations.
func RunLSPFixtures ¶ added in v0.8.0
RunLSPFixtures discovers and runs LSP tests from a testdata directory. Each subdirectory in testdata/ represents one test scenario with:
- input.html or input.ts (required): Content to test
- manifest.json (optional): Manifest data for custom elements
- expected.json or expected-*.json (optional): Expected results for assertions
Example usage:
RunLSPFixtures(t, "testdata/attribute-diagnostics", func(t *testing.T, fixture *LSPFixture) {
// Your test logic here using fixture.InputContent, fixture.Manifest, etc.
})
Types ¶
type GoldenOptions ¶ added in v0.8.0
type GoldenOptions struct {
// Dir specifies the directory for golden files (default: "goldens")
Dir string
// Extension specifies the file extension (default: inferred from name or ".txt")
Extension string
// StripANSI removes ANSI color codes before comparison
StripANSI bool
// NormalizeEOL normalizes line endings to \n before comparison
NormalizeEOL bool
// UseJSONDiff uses jsondiff for JSON comparison instead of string equality
UseJSONDiff bool
// AutoName uses t.Name() for the golden filename (ignores name parameter)
AutoName bool
}
GoldenOptions configures golden file comparison behavior
type LSPFixture ¶ added in v0.8.0
type LSPFixture struct {
Name string // Test scenario name (directory name)
InputHTML string // HTML content from input.html (deprecated: use InputContent)
InputContent string // Content from input.html or input.ts
InputType string // File type: "html" or "ts"
Manifest json.RawMessage // Optional manifest data from manifest.json
ExpectedMap map[string]any // Expected results from expected-*.json or expected.json
}
LSPFixture represents a single LSP test scenario loaded from fixtures
func (*LSPFixture) GetExpected ¶ added in v0.8.0
func (f *LSPFixture) GetExpected(key string, v any) error
GetExpected returns typed expected data from the fixture