| 120 | } |
| 121 | |
| 122 | function streamOutputsAndBuffer(child: ExecaChildProcess) { |
| 123 | const stdout: string[] = [] |
| 124 | const stderr: string[] = [] |
| 125 | const testName = expect.getState().currentTestName ?? "unknown" |
| 126 | const testPath = expect.getState().testPath ?? "unknown" |
| 127 | |
| 128 | const stdoutPrefix = chalk.cyan.dim(`[stdout] ${testPath}/${testName}: `) |
| 129 | const stderrPrefix = chalk.magenta.dim(`[stderr] ${testPath}/${testName}: `) |
| 130 | |
| 131 | if (child.stdout) { |
| 132 | child.stdout.on("data", (data) => { |
| 133 | const lines = data.toString().trim().split(/\r?\n/) |
| 134 | for (const line of lines) { |
| 135 | process.stdout.write(`${stdoutPrefix}${line}\n`) |
| 136 | } |
| 137 | stdout.push(data.toString()) |
| 138 | }) |
| 139 | } |
| 140 | |
| 141 | if (child.stderr) { |
| 142 | child.stderr.on("data", (data) => { |
| 143 | const lines = data.toString().trim().split(/\r?\n/) |
| 144 | for (const line of lines) { |
| 145 | process.stdout.write(`${stderrPrefix}${line}\n`) |
| 146 | } |
| 147 | stderr.push(data.toString()) |
| 148 | }) |
| 149 | } |
| 150 | |
| 151 | return { stdout, stderr } |
| 152 | } |
| 153 | |
| 154 | function padAllLines(text: string, padding: number): string { |
| 155 | return text |