statictest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0, MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package statictest exports an app inside a test and asserts on the result: files, headers and redirects as the host's preview serves them, and diagnostics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {

	// Dir is the output directory, inside t.TempDir().
	Dir string
	// Report is the export's report.
	Report *static.Report
	// Err is the export error: nil, or one wrapping static.ErrExport when
	// error diagnostics were found (nothing is written then).
	Err error
	// contains filtered or unexported fields
}

Result is one export made by Export.

func Export

func Export(t testing.TB, app static.App, opts ...static.Option) *Result

Export exports app with opts into a temporary directory. A configuration error fails the test at once; error diagnostics are left in Err and Report for the test to assert on.

func ExportWith

func ExportWith(t testing.TB, app static.App, o static.ExportOptions, opts ...static.Option) *Result

ExportWith is Export with explicit ExportOptions. An empty Out becomes a directory inside t.TempDir().

func (*Result) Diagnostics

func (r *Result) Diagnostics(code string) []static.Diagnostic

Diagnostics returns the diagnostics with code, or all of them for "".

func (*Result) File

func (r *Result) File(path string) string

File returns the contents of an output file, failing the test if it is missing.

func (*Result) Get

func (r *Result) Get(path string) *http.Response

Get requests path from the target's preview of the export, so redirects, headers, clean URLs and the 404 page behave as on the host.

func (*Result) HasDiagnostic

func (r *Result) HasDiagnostic(code, path string) bool

HasDiagnostic reports whether a diagnostic with code was found on path ("" for any path).

func (*Result) HasFile

func (r *Result) HasFile(path string) bool

HasFile reports whether the export wrote path.

func (*Result) Header

func (r *Result) Header(path, name string) string

Header returns header name of path as the preview serves it.

func (*Result) OK

func (r *Result) OK() *Result

OK fails the test when the export failed, listing the failing diagnostics.

func (*Result) Redirect

func (r *Result) Redirect(path string) (location string, status int, ok bool)

Redirect returns where the preview sends path, and the status; ok is false when it does not redirect.

Jump to

Keyboard shortcuts

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