API reference

On this page 712

Every declaration below is extracted from zig-test-framework's source, with the doc comments as written there. A declaration listed without prose is public but undocumented in the source.

Root

assertions

const assertions = @import("assertions.zig")

suite

const suite = @import("suite.zig")

test_runner

const test_runner = @import("test_runner.zig")

reporter

const reporter = @import("reporter.zig")

matchers

const matchers = @import("matchers.zig")

mock

const mock = @import("mock.zig")

cli

const cli = @import("cli.zig")

discovery

const discovery = @import("discovery.zig")

test_loader

const test_loader = @import("test_loader.zig")

coverage

const coverage = @import("coverage.zig")

parallel

const parallel = @import("parallel.zig")

ui_server

const ui_server = @import("ui_server.zig")

test_history

const test_history = @import("test_history.zig")

snapshot

const snapshot = @import("snapshot.zig")

watch

const watch = @import("watch.zig")

memory_profiler

const memory_profiler = @import("memory_profiler.zig")

config

const config = @import("config.zig")

async_support

const async_support = @import("async_support.zig")

async_test

const async_test = @import("async_test.zig")

timeout

const timeout = @import("timeout.zig")

progress

const progress = @import("progress.zig")

time

const time = @import("time.zig")

compat

const compat = @import("compat.zig")

expect

const expect = assertions.expect

Expectation

const Expectation = assertions.Expectation

StringExpectation

const StringExpectation = assertions.StringExpectation

SliceExpectation

const SliceExpectation = assertions.SliceExpectation

AssertionError

const AssertionError = assertions.AssertionError

describe

const describe = suite.describe

it

const it = suite.it

test_

const test_ = suite.test_

beforeEach

const beforeEach = suite.beforeEach

afterEach

const afterEach = suite.afterEach

beforeAll

const beforeAll = suite.beforeAll

afterAll

const afterAll = suite.afterAll

describeSkip

const describeSkip = suite.describeSkip

describeOnly

const describeOnly = suite.describeOnly

itSkip

const itSkip = suite.itSkip

itOnly

const itOnly = suite.itOnly

itAsync

const itAsync = suite.itAsync

itAsyncTimeout

const itAsyncTimeout = suite.itAsyncTimeout

itAsyncSkip

const itAsyncSkip = suite.itAsyncSkip

itAsyncOnly

const itAsyncOnly = suite.itAsyncOnly

itTimeout

const itTimeout = suite.itTimeout

describeTimeout

const describeTimeout = suite.describeTimeout

TestSuite

const TestSuite = suite.TestSuite

TestCase

const TestCase = suite.TestCase

TestStatus

const TestStatus = suite.TestStatus

TestRegistry

const TestRegistry = suite.TestRegistry

TestFn

const TestFn = suite.TestFn

HookFn

const HookFn = suite.HookFn

TestRunner

const TestRunner = test_runner.TestRunner

RunnerOptions

const RunnerOptions = test_runner.RunnerOptions

ReporterType

const ReporterType = test_runner.ReporterType

runTests

const runTests = test_runner.runTests

runTestsWithOptions

const runTestsWithOptions = test_runner.runTestsWithOptions

Reporter

const Reporter = reporter.Reporter

TestResults

const TestResults = reporter.TestResults

SpecReporter

const SpecReporter = reporter.SpecReporter

DotReporter

const DotReporter = reporter.DotReporter

JsonReporter

const JsonReporter = reporter.JsonReporter

TAPReporter

const TAPReporter = reporter.TAPReporter

JUnitReporter

const JUnitReporter = reporter.JUnitReporter

Colors

const Colors = reporter.Colors

Matchers

const Matchers = matchers.Matchers

StructMatcher

const StructMatcher = matchers.StructMatcher

ArrayMatcher

const ArrayMatcher = matchers.ArrayMatcher

expectStruct

const expectStruct = matchers.expectStruct

expectArray

const expectArray = matchers.expectArray

toBeCloseTo

const toBeCloseTo = matchers.Matchers.toBeCloseTo

toBeNaN

const toBeNaN = matchers.Matchers.toBeNaN

toBeInfinite

const toBeInfinite = matchers.Matchers.toBeInfinite

Mock

const Mock = mock.Mock

Spy

const Spy = mock.Spy

createMock

const createMock = mock.createMock

createSpy

const createSpy = mock.createSpy

CallRecord

const CallRecord = mock.CallRecord

CLI

const CLI = cli.CLI

CLIOptions

const CLIOptions = cli.CLIOptions

DiscoveryOptions

const DiscoveryOptions = discovery.DiscoveryOptions

DiscoveryResult

const DiscoveryResult = discovery.DiscoveryResult

TestFile

const TestFile = discovery.TestFile

discoverTests

const discoverTests = discovery.discoverTests

LoaderOptions

const LoaderOptions = test_loader.LoaderOptions

runDiscoveredTests

const runDiscoveredTests = test_loader.runDiscoveredTests

CoverageOptions

const CoverageOptions = coverage.CoverageOptions

CoverageResult

const CoverageResult = coverage.CoverageResult

CoverageTool

const CoverageTool = coverage.CoverageTool

runWithCoverage

const runWithCoverage = coverage.runWithCoverage

runTestWithCoverage

const runTestWithCoverage = coverage.runTestWithCoverage

parseCoverageReport

const parseCoverageReport = coverage.parseCoverageReport

printCoverageSummary

const printCoverageSummary = coverage.printCoverageSummary

isCoverageToolAvailable

const isCoverageToolAvailable = coverage.isCoverageToolAvailable

ParallelOptions

const ParallelOptions = parallel.ParallelOptions

runTestsParallel

const runTestsParallel = parallel.runTestsParallel

UIServer

const UIServer = ui_server.UIServer

UIServerOptions

const UIServerOptions = ui_server.UIServerOptions

UIReporter

const UIReporter = ui_server.UIReporter

MultiReporter

const MultiReporter = ui_server.MultiReporter

TestHistory

const TestHistory = test_history.TestHistory

HistoryEntry

const HistoryEntry = test_history.HistoryEntry

TestRecord

const TestRecord = test_history.TestRecord

Snapshot

const Snapshot = snapshot.Snapshot

SnapshotOptions

const SnapshotOptions = snapshot.SnapshotOptions

SnapshotFormat

const SnapshotFormat = snapshot.SnapshotFormat

SnapshotDiff

const SnapshotDiff = snapshot.SnapshotDiff

DiffEntry

const DiffEntry = snapshot.DiffEntry

InlineSnapshot

const InlineSnapshot = snapshot.InlineSnapshot

SnapshotCleanup

const SnapshotCleanup = snapshot.SnapshotCleanup

createSnapshot

const createSnapshot = snapshot.snapshot

TestWatcher

const TestWatcher = watch.TestWatcher

WatchOptions

const WatchOptions = watch.WatchOptions

FileWatcher

const FileWatcher = watch.FileWatcher

MemoryProfiler

const MemoryProfiler = memory_profiler.MemoryProfiler

MemoryStats

const MemoryStats = memory_profiler.MemoryStats

ProfilingAllocator

const ProfilingAllocator = memory_profiler.ProfilingAllocator

ProfileOptions

const ProfileOptions = memory_profiler.ProfileOptions

TestConfig

const TestConfig = config.TestConfig

ConfigLoader

const ConfigLoader = config.ConfigLoader

ConfigFormat

const ConfigFormat = config.ConfigFormat

Future

const Future = async_support.Future

Promise

const Promise = async_support.Promise

AsyncExecutor

const AsyncExecutor = async_support.AsyncExecutor

runAsync

const runAsync = async_support.runAsync

asyncDelay

const asyncDelay = async_support.delay

AsyncTestExecutor

const AsyncTestExecutor = async_test.AsyncTestExecutor

AsyncTestContext

const AsyncTestContext = async_test.AsyncTestContext

AsyncTestResult

const AsyncTestResult = async_test.AsyncTestResult

AsyncHooksManager

const AsyncHooksManager = async_test.AsyncHooksManager

AsyncOptions

const AsyncOptions = async_test.AsyncOptions

AsyncStatus

const AsyncStatus = async_test.AsyncStatus

AsyncStats

const AsyncStats = async_test.AsyncStats

TimeoutContext

const TimeoutContext = timeout.TimeoutContext

TimeoutEnforcer

const TimeoutEnforcer = timeout.TimeoutEnforcer

TimeoutConfig

const TimeoutConfig = timeout.TimeoutConfig

GlobalTimeoutConfig

const GlobalTimeoutConfig = timeout.GlobalTimeoutConfig

TimeoutStatus

const TimeoutStatus = timeout.TimeoutStatus

TimeoutResult

const TimeoutResult = timeout.TimeoutResult

SuiteTimeoutTracker

const SuiteTimeoutTracker = timeout.SuiteTimeoutTracker

Spinner

const Spinner = progress.Spinner

SpinnerStyle

const SpinnerStyle = progress.SpinnerStyle

ProgressBar

const ProgressBar = progress.ProgressBar

ProgressBarStyle

const ProgressBarStyle = progress.ProgressBarStyle

TestProgress

const TestProgress = progress.TestProgress

MultiSpinner

const MultiSpinner = progress.MultiSpinner

TimeMock

const TimeMock = time.TimeMock

DateHelper

const DateHelper = time.DateHelper

setSystemTime

const setSystemTime = time.setSystemTime

useFakeTimers

const useFakeTimers = time.useFakeTimers

useRealTimers

const useRealTimers = time.useRealTimers

advanceTimersByTime

const advanceTimersByTime = time.advanceTimersByTime

createDateHelper

const createDateHelper = time.createDateHelper

cleanupTimeMock

const cleanupTimeMock = time.cleanupTimeMock

jest

const jest = struct

setSystemTime

const setSystemTime = time.jest.setSystemTime

useFakeTimers

const useFakeTimers = time.jest.useFakeTimers

useRealTimers

const useRealTimers = time.jest.useRealTimers

now

const now = time.jest.now

advanceTimersByTime

const advanceTimersByTime = time.jest.advanceTimersByTime

clearAllTimers

const clearAllTimers = time.jest.clearAllTimers

runAllTimers

const runAllTimers = time.jest.runAllTimers

runOnlyPendingTimers

const runOnlyPendingTimers = time.jest.runOnlyPendingTimers

getRegistry

fn getRegistry(allocator: std.mem.Allocator) *TestRegistry

cleanupRegistry

fn cleanupRegistry() void

assertions

AssertionError

const AssertionError = error

Custom error for assertion failures

Expectation

fn Expectation(comptime T: type) type

Expectation struct that holds the actual value and provides assertion methods

not

fn not(self: Self) Self

Create a negated expectation

withMessage

fn withMessage(self: Self, message: []const u8) Self

Set a custom error message

toBe

fn toBe(self: Self, expected: T) !void

Assert strict equality (===)

toEqual

fn toEqual(self: Self, expected: T) !void

Assert deep equality

toBeTruthy

fn toBeTruthy(self: Self) !void

Assert value is true (for bools)

toBeFalsy

fn toBeFalsy(self: Self) !void

Assert value is false (for bools)

toBeNull

fn toBeNull(self: Self) !void

Assert value is null (for optionals)

toBeDefined

fn toBeDefined(self: Self) !void

Assert value is not null (for optionals)

toBeGreaterThan

fn toBeGreaterThan(self: Self, expected: T) !void

Assert greater than

toBeGreaterThanOrEqual

fn toBeGreaterThanOrEqual(self: Self, expected: T) !void

Assert greater than or equal

toBeLessThan

fn toBeLessThan(self: Self, expected: T) !void

Assert less than

toBeLessThanOrEqual

fn toBeLessThanOrEqual(self: Self, expected: T) !void

Assert less than or equal

toThrow

fn toThrow(self: Self) !void

Assert that a function throws an error Usage: try expect(allocator, myFunction).toThrow()

toThrowError

fn toThrowError(self: Self, expected_error: anyerror) !void

Assert that a function throws a specific error Usage: try expect(allocator, myFunction).toThrowError(error.MyError)

StringExpectation

const StringExpectation = struct

String-specific expectation methods

not

fn not(self: Self) Self

withMessage

fn withMessage(self: Self, message: []const u8) Self

toBe

fn toBe(self: Self, expected: []const u8) !void

toEqual

fn toEqual(self: Self, expected: []const u8) !void

toContain

fn toContain(self: Self, substring: []const u8) !void

toStartWith

fn toStartWith(self: Self, prefix: []const u8) !void

toEndWith

fn toEndWith(self: Self, suffix: []const u8) !void

toHaveLength

fn toHaveLength(self: Self, expected_length: usize) !void

toBeEmpty

fn toBeEmpty(self: Self) !void

SliceExpectation

fn SliceExpectation(comptime T: type) type

Slice expectation methods

not

fn not(self: Self) Self

toHaveLength

fn toHaveLength(self: Self, expected_length: usize) !void

toContain

fn toContain(self: Self, item: T) !void

toBeEmpty

fn toBeEmpty(self: Self) !void

expect

fn expect(allocator: std.mem.Allocator, actual: anytype) blk:

Create an expectation for a value

suite

TestError

const TestError = error

TestFn

const TestFn = *const fn (allocator: std.mem.Allocator) anyerror!void

Test function type

HookFn

const HookFn = *const fn (allocator: std.mem.Allocator) anyerror!void

Hook function type

TestType

const TestType = enum

Test type

TestStatus

const TestStatus = enum

Test status

TestCase

const TestCase = struct

Individual test case

init

fn init(name: []const u8, test_fn: TestFn) TestCase

initWithTimeout

fn initWithTimeout(name: []const u8, test_fn: TestFn, timeout_ms: u64) TestCase

initAsync

fn initAsync(name: []const u8, test_fn: TestFn, timeout_ms: u64) TestCase

TestSuite

const TestSuite = struct

Test suite (describe block)

init

fn init(allocator: std.mem.Allocator, name: []const u8) !*Self

deinit

fn deinit(self: *Self) void

addTest

fn addTest(self: *Self, test_case: TestCase) !void

Add a test to this suite

addSuite

fn addSuite(self: *Self, suite: *TestSuite) !void

Add a nested suite

addBeforeEach

fn addBeforeEach(self: *Self, hook: HookFn) !void

Add a beforeEach hook

addAfterEach

fn addAfterEach(self: *Self, hook: HookFn) !void

Add an afterEach hook

addBeforeAll

fn addBeforeAll(self: *Self, hook: HookFn) !void

Add a beforeAll hook

addAfterAll

fn addAfterAll(self: *Self, hook: HookFn) !void

Add an afterAll hook

getAllBeforeEachHooks

fn getAllBeforeEachHooks(self: *Self, allocator: std.mem.Allocator) !std.ArrayList(HookFn)

Get all beforeEach hooks including parent hooks

getAllAfterEachHooks

fn getAllAfterEachHooks(self: *Self, allocator: std.mem.Allocator) !std.ArrayList(HookFn)

Get all afterEach hooks including parent hooks

runBeforeAllHooks

fn runBeforeAllHooks(self: *Self, allocator: std.mem.Allocator) !void

Run all beforeAll hooks

runAfterAllHooks

fn runAfterAllHooks(self: *Self, allocator: std.mem.Allocator) !void

Run all afterAll hooks

shouldSkip

fn shouldSkip(self: *Self) bool

Check if this suite should be skipped

hasOnly

fn hasOnly(self: *Self) bool

Check if only this suite (or a parent) is marked as only

countTests

fn countTests(self: *Self) usize

Count total tests in this suite and nested suites

TestRegistry

const TestRegistry = struct

Global test registry

init

fn init(allocator: std.mem.Allocator) Self

deinit

fn deinit(self: *Self) void

registerSuite

fn registerSuite(self: *Self, suite: *TestSuite) !void

Register a new suite

registerTest

fn registerTest(self: *Self, test_case: TestCase) !void

Register a test in the current suite

countAllTests

fn countAllTests(self: *Self) usize

Count total tests across all suites

getRegistry

fn getRegistry(allocator: std.mem.Allocator) *TestRegistry

Get the global test registry

cleanupRegistry

fn cleanupRegistry() void

Clean up the global test registry

describe

fn describe(allocator: std.mem.Allocator, name: []const u8, func: anytype) !void

Helper to create a test suite (describe)

it

fn it(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn) !void

Helper to create a test case (it/test)

test_

const test_ = it

Alias for it

describeSkip

fn describeSkip(allocator: std.mem.Allocator, name: []const u8, func: anytype) !void

Skip a describe block

describeOnly

fn describeOnly(allocator: std.mem.Allocator, name: []const u8, func: anytype) !void

Only run this describe block

itSkip

fn itSkip(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn) !void

Skip a test

itOnly

fn itOnly(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn) !void

Only run this test

itTimeout

fn itTimeout(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn, timeout_ms: u64) !void

Register a test with timeout

itAsync

fn itAsync(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn) !void

Register an async test

itAsyncTimeout

fn itAsyncTimeout(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn, timeout_ms: u64) !void

Register an async test with custom timeout

itAsyncSkip

fn itAsyncSkip(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn) !void

Skip an async test

itAsyncOnly

fn itAsyncOnly(allocator: std.mem.Allocator, name: []const u8, test_fn: TestFn) !void

Only run this async test

describeTimeout

fn describeTimeout(allocator: std.mem.Allocator, name: []const u8, timeout_ms: u64, func: anytype) !void

Create a suite with timeout

beforeEach

fn beforeEach(allocator: std.mem.Allocator, hook: HookFn) !void

Add beforeEach hook

afterEach

fn afterEach(allocator: std.mem.Allocator, hook: HookFn) !void

Add afterEach hook

beforeAll

fn beforeAll(allocator: std.mem.Allocator, hook: HookFn) !void

Add beforeAll hook

afterAll

fn afterAll(allocator: std.mem.Allocator, hook: HookFn) !void

Add afterAll hook

test_runner

RunnerError

const RunnerError = error

RunnerOptions

const RunnerOptions = struct

ReporterType

const ReporterType = enum

TestRunner

const TestRunner = struct

init

fn init(allocator: std.mem.Allocator, registry: *suite.TestRegistry, options: RunnerOptions) Self

deinit

fn deinit(self: *Self) void

run

fn run(self: *Self) !bool

Run all registered tests

runTests

fn runTests(allocator: std.mem.Allocator, registry: *suite.TestRegistry) !bool

Helper function to run tests with default options

runTestsWithOptions

fn runTestsWithOptions(allocator: std.mem.Allocator, registry: *suite.TestRegistry, options: RunnerOptions) !bool

Helper function to run tests with custom options

reporter

Colors

const Colors = struct

ANSI color codes

reset

const reset = "\x1b[0m"

bold

const bold = "\x1b[1m"

dim

const dim = "\x1b[2m"

red

const red = "\x1b[31m"

green

const green = "\x1b[32m"

yellow

const yellow = "\x1b[33m"

blue

const blue = "\x1b[34m"

magenta

const magenta = "\x1b[35m"

cyan

const cyan = "\x1b[36m"

white

const white = "\x1b[37m"

gray

const gray = "\x1b[90m"

Reporter

const Reporter = struct

Reporter interface

VTable

const VTable = struct

onRunStart

fn onRunStart(self: *Self, total_tests: usize) !void

onRunEnd

fn onRunEnd(self: *Self, results: *TestResults) !void

onSuiteStart

fn onSuiteStart(self: *Self, suite_name: []const u8) !void

onSuiteEnd

fn onSuiteEnd(self: *Self, suite_name: []const u8) !void

onTestStart

fn onTestStart(self: *Self, test_name: []const u8) !void

onTestEnd

fn onTestEnd(self: *Self, test_case: *const suite.TestCase) !void

TestResults

const TestResults = struct

Test results summary

init

fn init(allocator: std.mem.Allocator) TestResults

deinit

fn deinit(self: *TestResults) void

addTest

fn addTest(self: *TestResults, test_case: *const suite.TestCase) !void

SpecReporter

const SpecReporter = struct

Default/Spec reporter

init

fn init(allocator: std.mem.Allocator, writer: std.Io.Writer) Self

DotReporter

const DotReporter = struct

Dot reporter (minimal output)

init

fn init(allocator: std.mem.Allocator, writer: std.Io.Writer) Self

JsonReporter

const JsonReporter = struct

JSON reporter

init

fn init(allocator: std.mem.Allocator, writer: std.Io.Writer) Self

deinit

fn deinit(s: *Self) void

TAPReporter

const TAPReporter = struct

TAP (Test Anything Protocol) reporter

init

fn init(allocator: std.mem.Allocator, writer: std.Io.Writer) Self

JUnitReporter

const JUnitReporter = struct

JUnit XML reporter

deinit

fn deinit(self: *TestSuiteResult, allocator: std.mem.Allocator) void

init

fn init(allocator: std.mem.Allocator, output_file: []const u8) Self

deinit

fn deinit(self: *Self) void

matchers

Matchers

const Matchers = struct

Extended matchers for advanced assertions

init

fn init(allocator: std.mem.Allocator) Self

toBeCloseTo

fn toBeCloseTo(actual: f64, expected: f64, precision: u32) !void

Check if a float is close to another value within a precision

toBeNaN

fn toBeNaN(actual: f64) !void

Check if a value is NaN

toBeInfinite

fn toBeInfinite(actual: f64) !void

Check if a value is infinite

toBePositiveInfinity

fn toBePositiveInfinity(actual: f64) !void

Check if a value is positive infinity

toBeNegativeInfinity

fn toBeNegativeInfinity(actual: f64) !void

Check if a value is negative infinity

StructMatcher

fn StructMatcher(comptime T: type) type

Struct matcher for checking properties

init

fn init(allocator: std.mem.Allocator, actual: T) Self

toHaveField

fn toHaveField(self: Self, comptime field_name: []const u8, expected_value: anytype) !void

Check if struct has a specific field with a value

toMatchObject

fn toMatchObject(self: Self, expected: anytype) !void

Check if struct matches a subset of properties

ArrayMatcher

fn ArrayMatcher(comptime T: type) type

Array matcher for advanced array assertions

init

fn init(allocator: std.mem.Allocator, actual: []const T) Self

toContainEqual

fn toContainEqual(self: Self, expected_item: T) !void

Check if array contains an item with deep equality

toContain

const toContain = toContainEqual

Alias for toContainEqual

toContainAll

fn toContainAll(self: Self, expected_items: []const T) !void

Check if array contains all specified items

toHaveLength

fn toHaveLength(self: Self, expected_length: usize) !void

Check if array has exact length

toBeEmpty

fn toBeEmpty(self: Self) !void

Check if array is empty

toBeSorted

fn toBeSorted(self: Self) !void

Check if array is sorted

expectStruct

fn expectStruct(allocator: std.mem.Allocator, actual: anytype) StructMatcher(@TypeOf(actual))

Helper to create struct matcher

expectArray

fn expectArray(allocator: std.mem.Allocator, actual: anytype) ArrayMatcher(std.meta.Child(@TypeOf(actual.*)))

Helper to create array matcher

mock

MockResult

const MockResult = union(enum)

Result type for mock function calls

isReturn

fn isReturn(self: MockResult) bool

isError

fn isError(self: MockResult) bool

CallRecord

const CallRecord = struct

Mock function call record

init

fn init(allocator: std.mem.Allocator, args: []const u8) !CallRecord

deinit

fn deinit(self: *CallRecord, allocator: std.mem.Allocator) void

MockRegistry

const MockRegistry = struct

Global mock registry for tracking all mocks

init

fn init(allocator: std.mem.Allocator) MockRegistry

deinit

fn deinit(self: *MockRegistry) void

register

fn register(self: *MockRegistry, mock_ptr: *anyopaque) !void

clearAll

fn clearAll(self: *MockRegistry) void

getGlobalRegistry

fn getGlobalRegistry(allocator: std.mem.Allocator) *MockRegistry

cleanupGlobalRegistry

fn cleanupGlobalRegistry() void

Mock

fn Mock(comptime ReturnType: type) type

Mock function tracker with comprehensive Bun-compatible API

init

fn init(allocator: std.mem.Allocator) Self

deinit

fn deinit(self: *Self) void

getMockName

fn getMockName(self: *Self) []const u8

Get the mock name

mockName

fn mockName(self: *Self, name: []const u8) *Self

Set the mock name

getCalls

fn getCalls(self: *Self) []CallRecord

Get all calls made to this mock

getResults

fn getResults(self: *Self) []MockResult

Get all results from mock calls

getLastCall

fn getLastCall(self: *Self) ?CallRecord

Get the last call arguments

recordCall

fn recordCall(self: *Self, args_str: []const u8) !void

Record a function call

recordCallWithResult

fn recordCallWithResult(self: *Self, args_str: []const u8, result: MockResult) !void

Record a call with a result

mockReturnValue

fn mockReturnValue(self: *Self, value: ReturnType) !*Self

Set a return value to be used for all subsequent calls

mockReturnValueOnce

fn mockReturnValueOnce(self: *Self, value: ReturnType) !*Self

Set a return value to be used once

mockReturnValues

fn mockReturnValues(self: *Self, values: []const ReturnType) !*Self

Set multiple return values

mockReturnThis

fn mockReturnThis(self: *Self) *Self

Mock return value as 'this' context (for method chaining)

getReturnValue

fn getReturnValue(self: *Self) ?ReturnType

Get the next return value

mockImplementation

fn mockImplementation(self: *Self, impl: *const fn () anyerror!ReturnType) *Self

Set a custom implementation

mockImplementationOnce

fn mockImplementationOnce(self: *Self, impl: *const fn () anyerror!ReturnType) !*Self

Set implementation for the next call only

withImplementation

fn withImplementation(

Temporarily change implementation for a callback

getImplementation

fn getImplementation(self: *Self) ?*const fn () anyerror!ReturnType

Get the current or next implementation

mockResolvedValue

fn mockResolvedValue(self: *Self, value: ReturnType) !*Self

Mock a resolved promise value

mockResolvedValueOnce

fn mockResolvedValueOnce(self: *Self, value: ReturnType) !*Self

Mock a resolved promise value once

mockRejectedValue

fn mockRejectedValue(self: *Self, error_msg: []const u8) !*Self

Mock a rejected promise (error)

mockRejectedValueOnce

fn mockRejectedValueOnce(self: *Self, error_msg: []const u8) !*Self

Mock a rejected promise once

mockClear

fn mockClear(self: *Self) *Self

Clear all call history but keep implementation

mockReset

fn mockReset(self: *Self) *Self

Reset to initial state (clear calls and remove implementation)

mockRestore

fn mockRestore(self: *Self) *Self

Restore the original implementation (for spies)

callCount

fn callCount(self: *Self) usize

Get call count

toHaveBeenCalled

fn toHaveBeenCalled(self: *Self) !void

Check if mock was called

toHaveBeenCalledTimes

fn toHaveBeenCalledTimes(self: *Self, expected_count: usize) !void

Check if mock was called n times

toHaveBeenCalledWith

fn toHaveBeenCalledWith(self: *Self, expected_args: []const u8) !void

Check if mock was called with specific arguments

toHaveBeenLastCalledWith

fn toHaveBeenLastCalledWith(self: *Self, expected_args: []const u8) !void

Check if the last call was with specific arguments

toHaveBeenNthCalledWith

fn toHaveBeenNthCalledWith(self: *Self, call_number: usize, expected_args: []const u8) !void

Check if the nth call was with specific arguments (1-indexed)

toHaveReturnedWith

fn toHaveReturnedWith(self: *Self, expected_value: ReturnType) !void

Check if mock returned a specific value

toHaveLastReturnedWith

fn toHaveLastReturnedWith(self: *Self, expected_value: ReturnType) !void

Check if the last call returned a specific value

toHaveNthReturnedWith

fn toHaveNthReturnedWith(self: *Self, call_number: usize, expected_value: ReturnType) !void

Check if the nth call returned a specific value

Spy

fn Spy(comptime FnType: type) type

Spy on an existing function (wrapper that records calls)

init

fn init(allocator: std.mem.Allocator, original: FnType) Self

deinit

fn deinit(self: *Self) void

call

fn call(self: *Self, args_str: []const u8) !void

Record a call and call the original function

callCount

fn callCount(self: *Self) usize

Get call count

mockRestore

fn mockRestore(self: *Self) ?FnType

Restore the original function

mockImplementation

fn mockImplementation(self: *Self, impl: *const fn () anyerror!?FnType) *Self

Override the spy's implementation

mockImplementationOnce

fn mockImplementationOnce(self: *Self, impl: *const fn () anyerror!?FnType) !*Self

Override implementation once

mockReturnValue

fn mockReturnValue(self: *Self, value: ?FnType) !*Self

Set return value

mockReturnValueOnce

fn mockReturnValueOnce(self: *Self, value: ?FnType) !*Self

Set return value once

mockResolvedValue

fn mockResolvedValue(self: *Self, value: ?FnType) !*Self

Mock resolved value (for async)

mockResolvedValueOnce

fn mockResolvedValueOnce(self: *Self, value: ?FnType) !*Self

Mock resolved value once

mockClear

fn mockClear(self: *Self) *Self

Clear call history

mockReset

fn mockReset(self: *Self) *Self

Reset the spy

toHaveBeenCalled

fn toHaveBeenCalled(self: *Self) !void

toHaveBeenCalledTimes

fn toHaveBeenCalledTimes(self: *Self, expected_count: usize) !void

toHaveBeenCalledWith

fn toHaveBeenCalledWith(self: *Self, expected_args: []const u8) !void

toHaveBeenLastCalledWith

fn toHaveBeenLastCalledWith(self: *Self, expected_args: []const u8) !void

toHaveBeenNthCalledWith

fn toHaveBeenNthCalledWith(self: *Self, call_number: usize, expected_args: []const u8) !void

getCalls

fn getCalls(self: *Self) []CallRecord

Get all calls

getLastCall

fn getLastCall(self: *Self) ?CallRecord

Get last call

clearAllMocks

fn clearAllMocks() void

Clear all mocks (call history only, preserves implementations)

restoreAllMocks

fn restoreAllMocks() void

Restore all mocks to their original implementations

resetAllMocks

fn resetAllMocks() void

Reset all mocks (clear history and remove implementations)

createMock

fn createMock(allocator: std.mem.Allocator, comptime T: type) Mock(T)

Create a mock function (Bun/Jest-compatible)

createSpy

fn createSpy(allocator: std.mem.Allocator, comptime T: type, original: T) Spy(T)

Create a spy on a function (Bun/Jest-compatible)

fn_

const fn_ = createMock

Alias for Jest compatibility

spyOn

const spyOn = createSpy

cli

CLIOptions

const CLIOptions = struct

CLIError

const CLIError = error

CLI

const CLI = struct

init

fn init(allocator: std.mem.Allocator) Self

parse

fn parse(self: *Self, args: []const []const u8) !void

Parse command-line arguments

printHelp

fn printHelp(self: Self) void

Print help message

printVersion

fn printVersion(self: Self) void

Print version information

toRunnerOptions

fn toRunnerOptions(self: Self) test_runner.RunnerOptions

Convert CLI options to RunnerOptions

discovery

DiscoveryOptions

const DiscoveryOptions = struct

Test file discovery options

TestFile

const TestFile = struct

Discovered test file

deinit

fn deinit(self: *TestFile, allocator: std.mem.Allocator) void

DiscoveryResult

const DiscoveryResult = struct

Test file discovery result

init

fn init(allocator: std.mem.Allocator) DiscoveryResult

deinit

fn deinit(self: *DiscoveryResult) void

addFile

fn addFile(self: *DiscoveryResult, path: []const u8, relative_path: []const u8, name: []const u8) !void

discoverTests

fn discoverTests(allocator: std.mem.Allocator, options: DiscoveryOptions) !DiscoveryResult

Discover test files in a directory

test_loader

LoaderOptions

const LoaderOptions = struct

Options for running discovered tests

runDiscoveredTests

fn runDiscoveredTests(

Run all discovered test files

coverage

CoverageOptions

const CoverageOptions = struct

Coverage collection options

CoverageTool

const CoverageTool = enum

Coverage tool to use

CoverageResult

const CoverageResult = struct

Coverage result summary

linePercentage

fn linePercentage(self: CoverageResult) f64

Calculate line coverage percentage

functionPercentage

fn functionPercentage(self: CoverageResult) f64

Calculate function coverage percentage

branchPercentage

fn branchPercentage(self: CoverageResult) f64

Calculate branch coverage percentage

isCoverageToolAvailable

fn isCoverageToolAvailable(allocator: std.mem.Allocator, tool: CoverageTool) !bool

Check if coverage tool is available

runWithCoverage

fn runWithCoverage(

Run a test executable with coverage collection

runTestWithCoverage

fn runTestWithCoverage(

Run test file with coverage using zig test --test-cmd

parseCoverageReport

fn parseCoverageReport(allocator: std.mem.Allocator, coverage_dir: []const u8) !CoverageResult

Parse kcov coverage report to extract metrics

printCoverageSummary

fn printCoverageSummary(result: CoverageResult) void

Print coverage summary to console

parallel

ParallelOptions

const ParallelOptions = struct

Options for parallel test execution

TestResult

const TestResult = struct

Result from running a test in parallel

ParallelContext

const ParallelContext = struct

Context for parallel test execution

init

fn init(allocator: std.mem.Allocator, rep: *reporter.Reporter) ParallelContext

deinit

fn deinit(self: *ParallelContext) void

TestTask

const TestTask = struct

Task for executing a single test

run

fn run(self: *TestTask) void

runTestsParallel

fn runTestsParallel(

Run tests in parallel using thread pool

ui_server

UIServerOptions

const UIServerOptions = struct

Options for the UI server

UIServer

const UIServer = struct

UI Server for web-based test visualization Note: std.net was removed in Zig 0.16. Server functionality is stubbed out until the new Io-based networking API stabilizes.

init

fn init(allocator: std.mem.Allocator, options: UIServerOptions) Self

deinit

fn deinit(self: *Self) void

start

fn start(self: *Self) !void

Start the UI server (stubbed - std.net removed in Zig 0.16)

acceptClient

fn acceptClient(self: *Self) !void

Accept a client connection (stubbed)

broadcast

fn broadcast(self: *Self, event: []const u8, data: []const u8) !void

Broadcast an event to all connected clients (stubbed)

UIReporter

const UIReporter = struct

UI Reporter - sends test events to the UI server

init

fn init(allocator: std.mem.Allocator, server: *UIServer) Self

deinit

fn deinit(self: *Self) void

MultiReporter

const MultiReporter = struct

Multi-Reporter - broadcasts events to multiple reporters

init

fn init(allocator: std.mem.Allocator, reporters: []*reporter_mod.Reporter) Self

test_history

HistoryEntry

const HistoryEntry = struct

Test history entry

deinit

fn deinit(self: *HistoryEntry, allocator: std.mem.Allocator) void

TestRecord

const TestRecord = struct

Individual test record

deinit

fn deinit(self: *TestRecord, allocator: std.mem.Allocator) void

TestHistory

const TestHistory = struct

Test history manager

init

fn init(allocator: std.mem.Allocator, history_dir: []const u8) Self

deinit

fn deinit(self: *Self) void

startRun

fn startRun(self: *Self, total: usize) !void

Start recording a new test run

recordTest

fn recordTest(

Record a test result

finishRun

fn finishRun(self: *Self, results: *reporter_mod.TestResults) !void

Finish the test run and save to file

listHistory

fn listHistory(self: *Self) !std.ArrayList([]const u8)

Get list of all history files Note: Directory iteration needs Io in Zig 0.16, stubbed for now

loadHistory

fn loadHistory(self: *Self, filename: []const u8) !HistoryEntry

Load a specific history entry

cleanOldHistory

fn cleanOldHistory(self: *Self, keep_count: usize) !void

Clean old history files (keep last N)

snapshot

SnapshotFormat

const SnapshotFormat = enum

Snapshot format type

SnapshotOptions

const SnapshotOptions = struct

Snapshot testing options

DiffEntry

const DiffEntry = struct

Snapshot diff entry

deinit

fn deinit(self: *DiffEntry) void

SnapshotDiff

const SnapshotDiff = struct

Snapshot diff result

init

fn init(allocator: std.mem.Allocator) SnapshotDiff

deinit

fn deinit(self: *SnapshotDiff) void

addDiff

fn addDiff(self: *SnapshotDiff, line_number: usize, expected: []const u8, received: []const u8) !void

print

fn print(self: *SnapshotDiff) void

InlineSnapshot

const InlineSnapshot = struct

Inline snapshot marker

init

fn init(allocator: std.mem.Allocator, file_path: []const u8, line_number: usize, value: []const u8) !InlineSnapshot

deinit

fn deinit(self: *InlineSnapshot) void

Snapshot

const Snapshot = struct

Snapshot matcher

init

fn init(allocator: std.mem.Allocator, test_name: []const u8, options: SnapshotOptions) Self

matchString

fn matchString(self: *Self, value: []const u8) !void

Match a string value against a snapshot

matchStringNamed

fn matchStringNamed(self: *Self, name: []const u8, value: []const u8) !void

Match a string with a specific name

match

fn match(self: *Self, value: anytype) !void

Match any value against a snapshot (converts to string)

matchNamed

fn matchNamed(self: *Self, name: []const u8, value: anytype) !void

Match any value with a specific name

matchInline

fn matchInline(self: *Self, file_path: []const u8, line_number: usize, value: anytype) !void

Match inline snapshot

SnapshotCleanup

const SnapshotCleanup = struct

Snapshot cleanup utility

init

fn init(allocator: std.mem.Allocator, snapshot_dir: []const u8) Self

deinit

fn deinit(self: *Self) void

markUsed

fn markUsed(self: *Self, snapshot_name: []const u8) !void

Mark a snapshot as used

cleanupUnused

fn cleanupUnused(self: *Self) !usize

Find and remove unused snapshots

listSnapshots

fn listSnapshots(self: *Self) !std.ArrayList([]const u8)

List all snapshot files

snapshot

fn snapshot(allocator: std.mem.Allocator, test_name: []const u8, options: SnapshotOptions) Snapshot

Create a snapshot matcher for a test

watch

WatchOptions

const WatchOptions = struct

Watch mode options

TestWatcher

const TestWatcher = struct

File watcher for test files

init

fn init(allocator: std.mem.Allocator, options: WatchOptions, running: *std.atomic.Value(bool)) Self

watch

fn watch(self: *Self, loader_options: test_loader.LoaderOptions) !void

Start watching for file changes

FileWatcher

const FileWatcher = struct

Simple file watcher using polling Note: In production, use std.fs.Watch or platform-specific APIs (inotify, kqueue, etc.)

init

fn init(allocator: std.mem.Allocator) Self

deinit

fn deinit(self: *Self) void

addPath

fn addPath(self: *Self, path: []const u8) !void

Add a path to watch

hasChanges

fn hasChanges(self: *Self) !bool

Check if any watched files have changed

memory_profiler

ProfileOptions

const ProfileOptions = struct

Memory profiling options

MemoryStats

const MemoryStats = struct

Memory statistics for a single test

hasLeak

fn hasLeak(self: MemoryStats) bool

format

fn format(

ProfilingAllocator

const ProfilingAllocator = struct

Profiling allocator that tracks memory usage

init

fn init(parent_allocator: std.mem.Allocator, stats: *MemoryStats) Self

allocator

fn allocator(self: *Self) std.mem.Allocator

MemoryProfiler

const MemoryProfiler = struct

Memory profiler for tests

init

fn init(allocator: std.mem.Allocator, options: ProfileOptions) Self

deinit

fn deinit(self: *Self) void

createTestAllocator

fn createTestAllocator(self: *Self, test_name: []const u8) !ProfilingAllocator

Create a profiling allocator for a test

getStats

fn getStats(self: *Self, test_name: []const u8) ?MemoryStats

Get statistics for a test

finalizeTest

fn finalizeTest(self: *Self, test_name: []const u8, stats: MemoryStats) !void

Update final stats for a test

printReport

fn printReport(self: *Self) !void

Print memory report

hasLeaks

fn hasLeaks(self: *Self) bool

Check if any tests have memory leaks

formatBytes

fn formatBytes(bytes: usize) []const u8

Format bytes in human-readable format

config

ConfigFormat

const ConfigFormat = enum

Configuration file format

TestConfig

const TestConfig = struct

Test framework configuration

TestOptions

const TestOptions = struct

ParallelOptions

const ParallelOptions = struct

ReporterOptions

const ReporterOptions = struct

SnapshotOptions

const SnapshotOptions = struct

WatchOptions

const WatchOptions = struct

MemoryOptions

const MemoryOptions = struct

UIOptions

const UIOptions = struct

CoverageOptions

const CoverageOptions = struct

ConfigLoader

const ConfigLoader = struct

Configuration loader

init

fn init(allocator: std.mem.Allocator) Self

loadFromFile

fn loadFromFile(self: *Self, path: []const u8) !TestConfig

Load configuration from file

autoLoad

fn autoLoad(self: *Self, config_name: []const u8) !?TestConfig

Try to find and load configuration file

async_support

AsyncTestFn

const AsyncTestFn = *const fn (allocator: std.mem.Allocator) anyerror!void

Async/Await Support for Zig Test Framework

NOTE: Zig's async/await is still experimental and subject to change. This module provides basic utilities for async testing until Zig's async stabilizes. For now, we provide thread-based async simulation. Async test function signature

Future

fn Future(comptime T: type) type

Future-like type for async operations

init

fn init() Self

await_value

fn await_value(self: *Self) !T

Wait for the future to complete and get the result

resolve

fn resolve(self: *Self, value: T) void

Complete the future with a value

reject

fn reject(self: *Self, err: anyerror) void

Complete the future with an error

isCompleted

fn isCompleted(self: *Self) bool

Check if the future is completed

Promise

fn Promise(comptime T: type) type

Promise type for creating async operations

init

fn init() Self

resolve

fn resolve(self: *Self, value: T) void

reject

fn reject(self: *Self, err: anyerror) void

getFuture

fn getFuture(self: *Self) *Future(T)

runAsync

fn runAsync(allocator: std.mem.Allocator, func: AsyncTestFn) !void

Run an async test function

AsyncExecutor

const AsyncExecutor = struct

Async executor for running multiple async operations concurrently

init

fn init(allocator: std.mem.Allocator) Self

deinit

fn deinit(self: *Self) void

spawn

fn spawn(self: *Self, comptime func: anytype, args: anytype) !void

Spawn an async task

waitAll

fn waitAll(self: *Self) void

Wait for all spawned tasks to complete

delay

fn delay(ms: u64) void

Delay for async operations

all

fn all(comptime T: type, allocator: std.mem.Allocator, futures: [](*Future(T))) ![]T

Run multiple futures concurrently and wait for all to complete

race

fn race(comptime T: type, futures: [](*Future(T))) !T

Run multiple futures concurrently and return the first completed

timeout

fn timeout(comptime T: type, future: *Future(T), timeout_ms: u64) !T

Timeout wrapper for async operations

async_test

AsyncTestFn

const AsyncTestFn = *const fn (allocator: std.mem.Allocator) anyerror!void

Async test function signature

AsyncHookFn

const AsyncHookFn = *const fn (allocator: std.mem.Allocator) anyerror!void

Async hook function signature

AsyncOptions

const AsyncOptions = struct

Async test execution options

AsyncStatus

const AsyncStatus = enum

Async test status

AsyncTestResult

const AsyncTestResult = struct

Async test result

deinit

fn deinit(self: *AsyncTestResult) void

AsyncTestContext

const AsyncTestContext = struct

Async test context

init

fn init(allocator: std.mem.Allocator, name: []const u8, test_fn: AsyncTestFn, timeout_ms: u64) Self

run

fn run(self: *Self) void

isCompleted

fn isCompleted(self: *Self) bool

getResult

fn getResult(self: *Self) AsyncTestResult

AsyncTestExecutor

const AsyncTestExecutor = struct

Async test executor

init

fn init(allocator: std.mem.Allocator, options: AsyncOptions) Self

deinit

fn deinit(self: *Self) void

registerTest

fn registerTest(self: *Self, name: []const u8, test_fn: AsyncTestFn) !void

Register an async test

executeAll

fn executeAll(self: *Self) ![]AsyncTestResult

Execute all registered async tests

getStats

fn getStats(results: []const AsyncTestResult) AsyncStats

Get test statistics

AsyncStats

const AsyncStats = struct

Async test statistics

format

fn format(

AsyncHooksManager

const AsyncHooksManager = struct

Async hooks manager

init

fn init(allocator: std.mem.Allocator) Self

runBeforeAll

fn runBeforeAll(self: *Self) !void

runAfterAll

fn runAfterAll(self: *Self) !void

runBeforeEach

fn runBeforeEach(self: *Self) !void

runAfterEach

fn runAfterEach(self: *Self) !void

timeout

GlobalTimeoutConfig

const GlobalTimeoutConfig = struct

Global timeout configuration

TimeoutConfig

const TimeoutConfig = struct

Timeout configuration

TimeoutStatus

const TimeoutStatus = enum

Timeout status

TimeoutResult

const TimeoutResult = struct

Timeout result

deinit

fn deinit(self: *TimeoutResult) void

format

fn format(

TimeoutContext

const TimeoutContext = struct

Timeout context for tracking test execution time

init

fn init(allocator: std.mem.Allocator, timeout_ms: u64) Self

start

fn start(self: *Self) void

Start the timeout timer

isTimedOut

fn isTimedOut(self: *Self) bool

Check if timeout has been exceeded

getElapsedMs

fn getElapsedMs(self: *Self) u64

Get elapsed time in milliseconds

getRemainingMs

fn getRemainingMs(self: *Self) u64

Get remaining time in milliseconds

extend

fn extend(self: *Self, additional_ms: u64) !void

Extend the timeout by specified milliseconds

complete

fn complete(self: *Self) void

Mark as completed

markTimedOut

fn markTimedOut(self: *Self) void

Mark as timed out

getResult

fn getResult(self: *Self) !TimeoutResult

Get the timeout result

TimeoutEnforcer

const TimeoutEnforcer = struct

Timeout enforcer - monitors and enforces test timeouts

init

fn init(allocator: std.mem.Allocator, global_config: GlobalTimeoutConfig) Self

deinit

fn deinit(self: *Self) void

startMonitoring

fn startMonitoring(self: *Self) !void

Start monitoring timeouts

stop

fn stop(self: *Self) void

Stop monitoring

registerContext

fn registerContext(self: *Self, context: *TimeoutContext) !void

Register a timeout context for monitoring

unregisterContext

fn unregisterContext(self: *Self, context: *TimeoutContext) void

Unregister a timeout context

getEffectiveTimeout

fn getEffectiveTimeout(self: *Self, test_timeout_ms: u64, suite_timeout_ms: u64) u64

Get the effective timeout for a test

SuiteTimeoutTracker

const SuiteTimeoutTracker = struct

Suite timeout tracker

init

fn init(allocator: std.mem.Allocator, suite_name: []const u8, timeout_ms: u64) Self

isTimedOut

fn isTimedOut(self: *Self) bool

getElapsedMs

fn getElapsedMs(self: *Self) u64

incrementTest

fn incrementTest(self: *Self) void

incrementCompleted

fn incrementCompleted(self: *Self) void

getRemainingMs

fn getRemainingMs(self: *Self) u64

progress

SpinnerStyle

const SpinnerStyle = enum

Spinner style

frames

fn frames(self: SpinnerStyle) []const []const u8

ProgressBarStyle

const ProgressBarStyle = enum

Progress bar style

chars

fn chars(self: ProgressBarStyle) struct

Spinner

const Spinner = struct

Spinner for showing ongoing operations

init

fn init(allocator: std.mem.Allocator, message: []const u8, style: SpinnerStyle) !Self

deinit

fn deinit(self: *Self) void

start

fn start(self: *Self) !void

Start the spinner in a background thread

stop

fn stop(self: *Self) void

Stop the spinner

updateMessage

fn updateMessage(self: *Self, new_message: []const u8) !void

Update the spinner message

succeed

fn succeed(self: *Self, message: []const u8) void

Show success message and stop

fail

fn fail(self: *Self, message: []const u8) void

Show failure message and stop

warn

fn warn(self: *Self, message: []const u8) void

Show warning message and stop

info

fn info(self: *Self, message: []const u8) void

Show info message and stop

ProgressBar

const ProgressBar = struct

Progress bar for showing completion percentage

init

fn init(allocator: std.mem.Allocator, total: usize, options: struct

deinit

fn deinit(self: *Self) void

update

fn update(self: *Self, current: usize) void

Update progress

increment

fn increment(self: *Self) void

Increment progress by 1

finish

fn finish(self: *Self) void

Set progress to completion

TestProgress

const TestProgress = struct

Real-time test progress tracker

init

fn init(allocator: std.mem.Allocator, total_tests: usize, options: struct

deinit

fn deinit(self: *Self) void

startTest

fn startTest(self: *Self, test_name: []const u8) !void

Start a test

completeTest

fn completeTest(self: *Self, passed: bool, skipped: bool) void

Complete a test

getElapsedMs

fn getElapsedMs(self: *Self) i64

Get elapsed time in milliseconds

printSummary

fn printSummary(self: *Self) void

Print summary

MultiSpinner

const MultiSpinner = struct

Multi-spinner for parallel operations

init

fn init(allocator: std.mem.Allocator) Self

deinit

fn deinit(self: *Self) void

add

fn add(self: *Self, name: []const u8, message: []const u8) !void

Add a spinner

update

fn update(self: *Self, name: []const u8, message: []const u8) !void

Update a spinner

succeed

fn succeed(self: *Self, name: []const u8, message: []const u8) void

Complete a spinner with success

fail

fn fail(self: *Self, name: []const u8, message: []const u8) void

Complete a spinner with failure

time

TimeMock

const TimeMock = struct

Time mocking state

init

fn init(allocator: std.mem.Allocator) Self

Initialize the time mock

deinit

fn deinit(self: *Self) void

Clean up resources

useFakeTimers

fn useFakeTimers(self: *Self) *Self

Enable fake timers (Jest compatibility)

useRealTimers

fn useRealTimers(self: *Self) *Self

Disable fake timers and restore real time (Jest compatibility)

setSystemTime

fn setSystemTime(self: *Self, timestamp: ?i64) *Self

Set the system time to a specific timestamp

now

fn now(self: *Self) i64

Get current time (mocked or real)

advanceTimersByTime

fn advanceTimersByTime(self: *Self, ms: i64) *Self

Advance mocked time by milliseconds

clearAllTimers

fn clearAllTimers(self: *Self) *Self

Clear all timers (Jest compatibility - currently a no-op)

runAllTimers

fn runAllTimers(self: *Self) *Self

Run all timers (Jest compatibility - currently a no-op)

runOnlyPendingTimers

fn runOnlyPendingTimers(self: *Self) *Self

Run pending timers (Jest compatibility - currently a no-op)

getTimeMock

fn getTimeMock(allocator: std.mem.Allocator) *TimeMock

Get or create the global time mock

cleanupTimeMock

fn cleanupTimeMock() void

Clean up the global time mock

setSystemTime

fn setSystemTime(allocator: std.mem.Allocator, timestamp: ?i64) void

Set the system time globally (Bun-compatible API)

useFakeTimers

fn useFakeTimers(allocator: std.mem.Allocator) void

Enable fake timers globally (Jest-compatible API)

useRealTimers

fn useRealTimers(allocator: std.mem.Allocator) void

Disable fake timers globally (Jest-compatible API)

now

fn now(allocator: std.mem.Allocator) i64

Get current mocked or real time (Jest-compatible API)

advanceTimersByTime

fn advanceTimersByTime(allocator: std.mem.Allocator, ms: i64) void

Advance time by milliseconds (Jest-compatible API)

jest

const jest = struct

Jest-compatible namespace for time functions

setSystemTime

fn setSystemTime(allocator: std.mem.Allocator, timestamp: i64) void

Set the system time (Jest compatibility)

useFakeTimers

fn useFakeTimers(allocator: std.mem.Allocator) void

Enable fake timers (Jest compatibility)

useRealTimers

fn useRealTimers(allocator: std.mem.Allocator) void

Disable fake timers (Jest compatibility)

now

fn now(allocator: std.mem.Allocator) i64

Get current mocked time (Jest compatibility)

advanceTimersByTime

fn advanceTimersByTime(allocator: std.mem.Allocator, ms: i64) void

Advance time by milliseconds (Jest compatibility)

clearAllTimers

fn clearAllTimers(allocator: std.mem.Allocator) void

Clear all timers (Jest compatibility - no-op for now)

runAllTimers

fn runAllTimers(allocator: std.mem.Allocator) void

Run all timers (Jest compatibility - no-op for now)

runOnlyPendingTimers

fn runOnlyPendingTimers(allocator: std.mem.Allocator) void

Run pending timers (Jest compatibility - no-op for now)

DateHelper

const DateHelper = struct

Date helper functions for tests

fromDate

fn fromDate(year: u16, month: u8, day: u8) i64

Create a timestamp from year, month, day

fromISO

fn fromISO(iso_string: []const u8) !i64

Create a timestamp from ISO 8601 string (simplified)

getYear

fn getYear(timestamp: i64) u16

Get the current year from a timestamp

now

fn now(self: DateHelper) i64

Get the current timestamp (respects mocked time)

createDateHelper

fn createDateHelper(allocator: std.mem.Allocator) DateHelper

Create a date helper

compat

nanoTimestamp

fn nanoTimestamp() i128

Get current wall-clock time in nanoseconds since Unix epoch. Replaces std.time.nanoTimestamp() which was removed in Zig 0.16.

milliTimestamp

fn milliTimestamp() i64

Get current wall-clock time in milliseconds since Unix epoch. Replaces std.time.milliTimestamp() which was removed in Zig 0.16.

sleep

fn sleep(ns: u64) void

Sleep for the given number of nanoseconds. Replaces std.Thread.sleep() which was removed in Zig 0.16.

Mutex

const Mutex = struct

Simple spinlock mutex for use without Io. Replaces std.Thread.Mutex which was removed in Zig 0.16.

lock

fn lock(self: *Mutex) void

unlock

fn unlock(self: *Mutex) void

tryLock

fn tryLock(self: *Mutex) bool

readFileAlloc

fn readFileAlloc(allocator: std.mem.Allocator, path: []const u8) ![]const u8

Read entire file contents using POSIX APIs. Replaces std.fs.cwd().openFile() + file.readToEndAlloc().

writeFile

fn writeFile(allocator: std.mem.Allocator, path: []const u8, content: []const u8) !void

Write content to a file using POSIX APIs. Replaces std.fs.cwd().createFile() + file.writeAll().

deleteFile

fn deleteFile(allocator: std.mem.Allocator, path: []const u8) !void

Delete a file using POSIX APIs. Replaces std.fs.cwd().deleteFile().

makePath

fn makePath(allocator: std.mem.Allocator, path: []const u8) !void

Create directories recursively using POSIX APIs. Replaces std.fs.cwd().makePath().

DirEntry

const DirEntry = struct

Entry from directory iteration

DirIterator

const DirIterator = struct

A simple directory iterator using POSIX APIs. Replaces std.fs.openDirAbsolute() + dir.iterate() which was removed in Zig 0.16.

open

fn open(dir_path: []const u8) !DirIterator

next

fn next(self: *DirIterator) !?DirEntry

close

fn close(self: *DirIterator) void

StdBehavior

const StdBehavior = enum

Spawn behavior for stdout/stderr

SpawnResult

const SpawnResult = union(enum)

Result of spawning and waiting for a child process

spawnAndWait

fn spawnAndWait(

Spawn a child process and wait for it to complete. Replaces std.process.Child.init() + spawnAndWait() which was removed in Zig 0.16.

formatAlloc

fn formatAlloc(allocator: std.mem.Allocator, comptime fmt: []const u8, args: anytype) ![]const u8

Format into an ArrayList(u8) using the allocator. Replaces buffer.writer(allocator) pattern. Returns the formatted string as an owned slice.

ArrayListWriter

const ArrayListWriter = struct

A writer that appends to an ArrayList(u8), capturing the allocator. Replaces the removed ArrayList.writer(allocator) API in Zig 0.16.

init

fn init(list: *std.ArrayList(u8), allocator: std.mem.Allocator) ArrayListWriter

writeAll

fn writeAll(self: *ArrayListWriter, bytes: []const u8) !void
fn print(self: *ArrayListWriter, comptime fmt: []const u8, args: anytype) !void

writeByte

fn writeByte(self: *ArrayListWriter, byte: u8) !void

writeByteNTimes

fn writeByteNTimes(self: *ArrayListWriter, byte: u8, n: usize) !void

SignalType

const SignalType = std.posix.SIG

The signal type used in signal handlers. In Zig 0.16, this changed from c_int to std.posix.SIG enum.