mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
## Summary
- `new Request()` was ignoring `cache` and `mode` options, always
returning hardcoded default values ("default" for cache, "navigate" for
mode)
- Added proper storage and handling of these options in the Request
struct
- Both options are now correctly parsed from the constructor init object
and preserved when cloning
Fixes #2993
## Test plan
- [x] Added regression test in `test/regression/issue/2993.test.ts`
- [x] Tests verify all valid cache values: "default", "no-store",
"reload", "no-cache", "force-cache", "only-if-cached"
- [x] Tests verify all valid mode values: "same-origin", "no-cors",
"cors", "navigate"
- [x] Tests verify default values (cache: "default", mode: "cors")
- [x] Tests verify `Request.clone()` preserves options
- [x] Tests verify `new Request(request)` preserves options
- [x] Tests verify `new Request(request, init)` allows overriding
options
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
|
|
test("Request cache option is set correctly", () => {
|
|
const cacheValues = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"] as const;
|
|
|
|
for (const cache of cacheValues) {
|
|
const request = new Request("http://localhost:8080/", { cache });
|
|
expect(request.cache).toBe(cache);
|
|
}
|
|
});
|
|
|
|
test("Request mode option is set correctly", () => {
|
|
const modeValues = ["same-origin", "no-cors", "cors", "navigate"] as const;
|
|
|
|
for (const mode of modeValues) {
|
|
const request = new Request("http://localhost:8080/", { mode });
|
|
expect(request.mode).toBe(mode);
|
|
}
|
|
});
|
|
|
|
test("Request cache defaults to 'default'", () => {
|
|
const request = new Request("http://localhost:8080/");
|
|
expect(request.cache).toBe("default");
|
|
});
|
|
|
|
test("Request mode defaults to 'cors'", () => {
|
|
const request = new Request("http://localhost:8080/");
|
|
expect(request.mode).toBe("cors");
|
|
});
|
|
|
|
test("Request.clone() preserves cache and mode options", () => {
|
|
const original = new Request("http://localhost:8080/", { cache: "no-cache", mode: "same-origin" });
|
|
const cloned = original.clone();
|
|
|
|
expect(cloned.cache).toBe("no-cache");
|
|
expect(cloned.mode).toBe("same-origin");
|
|
});
|
|
|
|
test("new Request(request) preserves cache and mode options", () => {
|
|
const original = new Request("http://localhost:8080/", { cache: "force-cache", mode: "no-cors" });
|
|
const newRequest = new Request(original);
|
|
|
|
expect(newRequest.cache).toBe("force-cache");
|
|
expect(newRequest.mode).toBe("no-cors");
|
|
});
|
|
|
|
test("new Request(request, init) allows overriding cache and mode", () => {
|
|
const original = new Request("http://localhost:8080/", { cache: "default", mode: "cors" });
|
|
const newRequest = new Request(original, { cache: "no-cache", mode: "same-origin" });
|
|
|
|
expect(newRequest.cache).toBe("no-cache");
|
|
expect(newRequest.mode).toBe("same-origin");
|
|
});
|