import { expect, tap } from '@push.rocks/tapbundle'; import { SmartlogDestinationDevtools } from '../ts_destination_devtools/index.js'; import * as smartlogInterfaces from '../ts_interfaces/index.js'; let testDestination: SmartlogDestinationDevtools; let originalConsoleLog: any; let consoleLogCalls: any[] = []; // Helper to create log package const createMockLogPackage = (level: smartlogInterfaces.TLogLevel, message: string): smartlogInterfaces.ILogPackage => { return { timestamp: Date.now(), type: 'log', level, message, context: { environment: 'test', runtime: 'chrome' }, correlation: { id: '123', type: 'none' } }; }; // Tests tap.test('should setup test environment', async () => { // Save original console.log originalConsoleLog = console.log; // Replace with mock console.log = (...args: any[]) => { consoleLogCalls.push(args); // Don't call original to avoid polluting test output }; }); tap.test('should create a devtools destination instance', async () => { testDestination = new SmartlogDestinationDevtools(); expect(testDestination).toBeTruthy(); }); tap.test('should log error level messages with appropriate styling', async () => { consoleLogCalls = []; const logPackage = createMockLogPackage('error', 'Test error message'); await testDestination.handleLog(logPackage); expect(consoleLogCalls.length).toEqual(1); expect(consoleLogCalls[0][0]).toContain('Error:'); expect(consoleLogCalls[0][1]).toContain('background:#000000;color:#800000;'); expect(consoleLogCalls[0][2]).toContain('Test error message'); }); tap.test('should log info level messages with appropriate styling', async () => { consoleLogCalls = []; const logPackage = createMockLogPackage('info', 'Test info message'); await testDestination.handleLog(logPackage); expect(consoleLogCalls.length).toEqual(1); expect(consoleLogCalls[0][0]).toContain('Info:'); expect(consoleLogCalls[0][1]).toContain('background:#EC407A;color:#ffffff;'); expect(consoleLogCalls[0][2]).toContain('Test info message'); }); tap.test('should log ok level messages with appropriate styling', async () => { consoleLogCalls = []; const logPackage = createMockLogPackage('ok', 'Test ok message'); await testDestination.handleLog(logPackage); expect(consoleLogCalls.length).toEqual(1); expect(consoleLogCalls[0][0]).toContain('OK:'); expect(consoleLogCalls[0][2]).toContain('Test ok message'); }); tap.test('should log success level messages with appropriate styling', async () => { consoleLogCalls = []; const logPackage = createMockLogPackage('success', 'Test success message'); await testDestination.handleLog(logPackage); expect(consoleLogCalls.length).toEqual(1); expect(consoleLogCalls[0][0]).toContain('Success:'); expect(consoleLogCalls[0][2]).toContain('Test success message'); }); tap.test('should log warn level messages with appropriate styling', async () => { consoleLogCalls = []; const logPackage = createMockLogPackage('warn', 'Test warning message'); await testDestination.handleLog(logPackage); expect(consoleLogCalls.length).toEqual(1); expect(consoleLogCalls[0][0]).toContain('Warn:'); expect(consoleLogCalls[0][2]).toContain('Test warning message'); }); tap.test('should log note level messages with appropriate styling', async () => { consoleLogCalls = []; const logPackage = createMockLogPackage('note', 'Test note message'); await testDestination.handleLog(logPackage); expect(consoleLogCalls.length).toEqual(1); expect(consoleLogCalls[0][0]).toContain('Note:'); expect(consoleLogCalls[0][2]).toContain('Test note message'); }); tap.test('should clean up test environment', async () => { // Restore the original console.log console.log = originalConsoleLog; }); export default tap.start();