mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-18 12:13:58 +00:00
test(docker): cover docker subcommand rendering paths
- add handler-level coverage for up, down, logs, config, update, and status - exercise success, validation, follow-mode, and boxed error output paths
This commit is contained in:
1 parent
5ad4303345
commit
5b9954cfad
7 files changed
+430
-33
No files matched your search
@@ -0,0 +1,44 @@
|
||||
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');
|
||||
}
|
||||
Reference in new issue
Block a user