70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { Request, Response } from "undici";
|
|
import { describe, it } from "vitest";
|
|
import { getPlatformProxy } from "./shared";
|
|
|
|
describe("getPlatformProxy - caches", () => {
|
|
(["default", "named"] as const).forEach((cacheType) =>
|
|
it(`correctly obtains a no-op ${cacheType} cache`, async ({ expect }) => {
|
|
const { caches, dispose } = await getPlatformProxy();
|
|
try {
|
|
const cache =
|
|
cacheType === "default"
|
|
? caches.default
|
|
: await caches.open("my-cache");
|
|
|
|
let match = await cache.match("http://0.0.0.0/test");
|
|
expect(match).toBeUndefined();
|
|
|
|
const req = new Request("http://0.0.0.0/test");
|
|
await cache.put(req, new Response("test"));
|
|
|
|
const resp = await cache.match(req);
|
|
expect(resp).toBeUndefined();
|
|
|
|
const deleted = await cache.delete(req);
|
|
expect(deleted).toBe(false);
|
|
} finally {
|
|
await dispose();
|
|
}
|
|
})
|
|
);
|
|
|
|
it("should match the production runtime caches object", async ({
|
|
expect,
|
|
}) => {
|
|
const { caches: platformProxyCaches, dispose } = await getPlatformProxy();
|
|
const caches = platformProxyCaches as any;
|
|
try {
|
|
expect(Object.keys(caches)).toEqual(["default"]);
|
|
|
|
expect(() => {
|
|
caches.has("my-cache");
|
|
}).toThrow(
|
|
"Failed to execute 'has' on 'CacheStorage': the method is not implemented."
|
|
);
|
|
|
|
expect(() => {
|
|
caches.delete("my-cache");
|
|
}).toThrow(
|
|
"Failed to execute 'delete' on 'CacheStorage': the method is not implemented."
|
|
);
|
|
|
|
expect(() => {
|
|
caches.keys();
|
|
}).toThrow(
|
|
"Failed to execute 'keys' on 'CacheStorage': the method is not implemented."
|
|
);
|
|
|
|
expect(() => {
|
|
caches.match(new URL("https://localhost"));
|
|
}).toThrow(
|
|
"Failed to execute 'match' on 'CacheStorage': the method is not implemented."
|
|
);
|
|
|
|
expect(() => {
|
|
caches.nonExistentMethod();
|
|
}).toThrow("caches.nonExistentMethod is not a function");
|
|
} finally {
|
|
await dispose();
|
|
}
|
|
});
|
|
});
|