diff --git a/packages/vite-plugin-cloudflare/playground/bindings/__tests__/worker.spec.ts b/packages/vite-plugin-cloudflare/playground/bindings/__tests__/worker.spec.ts index 0a73f9091f4c..dd54c1f5c9a4 100644 --- a/packages/vite-plugin-cloudflare/playground/bindings/__tests__/worker.spec.ts +++ b/packages/vite-plugin-cloudflare/playground/bindings/__tests__/worker.spec.ts @@ -6,6 +6,11 @@ test("kv_namspaces support", async () => { expect(response).toBe("KV binding works"); }); +test("images support", async () => { + const response = await getTextResponse("/images"); + expect(response).toBe("Images binding works"); +}); + test("unsafe_hello_world support", async () => { const response = await getTextResponse("/hello-world"); expect(response).toBe("Hello World binding works"); diff --git a/packages/vite-plugin-cloudflare/playground/bindings/src/image.png b/packages/vite-plugin-cloudflare/playground/bindings/src/image.png new file mode 100644 index 000000000000..bcb384acc019 Binary files /dev/null and b/packages/vite-plugin-cloudflare/playground/bindings/src/image.png differ diff --git a/packages/vite-plugin-cloudflare/playground/bindings/src/index.ts b/packages/vite-plugin-cloudflare/playground/bindings/src/index.ts index 198861a23ddf..a4e5283ce1ea 100644 --- a/packages/vite-plugin-cloudflare/playground/bindings/src/index.ts +++ b/packages/vite-plugin-cloudflare/playground/bindings/src/index.ts @@ -1,3 +1,5 @@ +import image from "./image.png?inline"; + export default { async fetch(request, env) { const url = new URL(request.url); @@ -18,6 +20,25 @@ export default { status: 200, }); } + case "/images": { + const request = await fetch(image); + + if (!request.body) { + return new Response("Failed to fetch image", { status: 500 }); + } + + const info = await env.IMAGES.info(request.body); + + if (info.format !== "image/png") { + return new Response("Images binding returns an incorrect format", { + status: 500, + }); + } + + return new Response("Images binding works", { + status: 200, + }); + } case "/ae": { await env.WAE.writeDataPoint({ doubles: [2, 3] }); diff --git a/packages/vite-plugin-cloudflare/playground/bindings/worker-configuration.d.ts b/packages/vite-plugin-cloudflare/playground/bindings/worker-configuration.d.ts index f865cce9b624..5ff75b054ab0 100644 --- a/packages/vite-plugin-cloudflare/playground/bindings/worker-configuration.d.ts +++ b/packages/vite-plugin-cloudflare/playground/bindings/worker-configuration.d.ts @@ -4,6 +4,7 @@ declare namespace Cloudflare { interface Env { KV: KVNamespace; HELLO_WORLD: HelloWorldBinding; + IMAGES: ImagesBinding; WAE: AnalyticsEngineDataset; RATE_LIMITER: RateLimit; } diff --git a/packages/vite-plugin-cloudflare/playground/bindings/wrangler.jsonc b/packages/vite-plugin-cloudflare/playground/bindings/wrangler.jsonc index 391214656768..e1f3f91354f8 100644 --- a/packages/vite-plugin-cloudflare/playground/bindings/wrangler.jsonc +++ b/packages/vite-plugin-cloudflare/playground/bindings/wrangler.jsonc @@ -9,6 +9,9 @@ "id": "test-kv-id", }, ], + "images": { + "binding": "IMAGES", + }, "unsafe_hello_world": [ { "binding": "HELLO_WORLD",