import { expect, tap } from '@git.zone/tstest/tapbundle'; import { SmartlogSourceInteractive, SmartlogProgressBar } from '../ts_source_interactive/index.js'; // Test instances let testSpinner: SmartlogSourceInteractive; let testProgressBar: SmartlogProgressBar; // Original state for restoration const originalState = { stdoutTTY: process.stdout.isTTY, consoleLog: console.log }; // Log tracking const logs: string[] = []; tap.test('should handle non-interactive mode correctly', async (toolsArg) => { // Setup non-interactive mode process.stdout.isTTY = false; console.log = (...args: any[]) => { logs.push(args.join(' ')); }; // Test spinner creation testSpinner = new SmartlogSourceInteractive(); expect(testSpinner).toBeTruthy(); // Test spinner text logs.length = 0; testSpinner.text('Loading data'); expect(logs.length).toBeGreaterThan(0); expect(logs[0]).toContain('[Loading]'); expect(logs[0]).toContain('Loading data'); // Test spinner success logs.length = 0; testSpinner.finishSuccess('Task completed'); expect(logs.length).toBeGreaterThan(0); expect(logs[0]).toContain('[Success]'); expect(logs[0]).toContain('Task completed'); // Test progress bar testProgressBar = new SmartlogProgressBar({ total: 100 }); expect(testProgressBar).toBeTruthy(); // Test progress updates logs.length = 0; testProgressBar.update(10); testProgressBar.update(50); testProgressBar.update(100); expect(logs.length).toBeGreaterThan(0); const progressLogs = logs.join(' '); expect(progressLogs).toContain('10%'); expect(progressLogs).toContain('50%'); expect(progressLogs).toContain('100%'); // Cleanup testSpinner.stop(); console.log = originalState.consoleLog; process.stdout.isTTY = originalState.stdoutTTY; }); export default tap.start();