Skip to content

Commit 63a77f4

Browse files
authored
chore(vite-plugin-cloudflare): test local mode support for image bindings (#10687)
1 parent bde8ef2 commit 63a77f4

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

packages/vite-plugin-cloudflare/playground/bindings/__tests__/worker.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ test("kv_namspaces support", async () => {
66
expect(response).toBe("KV binding works");
77
});
88

9+
test("images support", async () => {
10+
const response = await getTextResponse("/images");
11+
expect(response).toBe("Images binding works");
12+
});
13+
914
test("unsafe_hello_world support", async () => {
1015
const response = await getTextResponse("/hello-world");
1116
expect(response).toBe("Hello World binding works");
94.3 KB
Loading

packages/vite-plugin-cloudflare/playground/bindings/src/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import image from "./image.png?inline";
2+
13
export default {
24
async fetch(request, env) {
35
const url = new URL(request.url);
@@ -18,6 +20,25 @@ export default {
1820
status: 200,
1921
});
2022
}
23+
case "/images": {
24+
const request = await fetch(image);
25+
26+
if (!request.body) {
27+
return new Response("Failed to fetch image", { status: 500 });
28+
}
29+
30+
const info = await env.IMAGES.info(request.body);
31+
32+
if (info.format !== "image/png") {
33+
return new Response("Images binding returns an incorrect format", {
34+
status: 500,
35+
});
36+
}
37+
38+
return new Response("Images binding works", {
39+
status: 200,
40+
});
41+
}
2142
case "/ae": {
2243
await env.WAE.writeDataPoint({ doubles: [2, 3] });
2344

packages/vite-plugin-cloudflare/playground/bindings/worker-configuration.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ declare namespace Cloudflare {
44
interface Env {
55
KV: KVNamespace;
66
HELLO_WORLD: HelloWorldBinding;
7+
IMAGES: ImagesBinding;
78
WAE: AnalyticsEngineDataset;
89
RATE_LIMITER: RateLimit;
910
}

packages/vite-plugin-cloudflare/playground/bindings/wrangler.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"id": "test-kv-id",
1010
},
1111
],
12+
"images": {
13+
"binding": "IMAGES",
14+
},
1215
"unsafe_hello_world": [
1316
{
1417
"binding": "HELLO_WORLD",

0 commit comments

Comments
 (0)