console: fix printing of Response(Bun.file()) (#20933)

This commit is contained in:
Meghan Denny
2025-07-11 10:37:44 -08:00
parent 4fa1e8398a
commit deed806db5
2 changed files with 23 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ const Body = @This();
value: Value, // = Value.empty,
pub inline fn len(this: *const Body) Blob.SizeType {
pub fn len(this: *Body) Blob.SizeType {
return this.value.size();
}
@@ -366,9 +366,9 @@ pub const Value = union(Tag) {
}
}
pub fn size(this: *const Value) Blob.SizeType {
pub fn size(this: *Value) Blob.SizeType {
return switch (this.*) {
.Blob => this.Blob.size,
.Blob => @truncate(this.Blob.getSizeForBindings()),
.InternalBlob => @as(Blob.SizeType, @truncate(this.InternalBlob.sliceConst().len)),
.WTFStringImpl => @as(Blob.SizeType, @truncate(this.WTFStringImpl.utf8ByteLength())),
.Locked => this.Locked.sizeHint(),

View File

@@ -1,4 +1,5 @@
import { describe, expect, test } from "bun:test";
import { sep } from "node:path";
test("zero args returns an otherwise empty 200 response", () => {
const response = new Response();
@@ -44,3 +45,22 @@ describe("2-arg form", () => {
expect(response.statusText).toBe("");
});
});
test("print size", () => {
expect(Bun.inspect(new Response(Bun.file(import.meta.filename)))).toMatchInlineSnapshot(`
"Response (1.81 KB) {
ok: true,
url: "",
status: 200,
statusText: "",
headers: Headers {
"content-type": "text/javascript;charset=utf-8",
},
redirected: false,
bodyUsed: false,
FileRef ("${import.meta.dir}${sep}response.test.ts") {
type: "text/javascript;charset=utf-8"
}
}"
`);
});