@probitas/builder

Builder module for creating scenario definitions with a fluent, type-safe API.

This package provides the scenario fn function that returns a builder for constructing scenario definitions. The builder uses method chaining to define resources, setup functions, and test steps with full TypeScript type inference.

Package Description
@probitas/scenario Core type definitions used by this builder
@probitas/runner Executes scenarios built with this package

Key Features

  • Fluent API: Chain methods naturally to build complex scenarios
  • Type-safe context: Each step receives typed access to previous step results
  • Resource management: Register resources with automatic lifecycle handling
  • Setup/Cleanup: Define setup functions with automatic cleanup support
  • Configurable defaults: Override timeout and retry settings at any level

Core Exports

Installation

deno add jsr:@probitas/builder

Functions

function

#scenario

function scenario(name: string, options?: ScenarioOptions): ScenarioBuilderInit

Create a new scenario builder with a fluent API.

This is the primary entry point for defining scenarios. It returns a builder that provides a type-safe, chainable API for constructing test scenarios.

Parameters
  • namestring
    • Human-readable scenario name (shown in test reports)
    • Optional configuration for tags, timeouts, and retry behavior
Returns

ScenarioBuilderInit — New {@linkcode ScenarioBuilderInit} instance ready for chaining

Examples

Basic scenario with type-safe step chaining

import { scenario } from "@probitas/builder";

export default scenario("User Registration")
  .step("Create user", async () => {
    const user = await createUser({ email: "test@example.com" });
    return { userId: user.id };
  })
  .step("Verify email", async (ctx) => {
    // ctx.previous is typed as { userId: string }
    await verifyEmail(ctx.previous.userId);
  })
  .build();

Scenario with tags for filtering

scenario("Payment Integration", {
  tags: ["integration", "payment", "slow"],
  stepOptions: { timeout: 60000 }  // 1 minute timeout for all steps
})
  .step("Process payment", async () => { ... })
  .build();

// Run with: probitas run -s "tag:payment"

Scenario with resources and setup

scenario("Database Test")
  .resource("db", async () => await Database.connect())
  .setup((ctx) => {
    // Run migrations
    return () => ctx.resources.db.rollback();
  })
  .step("Insert data", (ctx) => ctx.resources.db.insert(...))
  .step("Query data", (ctx) => ctx.resources.db.query(...))
  .build();

Type Aliases

type

#BuilderStepContext

type BuilderStepContext<P = unknown, A extends readonly unknown[] = readonly unknown[], R extends Record<string, unknown> = Record<string, unknown>> = StepContext & { previous: P; results: A; resources: R }

Execution context provided to steps, resources, and setup hooks.

The context provides access to:

  • Previous step results with full type inference
  • All accumulated results as a typed tuple
  • Named resources registered with .resource()
  • Shared storage for cross-step communication
  • Abort signal for timeout and cancellation handling
type

#BuilderStepDefinition

type BuilderStepDefinition<T = unknown, P = unknown, A extends readonly unknown[] = readonly unknown[], R extends Record<string, unknown> = Record<string, unknown>> = StepDefinition & { fn: BuilderStepFunction<T, P, A, R> }

Immutable definition of a scenario step.

Contains all information needed to execute a single step: the step function, its options, and debugging metadata.

type

#BuilderStepFunction

type BuilderStepFunction<T = unknown, P = unknown, A extends readonly unknown[] = readonly unknown[], R extends Record<string, unknown> = Record<string, unknown>> = (ctx: BuilderStepContext<P, A, R>) => unknown

Function signature for step execution.

A step function receives the execution context and returns a value (sync or async) that becomes available to subsequent steps.

Search Documentation