fix large stdout output (#2850)

* fix large stdout output

* remove skip from #2674 for testing

* add big stdout test using spawnSync

* add bunEnv on big stdout test
This commit is contained in:
Ciro Spaciari
2023-05-12 08:05:46 -03:00
committed by GitHub
parent 273ccbc241
commit f8c840aec7
3 changed files with 36 additions and 1 deletions

View File

@@ -1177,6 +1177,22 @@ pub const Blob = struct {
return;
}
if (@hasField(This, "file_store")) {
const pathlike = this.file_store.pathlike;
if (pathlike == .fd) {
this.opened_fd = pathlike.fd;
Callback(this, this.opened_fd);
return;
}
} else {
const pathlike = this.file_blob.store.?.data.file.pathlike;
if (pathlike == .fd) {
this.opened_fd = pathlike.fd;
Callback(this, this.opened_fd);
return;
}
}
if (comptime Environment.isMac) {
Callback(this, this.getFdMac());
} else {

View File

@@ -0,0 +1,2 @@
const str = "a".repeat(300000);
await Bun.write(Bun.stdout, str);

View File

@@ -1,7 +1,7 @@
import fs from "fs";
import { it, expect, describe } from "bun:test";
import path from "path";
import { gcTick, withoutAggressiveGC } from "harness";
import { gcTick, withoutAggressiveGC, bunExe, bunEnv } from "harness";
import { tmpdir } from "os";
it("Bun.write blob", async () => {
@@ -290,3 +290,20 @@ it.skip("Bun.write('output.html', HTMLRewriter.transform(Bun.file)))", async don
expect(await Bun.file(outpath).text()).toBe("<div><blink>it worked!</blink></div>");
done();
});
it("#2674", async () => {
const file = path.join(import.meta.dir, "big-stdout.js");
const { stderr, stdout, exitCode } = Bun.spawnSync({
cmd: [bunExe(), "run", file],
env: bunEnv,
stderr: "pipe",
stdout: "pipe",
});
console.log(stderr?.toString());
const text = stdout?.toString();
expect(text?.length).toBe(300000);
const error = stderr?.toString();
expect(error?.length).toBeFalsy();
expect(exitCode).toBe(0);
});