aboutsummaryrefslogtreecommitdiff
path: root/test/js/web/fetch
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/js/web/fetch/fetch-leak-test-fixture.js2
-rw-r--r--test/js/web/fetch/fetch.test.ts23
2 files changed, 24 insertions, 1 deletions
diff --git a/test/js/web/fetch/fetch-leak-test-fixture.js b/test/js/web/fetch/fetch-leak-test-fixture.js
index 07275a425..c83bbea83 100644
--- a/test/js/web/fetch/fetch-leak-test-fixture.js
+++ b/test/js/web/fetch/fetch-leak-test-fixture.js
@@ -29,6 +29,6 @@ await (async function runAll() {
await Bun.sleep(10);
Bun.gc(true);
-if ((heapStats().objectTypeCounts.Response ?? 0) > 10) {
+if ((heapStats().objectTypeCounts.Response ?? 0) > 1 + ((COUNT / 2) | 0)) {
throw new Error("Too many Response objects: " + heapStats().objectTypeCounts.Response);
}
diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts
index 4d529b231..768818420 100644
--- a/test/js/web/fetch/fetch.test.ts
+++ b/test/js/web/fetch/fetch.test.ts
@@ -387,6 +387,25 @@ describe("fetch", () => {
}).toThrow("fetch() request with GET/HEAD/OPTIONS method cannot have body.");
}),
);
+
+ it("content length is inferred", async () => {
+ startServer({
+ fetch(req) {
+ return new Response(req.headers.get("content-length"));
+ },
+ hostname: "localhost",
+ });
+
+ // POST with body
+ const url = `http://${server.hostname}:${server.port}`;
+ const response = await fetch(url, { method: "POST", body: "buntastic" });
+ expect(response.status).toBe(200);
+ expect(await response.text()).toBe("9");
+
+ const response2 = await fetch(url, { method: "POST", body: "" });
+ expect(response2.status).toBe(200);
+ expect(await response2.text()).toBe("0");
+ });
});
it("simultaneous HTTPS fetch", async () => {
@@ -1156,6 +1175,10 @@ it("#2794", () => {
expect(typeof Bun.fetch.bind).toBe("function");
});
+it("#3545", () => {
+ expect(() => fetch("http://example.com?a=b")).not.toThrow();
+});
+
it("invalid header doesnt crash", () => {
expect(() =>
fetch("http://example.com", {