Skip to content

Commit 8584d7b

Browse files
committed
add test
1 parent 2be3a17 commit 8584d7b

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# To test whether vite plugin could configure the hyperdrive binding properly
2+
WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="postgres://user:[email protected]:3456/testdb"

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ test("ratelimit support", async () => {
2525
const response = await getTextResponse("/rate-limit");
2626
expect(response).toBe("Rate limit binding works: first: true, second: false");
2727
});
28+
29+
test("hyperdrive support", async () => {
30+
const response = await getTextResponse("/hyperdrive");
31+
expect(response).toBe("Hyperdrive binding works");
32+
});

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ export default {
6161
}
6262
);
6363
}
64+
case "/hyperdrive": {
65+
if (
66+
typeof env.HYPERDRIVE.connect !== "function" ||
67+
typeof env.HYPERDRIVE.connectionString !== "string"
68+
) {
69+
return new Response("Hyperdrive binding is not configured properly", {
70+
status: 500,
71+
});
72+
}
73+
74+
return new Response("Hyperdrive binding works");
75+
}
6476
case "/hello-world": {
6577
const value = Math.floor(Date.now() * Math.random()).toString(36);
6678
await env.HELLO_WORLD.set(value);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ declare namespace Cloudflare {
77
IMAGES: ImagesBinding;
88
WAE: AnalyticsEngineDataset;
99
RATE_LIMITER: RateLimit;
10+
HYPERDRIVE: Hyperdrive;
1011
}
1112
}
1213
interface Env extends Cloudflare.Env {}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"binding": "WAE",
2424
},
2525
],
26+
"hyperdrive": [
27+
{
28+
"binding": "HYPERDRIVE",
29+
"id": "test-hyperdrive-id",
30+
},
31+
],
2632
"unsafe": {
2733
"bindings": [
2834
{

0 commit comments

Comments
 (0)