Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion test/js/bun/util/filesink.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSocketPair, fileSinkInternals } from "bun:internal-for-testing";
import { describe, expect, it } from "bun:test";
import { bunEnv, bunExe, fileDescriptorLeakChecker, isLinux, isPosix, isWindows, tmpdirSync } from "harness";
import { bunEnv, bunExe, fileDescriptorLeakChecker, isLinux, isPosix, isWindows, tempDir, tmpdirSync } from "harness";
import { mkfifo } from "mkfifo";
import { join } from "node:path";

Expand Down Expand Up @@ -699,3 +699,42 @@ it("fs.promises.writeFile with iterables under GC pressure does not crash", asyn
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout: stdout.trim(), stderr, exitCode }).toEqual({ stdout: "ok", stderr: "", exitCode: 0 });
});

it("Bun.file().writer() ignores invalid path/fd in options instead of crashing", async () => {
using dir = tempDir("filesink-writer-invalid-options", {});

// `fd` in options is not an integer: previously this panicked accessing the
// wrong union field after `fromJSWithTag` returned `.err`.
{
const file = Bun.file(join(dir, "a.txt")) as any;
file.fd = Int16Array;
const writer = file.writer(file);
writer.write("a");
await writer.end();
expect(await Bun.file(join(dir, "a.txt")).text()).toBe("a");
}

// Explicit non-integer `fd` in options object.
{
const writer = Bun.file(join(dir, "b.txt")).writer({ fd: "nope" } as any);
writer.write("b");
await writer.end();
expect(await Bun.file(join(dir, "b.txt")).text()).toBe("b");
}

// Non-string `path` in options object.
{
const writer = Bun.file(join(dir, "c.txt")).writer({ path: 123 } as any);
writer.write("c");
await writer.end();
expect(await Bun.file(join(dir, "c.txt")).text()).toBe("c");
}

// String `path` in options is parsed but overridden by the Blob's own path.
{
const writer = Bun.file(join(dir, "d.txt")).writer({ path: join(dir, "ignored.txt") } as any);
writer.write("d");
await writer.end();
expect(await Bun.file(join(dir, "d.txt")).text()).toBe("d");
}
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.