Skip to content

Commit e79cc88

Browse files
committed
redirect stdout/stderr to file
1 parent a599f8a commit e79cc88

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/tools/src/snap-test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { npath } from '@yarnpkg/fslib';
22
import { execute } from '@yarnpkg/shell';
33
import { randomUUID } from 'node:crypto';
4-
import fs from 'node:fs';
4+
import fs, { readFileSync } from 'node:fs';
55
import fsPromises from 'node:fs/promises';
6+
import { open } from 'node:fs/promises';
67
import { cpus, tmpdir } from 'node:os';
78
import path from 'node:path';
8-
import { PassThrough } from 'node:stream';
9-
import { text } from 'node:stream/consumers';
109
import { debuglog, parseArgs } from 'node:util';
1110

1211
import { isPassThroughEnv, replaceUnstableOutput } from './utils';
@@ -153,18 +152,20 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {
153152
const cwd = npath.toPortablePath(caseTmpDir);
154153
for (const command of steps.commands) {
155154
debug('running command: %s, cwd: %s, env: %o', command, caseTmpDir, env);
156-
const outputStream = new PassThrough();
155+
const outpuStreamPath = path.join(caseTmpDir, 'output.log');
156+
const outputStream = await open(outpuStreamPath, 'w');
157157

158158
const exitCode = await execute(stripComments(command), [], {
159159
env,
160160
cwd,
161161
stdin: null,
162-
stderr: outputStream,
163-
stdout: outputStream,
162+
stderr: outputStream as any,
163+
stdout: outputStream as any,
164164
});
165165

166-
outputStream.end();
167-
const output = await text(outputStream);
166+
outputStream.close();
167+
168+
const output = readFileSync(outpuStreamPath, 'utf-8');
168169

169170
let commandLine = `> ${command}`;
170171
if (exitCode !== 0) {

0 commit comments

Comments
 (0)