mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
## Summary - Adds `Symbol.asyncIterator` to `process.stdout` and `process.stderr` when they are TTY or pipe/socket streams - Matches Node.js behavior where these streams are Duplex-like and support async iteration - Does not add the iterator when streams are redirected to files (matching Node.js SyncWriteStream behavior) ## Test plan - Added test in `test/regression/issue/test-process-stdout-async-iterator.test.ts` - Verified the fix works with Claude Code on Linux x64 - Test passes with `bun bd test test/regression/issue/test-process-stdout-async-iterator.test.ts` Fixes #21704 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
|
|
test("process.stdout and process.stderr have Symbol.asyncIterator for Node.js compatibility", () => {
|
|
// This is needed for compatibility with tools like execa that check for async iterability
|
|
// to determine stream capabilities
|
|
expect(typeof process.stdout[Symbol.asyncIterator]).toBe("function");
|
|
expect(typeof process.stderr[Symbol.asyncIterator]).toBe("function");
|
|
});
|
|
|
|
test("process.stdout and process.stderr async iterators work without throwing", async () => {
|
|
// The iterators should work even though stdout/stderr are write-only
|
|
// They should just complete immediately without yielding any values
|
|
const stdoutIterator = process.stdout[Symbol.asyncIterator]();
|
|
const stdoutResult = await stdoutIterator.next();
|
|
expect(stdoutResult.done).toBe(true);
|
|
expect(stdoutResult.value).toBeUndefined();
|
|
|
|
const stderrIterator = process.stderr[Symbol.asyncIterator]();
|
|
const stderrResult = await stderrIterator.next();
|
|
expect(stderrResult.done).toBe(true);
|
|
expect(stderrResult.value).toBeUndefined();
|
|
});
|
|
|
|
test("tty.WriteStream has Symbol.asyncIterator", () => {
|
|
const tty = require("node:tty");
|
|
// Create a WriteStream for stdout fd
|
|
const stream = new tty.WriteStream(1);
|
|
expect(typeof stream[Symbol.asyncIterator]).toBe("function");
|
|
});
|