mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-15 22:21:20 +00:00
- add handler-level coverage for up, down, logs, config, update, and status - exercise success, validation, follow-mode, and boxed error output paths
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { afterEach, beforeEach, mock } from 'bun:test';
|
|
|
|
export function useDockerSubcommandConsoleCapture(): {
|
|
logLines: string[];
|
|
errorLines: string[];
|
|
} {
|
|
const state = {
|
|
logLines: [] as string[],
|
|
errorLines: [] as string[],
|
|
};
|
|
|
|
let originalConsoleLog: typeof console.log;
|
|
let originalConsoleError: typeof console.error;
|
|
let originalExitCode: number | undefined;
|
|
|
|
beforeEach(() => {
|
|
state.logLines = [];
|
|
state.errorLines = [];
|
|
originalConsoleLog = console.log;
|
|
originalConsoleError = console.error;
|
|
originalExitCode = process.exitCode;
|
|
process.exitCode = 0;
|
|
|
|
console.log = (...args: unknown[]) => {
|
|
state.logLines.push(args.map(String).join(' '));
|
|
};
|
|
console.error = (...args: unknown[]) => {
|
|
state.errorLines.push(args.map(String).join(' '));
|
|
};
|
|
});
|
|
|
|
afterEach(() => {
|
|
console.log = originalConsoleLog;
|
|
console.error = originalConsoleError;
|
|
process.exitCode = originalExitCode ?? 0;
|
|
mock.restore();
|
|
});
|
|
|
|
return state;
|
|
}
|
|
|
|
export function renderCapturedLines(lines: string[]): string {
|
|
return lines.join('\n');
|
|
}
|