@mbc-cqrs-serverless/core
Version:
CQRS and event base core
113 lines (112 loc) • 3.9 kB
TypeScript
/**
* Test Assertions
*
* Provides reusable assertion functions for AWS SDK error patterns
* and common test scenarios. These helpers ensure consistent
* validation across integration tests.
*
* Usage:
* import {
* assertIsRetriableError,
* assertIsThrottlingError,
* assertErrorMetadata
* } from './utilities/test-assertions'
*
* it('should be retriable', () => {
* assertIsRetriableError(error)
* })
*/
/**
* Asserts that an error is retriable based on AWS SDK v3 patterns
*/
export declare function assertIsRetriableError(error: unknown): void;
/**
* Asserts that an error is NOT retriable
*/
export declare function assertIsNotRetriableError(error: unknown): void;
/**
* Asserts that an error is a throttling error
*/
export declare function assertIsThrottlingError(error: unknown): void;
/**
* Asserts that an error is a network error
*/
export declare function assertIsNetworkError(error: unknown): void;
/**
* Asserts that an error is a timeout error
*/
export declare function assertIsTimeoutError(error: unknown): void;
/**
* Asserts that an error has the expected metadata
*/
export declare function assertErrorMetadata(error: unknown, expected: {
httpStatusCode?: number;
requestId?: string;
name?: string;
fault?: 'client' | 'server';
}): void;
/**
* Asserts that an error has a valid request ID
*/
export declare function assertHasRequestId(error: unknown): void;
/**
* Asserts that an error is a client fault (4xx)
*/
export declare function assertIsClientFault(error: unknown): void;
/**
* Asserts that an error is a server fault (5xx)
*/
export declare function assertIsServerFault(error: unknown): void;
/**
* Asserts that a response has the expected structure
*/
export declare function assertResponseStructure<T extends object>(response: unknown, expectedKeys: Array<keyof T>): void;
/**
* Asserts that a DynamoDB response has valid metadata
*/
export declare function assertDynamoDBResponseMetadata(response: unknown): void;
/**
* Asserts that an async function throws an error with the expected name
*/
export declare function assertThrowsErrorWithName(fn: () => Promise<unknown>, expectedName: string): Promise<void>;
/**
* Asserts that an async function throws an error matching a predicate
*/
export declare function assertThrowsErrorMatching(fn: () => Promise<unknown>, predicate: (error: unknown) => boolean, description?: string): Promise<void>;
/**
* Asserts that an async operation completes within a time limit
*/
export declare function assertCompletesWithin<T>(fn: () => Promise<T>, timeoutMs: number): Promise<T>;
/**
* Asserts that an async operation takes at least a minimum time
* (useful for testing retry delays)
*/
export declare function assertTakesAtLeast<T>(fn: () => Promise<T>, minMs: number): Promise<T>;
/**
* Forces garbage collection if available (requires --expose-gc flag)
*/
export declare function forceGC(): void;
/**
* Gets current heap memory usage in bytes
*/
export declare function getHeapUsed(): number;
/**
* Asserts that memory increase is within acceptable limits
*/
export declare function assertMemoryIncreaseLessThan(initialMemory: number, maxIncreaseBytes: number): void;
/**
* Runs a function and asserts memory usage stays within limits
*/
export declare function assertNoMemoryLeak<T>(fn: () => Promise<T>, maxIncreaseBytes?: number): Promise<T>;
/**
* Asserts that an array has the expected length
*/
export declare function assertArrayLength<T>(array: T[], expectedLength: number): void;
/**
* Asserts that all items in an array match a predicate
*/
export declare function assertAllMatch<T>(array: T[], predicate: (item: T) => boolean, description?: string): void;
/**
* Asserts that an array contains unique items based on a key function
*/
export declare function assertUniqueBy<T, K>(array: T[], keyFn: (item: T) => K): void;