syntropylog
Version:
An instance manager with observability for Node.js applications
109 lines (108 loc) • 3.28 kB
TypeScript
/**
* Mock implementation of SyntropyLog for testing
*
* This mock provides a complete simulation of SyntropyLog functionality
* without depending on the actual framework state, making tests more reliable
* and avoiding initialization/shutdown issues.
*
* Similar to BeaconRedisMock, this is designed to be flexible and configurable
* for different testing scenarios.
*/
export interface MockLogger {
info: (message: string, metadata?: any) => void;
warn: (message: string, metadata?: any) => void;
error: (message: string, metadata?: any) => void;
debug: (message: string, metadata?: any) => void;
trace: (message: string, metadata?: any) => void;
fatal: (message: string, metadata?: any) => void;
withSource: (source: string) => MockLogger;
}
export interface MockContextManager {
run: <T>(fn: () => Promise<T> | T) => Promise<T>;
set: (key: string, value: any) => void;
get: (key: string) => any;
getCorrelationIdHeaderName: () => string;
getTransactionIdHeaderName: () => string;
}
export interface MockSyntropyLog {
init: (config?: any) => Promise<void>;
shutdown: () => Promise<void>;
getLogger: (serviceName?: string) => MockLogger;
getContextManager: () => MockContextManager;
getHttpManager: () => any;
getBrokerManager: () => any;
getSerializationManager: () => any;
}
/**
* Create a mock logger instance
*/
export declare function createMockLogger(): MockLogger;
/**
* Create a mock context manager instance
*/
export declare function createMockContextManager(): MockContextManager;
/**
* Create a mock HTTP manager instance
*/
export declare function createMockHttpManager(): {
createClient: () => {
get: () => Promise<{
data: {};
}>;
post: () => Promise<{
data: {};
}>;
put: () => Promise<{
data: {};
}>;
delete: () => Promise<{
data: {};
}>;
};
};
/**
* Create a mock broker manager instance
*/
export declare function createMockBrokerManager(): {
createClient: () => {
publish: () => Promise<undefined>;
subscribe: () => Promise<undefined>;
};
};
/**
* Create a mock serialization manager instance
*/
export declare function createMockSerializationManager(): {
serialize: () => Promise<string>;
deserialize: () => Promise<{}>;
};
/**
* Get or create mock logger instance
*/
export declare function getMockLogger(): MockLogger;
/**
* Get or create mock context manager instance
*/
export declare function getMockContextManager(): MockContextManager;
/**
* Get or create mock HTTP manager instance
*/
export declare function getMockHttpManager(): any;
/**
* Get or create mock broker manager instance
*/
export declare function getMockBrokerManager(): any;
/**
* Get or create mock serialization manager instance
*/
export declare function getMockSerializationManager(): any;
/**
* Create a complete mock of SyntropyLog
*
* @param spyFn - Optional spy function for framework compatibility (vi.fn, jest.fn, etc.)
*/
export declare function createSyntropyLogMock(spyFn?: (implementation?: any) => any): MockSyntropyLog;
/**
* Reset all mock instances
*/
export declare function resetSyntropyLogMocks(): void;