or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-dsl.mddecorators.mdextensions.mdindex.mdreporters.mdreporting.mdtable-driven-testing.mdtypes.md
tile.json

decorators.mddocs/

Decorators

Decorators modify the behavior of container nodes, subject nodes, and setup/teardown nodes. They control execution order, timeouts, retries, labeling, and more.

Labels and Filtering

Label

Adds labels to specs or containers for filtering and organization.

func Label(labels ...string) Labels

type Labels []string

Parameters:

  • labels: One or more label strings

Example:

Describe("API Tests", Label("integration", "api"), func() {
    It("handles GET requests", Label("smoke"), func() {
        // test code
    })

    It("handles POST requests", Label("slow"), func() {
        // test code
    })
})

// Run with: ginkgo --label-filter="integration && !slow"

SemVerConstraint

Adds semantic version constraints to specs or containers.

func SemVerConstraint(constraints ...string) SemVerConstraints

type SemVerConstraints []string

Parameters:

  • constraints: Semantic version constraint expressions (e.g., ">=1.0.0", "<2.0.0")

Example:

Describe("Version-specific tests", func() {
    It("works in v1.x", SemVerConstraint(">=1.0.0", "<2.0.0"), func() {
        // test code
    })

    It("works in v2.x", SemVerConstraint(">=2.0.0"), func() {
        // test code
    })
})

// Run with: ginkgo --sem-ver-filter="1.5.0"

Retry and Stability

FlakeAttempts

Retries a failed spec up to N times. If any attempt passes, the spec passes.

func FlakeAttempts(attempts uint) FlakeAttempts

type FlakeAttempts uint

Parameters:

  • attempts: Maximum number of retry attempts

Example:

It("handles flaky external API", FlakeAttempts(3), func() {
    // This will retry up to 3 times on failure
    response := callExternalAPI()
    Expect(response.Status).To(Equal(200))
})

MustPassRepeatedly

Requires a spec to pass N times consecutively. If any run fails, the spec fails.

func MustPassRepeatedly(count uint) MustPassRepeatedly

type MustPassRepeatedly uint

Parameters:

  • count: Number of times the spec must pass

Example:

It("is consistently stable", MustPassRepeatedly(5), func() {
    // Must pass 5 times in a row
    result := performOperation()
    Expect(result).To(BeTrue())
})

Timeouts and Interrupts

NodeTimeout

Sets a timeout for an individual node (BeforeEach, It, AfterEach, etc.).

func NodeTimeout(timeout time.Duration) NodeTimeout

type NodeTimeout time.Duration

Parameters:

  • timeout: Maximum duration for the node

Example:

BeforeEach(func(ctx SpecContext) {
    // This BeforeEach has 5 second timeout
    setupResources(ctx)
}, NodeTimeout(5*time.Second))

It("completes quickly", func() {
    // test code
}, NodeTimeout(2*time.Second))

SpecTimeout

Sets a timeout for an entire spec (including all BeforeEach, It, and AfterEach nodes).

func SpecTimeout(timeout time.Duration) SpecTimeout

type SpecTimeout time.Duration

Parameters:

  • timeout: Maximum duration for the entire spec

Example:

It("performs end-to-end test", func(ctx SpecContext) {
    By("starting services")
    startServices(ctx)

    By("running test")
    runTest(ctx)

    By("checking results")
    checkResults(ctx)
}, SpecTimeout(30*time.Second))

GracePeriod

Sets the grace period for cleanup after an interrupt or timeout.

func GracePeriod(gracePeriod time.Duration) GracePeriod

type GracePeriod time.Duration

Parameters:

  • gracePeriod: Duration to allow for cleanup

Example:

It("cleans up gracefully", func(ctx SpecContext) {
    resource := allocateExpensiveResource()
    DeferCleanup(func() {
        resource.Cleanup()
    })

    performLongOperation(ctx)
}, SpecTimeout(10*time.Second), GracePeriod(5*time.Second))

Execution Control

Ordered

Marks a container so its specs run sequentially in order, not randomized.

const Ordered

Example:

Describe("Sequential workflow", Ordered, func() {
    var workflowID string

    It("creates workflow", func() {
        workflowID = createWorkflow()
    })

    It("starts workflow", func() {
        startWorkflow(workflowID)
    })

    It("completes workflow", func() {
        Eventually(func() bool {
            return isWorkflowComplete(workflowID)
        }).Should(BeTrue())
    })
})

Serial

Marks specs to never run in parallel, even when running with -p flag.

const Serial

Example:

Describe("Database tests", Serial, func() {
    // These tests modify shared state and must run serially
    It("migrates schema", func() {
        migrateSchema()
    })

    It("seeds data", func() {
        seedTestData()
    })
})

ContinueOnFailure

In an Ordered container, continue running subsequent specs even if one fails.

const ContinueOnFailure

Example:

Describe("Test suite", Ordered, ContinueOnFailure, func() {
    It("test 1", func() {
        Expect(false).To(BeTrue()) // Fails
    })

    It("test 2", func() {
        // Still runs despite test 1 failure
        Expect(true).To(BeTrue())
    })
})

Focus

Focuses on specific specs or containers. Only focused specs run.

const Focus

Example:

Describe("Feature tests", func() {
    It("test 1", func() {
        // Will not run
    })

    It("test 2", Focus, func() {
        // Only this runs
    })
})

// Equivalent to:
FIt("test 2", func() {
    // Only this runs
})

Pending

Marks specs or containers as pending (skipped).

const Pending

Example:

Describe("Future feature", Pending, func() {
    It("will be implemented later", func() {
        // Not run
    })
})

// Equivalent to:
PIt("will be implemented later", func() {
    // Not run
})

OncePerOrdered

For setup nodes in an Ordered container, run once per ordered context instead of per spec.

const OncePerOrdered

Example:

Describe("Ordered tests", Ordered, func() {
    BeforeEach(func() {
        // Normally runs before each It
        // With OncePerOrdered, runs once at start
        setupExpensiveResource()
    }, OncePerOrdered)

    It("test 1", func() {
        useResource()
    })

    It("test 2", func() {
        useResource()
    })
})

Progress Reporting

PollProgressAfter

Emits progress reports if a node hasn't completed after the specified duration.

func PollProgressAfter(interval time.Duration) PollProgressAfter

type PollProgressAfter time.Duration

Parameters:

  • interval: Duration after which to start emitting progress

Example:

It("performs long operation", func() {
    // Emit progress if not done after 5 seconds
    performLongOperation()
}, PollProgressAfter(5*time.Second))

PollProgressInterval

Sets the rate at which to emit progress reports after PollProgressAfter has elapsed.

func PollProgressInterval(interval time.Duration) PollProgressInterval

type PollProgressInterval time.Duration

Parameters:

  • interval: Rate for emitting progress reports

Example:

It("monitors progress", func() {
    performLongOperation()
}, PollProgressAfter(5*time.Second), PollProgressInterval(2*time.Second))

SuppressProgressReporting

Disables progress reporting for a node.

const SuppressProgressReporting

Example:

It("runs without progress reports", func() {
    performOperation()
}, SuppressProgressReporting)

Source Location

Offset

Adjusts the reported source code location for failures.

func Offset(offset int) Offset

type Offset int

Parameters:

  • offset: Number of stack frames to skip (positive) or add (negative)

Example:

func CustomAssertion(value string) {
    // Report failures at caller's location, not here
    It("validates value", Offset(1), func() {
        Expect(value).To(BeValid())
    })
}

CodeLocation

Explicitly sets the code location for a node.

func CodeLocation(cl CodeLocation) CodeLocation

type CodeLocation struct {
    FileName       string
    LineNumber     int
    FullStackTrace string
}

Methods:

func (cl CodeLocation) String() string
func (cl CodeLocation) ContentsOfLine() string

Example:

loc := types.NewCodeLocation(2) // Get location 2 frames up
It("has custom location", CodeLocation(loc), func() {
    // test code
})

Execution Priority

SpecPriority

Sets execution priority for specs. Higher priority specs run first.

func SpecPriority(priority int) SpecPriority

type SpecPriority int

Parameters:

  • priority: Integer priority (higher = runs first)

Example:

Describe("Tests", func() {
    It("low priority", SpecPriority(1), func() {
        // Runs last
    })

    It("high priority", SpecPriority(10), func() {
        // Runs first
    })

    It("medium priority", SpecPriority(5), func() {
        // Runs second
    })
})

Advanced Decorators

AroundNode

Advanced decorator that wraps node execution, allowing custom behavior before and after.

func AroundNode[F types.AroundNodeAllowedFuncs](f F) types.AroundNodeDecorator

// AroundNodeAllowedFuncs are function signatures allowed for AroundNode
type AroundNodeAllowedFuncs interface {
    func(ctx context.Context, fn func(ctx context.Context))
    func(ctx context.Context, fn func(ctx context.Context) error) error
    func(fn func())
    func(fn func() error) error
}

Example:

// Add tracing around each It
var _ = It("is traced", AroundNode(func(ctx context.Context, fn func(ctx context.Context)) {
    span := startTracing("test-span")
    defer span.Finish()

    fn(ctx) // Run the actual test
}), func(ctx context.Context) {
    // Test code runs here
    performOperation()
})

Decorator Combinations

Decorators can be combined to create sophisticated test behaviors:

Describe("Complex test scenarios", func() {
    It("handles everything",
        Label("integration", "slow"),
        FlakeAttempts(3),
        SpecTimeout(30*time.Second),
        PollProgressAfter(10*time.Second),
        func(ctx SpecContext) {
            // Test implementation
        })
})

Using Decorators with Containers

Most decorators work on both individual specs and containers:

Describe("Feature", Label("feature"), Serial, func() {
    // All specs inherit Label and Serial

    BeforeEach(func() {
        setupData()
    }, NodeTimeout(5*time.Second))

    It("test 1", func() {
        // Inherits Label and Serial from Describe
    })

    It("test 2", Label("smoke"), func() {
        // Has both "feature" and "smoke" labels
    })
})

Decorator Inheritance

  • Labels are inherited and accumulated from parent containers
  • Timeouts are specific to the node they're applied to
  • Focus and Pending propagate to child nodes
  • Ordered and Serial apply to the container and its contents
  • FlakeAttempts and MustPassRepeatedly apply to individual specs