/** * Test helper utilities for Effect-ts based testing * * This module provides utilities to simplify testing Effect and Either types: * - Synchronous and asynchronous Effect execution * - Assertions for success and failure cases * - Pattern matching for specific error types * * These utilities follow Effect-ts best practices and are designed to work * seamlessly with Vitest test framework. * * @example * ```typescript * // Test successful Effect * const result = expectEffectSuccess(myService.getData()); * expect(result).toEqual(expectedData); * * // Test failed Effect * const error = expectEffectFailure(myService.failingOp()); * expect(error._tag).toBe('GitError'); * * // Pattern match on specific error type * const command = matchEffectError(effect, { * GitError: (err) => err.command * }); * expect(command).toBe('git status'); * ``` * * @module testHelpers */ import { Effect, Either } from 'effect'; import type { AppError } from '../types/errors.js'; /** * Run an Effect synchronously and return the success value * Throws if the Effect fails * * @param effect - The Effect to run * @returns The success value * @throws Error if the Effect fails */ export declare function runEffectSync(effect: Effect.Effect): A; /** * Run an Effect as a Promise * * @param effect - The Effect to run * @returns Promise that resolves with success value or rejects with error */ export declare function runEffectPromise(effect: Effect.Effect): Promise; /** * Assert that an Effect succeeds and return the success value * Throws an error if the Effect fails * * @param effect - The Effect to test * @returns The success value * @throws Error if the Effect fails */ export declare function expectEffectSuccess(effect: Effect.Effect): A; /** * Assert that an Effect fails and return the error * Throws an error if the Effect succeeds * * @param effect - The Effect to test * @returns The error value * @throws Error if the Effect succeeds */ export declare function expectEffectFailure(effect: Effect.Effect): E; /** * Assert that an Either is Right and return the right value * Throws an error if the Either is Left * * @param either - The Either to test * @returns The right value * @throws Error if the Either is Left */ export declare function expectEitherRight(either: Either.Either): A; /** * Assert that an Either is Left and return the left value * Throws an error if the Either is Right * * @param either - The Either to test * @returns The left value * @throws Error if the Either is Right */ export declare function expectEitherLeft(either: Either.Either): E; /** * Pattern match on Effect error and extract specific error type * Useful for testing specific error scenarios * * @param effect - The Effect that should fail * @param matchers - Object mapping error tags to extraction functions * @returns The extracted value from the matched error * @throws Error if the Effect succeeds or error doesn't match * * @example * ```typescript * const result = matchEffectError(effect, { * GitError: (err) => err.command, * ValidationError: (err) => err.field * }); * ``` */ export declare function matchEffectError(effect: Effect.Effect, matchers: { [K in AppError['_tag']]?: (error: Extract) => R; }): R;