MCPcopy Create free account
hub / github.com/langgenius/dify / captureRun

Function captureRun

cli/src/framework/run.test.ts:61–91  ·  view source on GitHub ↗
(tree: CommandTree, argv: string[])

Source from the content-addressed store, hash-verified

59}
60
61async function captureRun(tree: CommandTree, argv: string[]): Promise<Captured> {
62 const captured: Captured = { stdout: '', stderr: '', exit: undefined }
63 const origStdout = process.stdout.write.bind(process.stdout)
64 const origStderr = process.stderr.write.bind(process.stderr)
65 const origExit = process.exit.bind(process)
66
67 process.stdout.write = ((chunk: string | Uint8Array) => {
68 captured.stdout += typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk)
69 return true
70 }) as typeof process.stdout.write
71
72 process.stderr.write = ((chunk: string | Uint8Array) => {
73 captured.stderr += typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk)
74 return true
75 }) as typeof process.stderr.write
76
77 process.exit = ((code?: number) => {
78 captured.exit = code
79 // do not throw; the catch block should `return` after exit
80 }) as typeof process.exit
81
82 try {
83 await run(tree, argv)
84 }
85 finally {
86 process.stdout.write = origStdout
87 process.stderr.write = origStderr
88 process.exit = origExit
89 }
90 return captured
91}
92
93function makeTree(cmd: CommandConstructor): CommandTree {
94 return { cmd: { command: cmd, subcommands: {} } }

Callers 1

run.test.tsFile · 0.70

Calls 3

runFunction · 0.90
bindMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected