Ginkgo provides comprehensive type definitions for reports, states, locations, events, and enumerations used throughout the framework.
const VERSION = "2.27.2"
const GINKGO_VERSION = "2.27.2"
const GINKGO_FOCUS_EXIT_CODE = 197
var GINKGO_TIME_FORMAT = "01/02/06 15:04:05.999"The time format can be customized via the GINKGO_TIME_FORMAT environment variable.
These types have been covered in detail in Reporting Documentation and Configuration Documentation, but are summarized here for completeness.
###Report
Complete suite execution report.
type Report struct {
SuitePath string
SuiteDescription string
SuiteLabels []string
SuiteSemVerConstraints []string
SuiteSucceeded bool
SuiteHasProgrammaticFocus bool
SpecialSuiteFailureReasons []string
PreRunStats PreRunStats
StartTime time.Time
EndTime time.Time
RunTime time.Duration
SuiteConfig SuiteConfig
SpecReports SpecReports
}Methods:
func (report Report) Add(other Report) ReportIndividual spec execution report.
type SpecReport struct {
// Hierarchy
ContainerHierarchyTexts []string
ContainerHierarchyLocations []CodeLocation
ContainerHierarchyLabels [][]string
ContainerHierarchySemVerConstraints [][]string
// Leaf node information
LeafNodeType NodeType
LeafNodeLocation CodeLocation
LeafNodeLabels []string
LeafNodeSemVerConstraints []string
LeafNodeText string
// Execution details
SpecPriority int
State SpecState
IsSerial bool
IsInOrderedContainer bool
StartTime time.Time
EndTime time.Time
RunTime time.Duration
ParallelProcess int
RunningInParallel bool
// Failure and retry information
Failure Failure
NumAttempts int
MaxFlakeAttempts int
MaxMustPassRepeatedly int
// Output and reporting
CapturedGinkgoWriterOutput string
CapturedStdOutErr string
ReportEntries ReportEntries
ProgressReports []ProgressReport
AdditionalFailures []AdditionalFailure
SpecEvents SpecEvents
}Methods:
func (report SpecReport) FullText() string
func (report SpecReport) Failed() bool
func (report SpecReport) IsSerial() bool
func (report SpecReport) IsInOrderedContainer() bool
func (report SpecReport) CombinedOutput() string
func (report SpecReport) Labels() []string
func (report SpecReport) SemVerConstraints() []string
func (report SpecReport) MatchesLabelFilter(query string) (bool, error)
func (report SpecReport) MatchesSemVerFilter(version string) (bool, error)
func (report SpecReport) FileName() string
func (report SpecReport) LineNumber() int
func (report SpecReport) FailureMessage() string
func (report SpecReport) FailureLocation() CodeLocation
func (report SpecReport) Timeline() TimelineCollection of spec reports with filtering and counting methods.
type SpecReports []SpecReportMethods:
func (reports SpecReports) WithLeafNodeType(nodeTypes NodeType) SpecReports
func (reports SpecReports) WithState(states SpecState) SpecReports
func (reports SpecReports) CountWithState(states SpecState) int
func (reports SpecReports) CountOfFlakedSpecs() int
func (reports SpecReports) CountOfRepeatedSpecs() intStatistics before suite execution.
type PreRunStats struct {
TotalSpecs int
SpecsThatWillRun int
}Report available during tree construction phase.
type ConstructionNodeReport struct {
CodeLocation CodeLocation
ContainerHierarchyTexts []string
ContainerHierarchyLocations []CodeLocation
ContainerHierarchyLabels [][]string
ContainerHierarchySemVerConstraints [][]string
IsSerial bool
IsInOrderedContainer bool
}Methods:
func (report ConstructionNodeReport) FullText() string
func (report ConstructionNodeReport) Labels() []stringDetailed failure information.
type Failure struct {
Message string
Location CodeLocation
TimelineLocation TimelineLocation
ForwardedPanic string
// Node context
FailureNodeContext FailureNodeContext
FailureNodeType NodeType
FailureNodeLocation CodeLocation
FailureNodeContainerIndex int
// Progress and additional failures
ProgressReport ProgressReport
AdditionalFailure *AdditionalFailure
}Methods:
func (f Failure) IsZero() bool
func (f Failure) GetTimelineLocation() TimelineLocationContext describing where a failure occurred.
type FailureNodeContext uint
const (
FailureNodeContextInvalid FailureNodeContext = iota
FailureNodeIsLeafNode
FailureNodeAtTopLevel
FailureNodeInContainer
)Methods:
func (fnc FailureNodeContext) String() string
func (fnc *FailureNodeContext) UnmarshalJSON(b []byte) error
func (fnc FailureNodeContext) MarshalJSON() ([]byte, error)Failures that occur after the initial failure (typically in cleanup).
type AdditionalFailure struct {
State SpecState
Failure Failure
}Methods:
func (f AdditionalFailure) GetTimelineLocation() TimelineLocationSource code location with stack trace.
type CodeLocation struct {
FileName string
LineNumber int
FullStackTrace string
}Methods:
func (cl CodeLocation) String() string
func (cl CodeLocation) ContentsOfLine() stringLocation of an event in the spec's execution timeline.
type TimelineLocation struct {
Offset int
Order int
Time time.Time
}Progress information for running specs.
type ProgressReport struct {
// Current execution state
CurrentNodeType NodeType
CurrentNodeText string
CurrentNodeLocation CodeLocation
CurrentStepText string
// Context
ParallelProcess int
RunningInParallel bool
Time time.Time
// Hierarchy
ContainerHierarchyTexts []string
LeafNodeText string
// Goroutine information
SpecGoroutine Goroutine
Goroutines []Goroutine
AdditionalReports []string
// Output
CapturedGinkgoWriterOutput string
CapturedStdOutErr string
ReportEntries ReportEntries
}Methods:
func (pr ProgressReport) GetTimelineLocation() TimelineLocationCustom report entry attached to spec.
type ReportEntry struct {
Visibility ReportEntryVisibility
Location CodeLocation
Time time.Time
TimelineLocation TimelineLocation
Name string
Value any
}Methods:
func (entry ReportEntry) GetRawValue() any
func (entry ReportEntry) StringRepresentation() string
func (entry ReportEntry) GetTimelineLocation() TimelineLocationCollection of report entries.
type ReportEntries []ReportEntryMethods:
func (entries ReportEntries) HasVisibility(
visibilities ...ReportEntryVisibility,
) ReportEntries
func (entries ReportEntries) WithName(name string) ReportEntryEvent that occurs during spec execution.
type SpecEvent struct {
SpecEventType SpecEventType
Message string
CodeLocation CodeLocation
TimelineLocation TimelineLocation
NodeType NodeType
Duration time.Duration
}Methods:
func (se SpecEvent) GetTimelineLocation() TimelineLocation
func (se SpecEvent) IsOnlyVisibleAtVeryVerbose() boolCollection of spec events.
type SpecEvents []SpecEventMethods:
func (events SpecEvents) WithType(eventType SpecEventType) SpecEventsOrdered collection of timeline events.
type TimelineEvent interface {
GetTimelineLocation() TimelineLocation
}
type Timeline []TimelineEventMethods:
func (t Timeline) Len() int
func (t Timeline) Less(i, j int) bool
func (t Timeline) Swap(i, j int)
func (t Timeline) WithoutHiddenReportEntries() Timeline
func (t Timeline) WithoutVeryVerboseSpecEvents() TimelineInformation about a goroutine.
type Goroutine struct {
ID uint64
State string
Stack []byte
}Type of Ginkgo node.
type NodeType uint
const (
NodeTypeInvalid NodeType = iota
NodeTypeContainer
NodeTypeIt
NodeTypeBeforeEach
NodeTypeJustBeforeEach
NodeTypeAfterEach
NodeTypeJustAfterEach
NodeTypeBeforeAll
NodeTypeAfterAll
NodeTypeBeforeSuite
NodeTypeAfterSuite
NodeTypeSynchronizedBeforeSuite
NodeTypeSynchronizedAfterSuite
NodeTypeReportBeforeEach
NodeTypeReportAfterEach
NodeTypeReportBeforeSuite
NodeTypeReportAfterSuite
NodeTypeCleanupInvalid
NodeTypeCleanupAfterEach
NodeTypeCleanupAfterAll
NodeTypeCleanupAfterSuite
)Methods:
func (nt NodeType) String() string
func (nt NodeType) Is(nodeTypes NodeType) boolType Collections:
var NodeTypesForContainerAndIt NodeType
var NodeTypesForSuiteLevelNodes NodeType
var NodeTypesAllowedDuringCleanupInterrupt NodeType
var NodeTypesAllowedDuringReportInterrupt NodeTypeExample:
if report.LeafNodeType.Is(types.NodeTypeIt) {
fmt.Println("This is an It node")
}
// Check multiple types
if report.LeafNodeType.Is(types.NodeTypeIt | types.NodeTypeBeforeEach) {
fmt.Println("This is an It or BeforeEach node")
}State of spec execution.
type SpecState uint
const (
SpecStateInvalid SpecState = iota
SpecStatePending
SpecStateSkipped
SpecStatePassed
SpecStateFailed
SpecStateAborted
SpecStatePanicked
SpecStateInterrupted
SpecStateTimedout
)Methods:
func (ss SpecState) String() string
func (ss SpecState) Is(states SpecState) boolState Collections:
var SpecStateFailureStates SpecStateExample:
if report.State.Is(types.SpecStatePassed) {
fmt.Println("Spec passed")
}
if report.State.Is(types.SpecStateFailureStates) {
fmt.Println("Spec failed")
}Type of spec event.
type SpecEventType uint
const (
SpecEventInvalid SpecEventType = iota
SpecEventNodeStart
SpecEventNodeEnd
SpecEventSpecRepeat
SpecEventSpecRetry
SpecEventByStart
SpecEventByEnd
SpecEventProgressReport
)Methods:
func (set SpecEventType) String() stringVisibility level for report entries.
type ReportEntryVisibility uint
const (
ReportEntryVisibilityAlways ReportEntryVisibility = iota
ReportEntryVisibilityFailureOrVerbose
ReportEntryVisibilityNever
)Methods:
func (rev ReportEntryVisibility) String() stringRemoves internal Ginkgo functions from stack traces.
func PruneStack(fullStackTrace string, skip int) stringParameters:
fullStackTrace: Complete stack trace stringskip: Number of frames to skipExample:
stackTrace := debug.Stack()
cleanTrace := types.PruneStack(string(stackTrace), 0)Marks the calling function as a helper for stack trace purposes.
func MarkAsHelper(optionalSkip ...int)Label decorator type.
type Labels []stringMethods:
func (labels Labels) MatchesLabelFilter(filter string) boolCompiled label filter function.
type LabelFilter func([]string) boolParses a label filter expression.
func ParseLabelFilter(filter string) (LabelFilter, error)Example:
filter, err := types.ParseLabelFilter("(integration || unit) && !slow")
if err != nil {
panic(err)
}
labels := []string{"integration", "api"}
if filter(labels) {
fmt.Println("Labels match filter")
}Semantic version constraints decorator.
type SemVerConstraints []stringMethods:
func (constraints SemVerConstraints) MatchesSemVerFilter(filter string) boolParses a semantic version filter.
func ParseSemVerFilter(filter string) (func([]string) bool, error)Validates and normalizes a label string.
func ValidateAndCleanupLabel(label string, cl CodeLocation) (string, error)Example:
cleaned, err := types.ValidateAndCleanupLabel(" Integration Test ", location)
if err != nil {
panic(err)
}
// cleaned == "integration test"Validates a label filter expression.
func MustValidateLabelFilter(filter string) (LabelFilter, error)Generates command-line flag arguments from configuration.
func GenerateFlagArgs(flags GinkgoFlags, bindings any) ([]string, error)Generates arguments for running a Ginkgo test binary.
func GenerateGinkgoTestRunArgs(
suiteConfig SuiteConfig,
reporterConfig ReporterConfig,
goFlagsConfig GoFlagsConfig,
) ([]string, error)Generates arguments for compiling tests with go test -c.
func GenerateGoTestCompileArgs(
goFlagsConfig GoFlagsConfig,
packageToBuild string,
pathToInvocationPath string,
preserveSymbols bool,
) ([]string, error)Generates arguments for running non-Ginkgo test binaries.
func GenerateGoTestRunArgs(goFlagsConfig GoFlagsConfig) ([]string, error)For backward compatibility with Ginkgo v1:
// Deprecated aliases for NodeType
var SpecComponentTypeInvalid = NodeTypeInvalid
var SpecComponentTypeContainer = NodeTypeContainer
var SpecComponentTypeIt = NodeTypeIt
var SpecComponentTypeBeforeEach = NodeTypeBeforeEach
// ... etcThese are maintained for compatibility but should not be used in new code.