UNPKG

@seedts/testing

Version:

Testing utilities for SeedTS - Snapshot testing, deterministic seeding, and test helpers

107 lines 3.49 kB
/** * Test helper utilities for SeedTS */ import type { SeedResult } from '@seedts/types'; import type { Executor } from '@seedts/core'; /** * Execute seeds and return results by name for easy access * * @param executor Executor instance * @returns Map of seed results by name * * @example * ```typescript * const executor = new Executor([UsersSeed, PostsSeed]); * const results = await executeSeedsAsMap(executor); * * expect(results.get('users')).toBeDefined(); * expect(results.get('users')?.count).toBe(10); * ``` */ export declare function executeSeedsAsMap(executor: Executor): Promise<Map<string, SeedResult>>; /** * Assert that a seed executed successfully * * @param result Seed result * @throws Error if seed failed * * @example * ```typescript * const results = await executor.execute(); * assertSeedSuccess(results[0]); * ``` */ export declare function assertSeedSuccess(result: SeedResult): void; /** * Assert that all seeds executed successfully * * @param results Array of seed results * @throws Error if any seed failed */ export declare function assertAllSeedsSuccess(results: SeedResult[]): void; /** * Get seed result by name * * @param results Array of seed results * @param name Seed name * @returns Seed result or undefined */ export declare function getSeedByName(results: SeedResult[], name: string): SeedResult | undefined; /** * Assert that seed result exists and has expected count * * @param result Seed result * @param expectedCount Expected record count * @throws Error if count doesn't match */ export declare function assertSeedCount(result: SeedResult, expectedCount: number): void; /** * Assert that seed data matches predicate * * @param data Seed data array * @param seedName Seed name (for error messages) * @param predicate Function to test each record * @throws Error if any record fails predicate */ export declare function assertSeedData<T = any>(data: T[], seedName: string, predicate: (record: T) => boolean, message?: string): void; /** * Assert that seed completed within expected duration * * @param result Seed result * @param maxDuration Maximum duration in milliseconds * @throws Error if duration exceeds limit */ export declare function assertSeedDuration(result: SeedResult, maxDuration: number): void; /** * Create a test data validator * * @example * ```typescript * const validateUser = createValidator<User>({ * email: (v) => typeof v === 'string' && v.includes('@'), * age: (v) => typeof v === 'number' && v >= 0 && v <= 150, * name: (v) => typeof v === 'string' && v.length > 0 * }); * * assertSeedData(usersResult, validateUser); * ``` */ export declare function createValidator<T extends Record<string, any>>(rules: Partial<Record<keyof T, (value: any) => boolean>>): (record: T) => boolean; /** * Wait for a condition to be true with timeout * * @param condition Function that returns true when condition is met * @param timeout Timeout in milliseconds (default: 5000) * @param interval Check interval in milliseconds (default: 100) * @throws Error if timeout reached */ export declare function waitFor(condition: () => boolean | Promise<boolean>, timeout?: number, interval?: number): Promise<void>; /** * Compare two objects deeply for equality * * @param a First object * @param b Second object * @returns True if objects are deeply equal */ export declare function deepEqual(a: any, b: any): boolean; //# sourceMappingURL=helpers.d.ts.map