Skip to content

Commit 50a72a8

Browse files
committed
add test
1 parent 36be04a commit 50a72a8

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
@@ -20,3 +20,8 @@ test("ratelimit support", async () => {
2020
const response = await getTextResponse("/rate-limit");
2121
expect(response).toBe("Rate limit binding works: first: true, second: false");
2222
});
23+
24+
test("hyperdrive support", async () => {
25+
const response = await getTextResponse("/hyperdrive");
26+
expect(response).toBe("Hyperdrive binding works");
27+
});

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ export default {
4040
}
4141
);
4242
}
43+
case "/hyperdrive": {
44+
if (
45+
typeof env.HYPERDRIVE.connect !== "function" ||
46+
typeof env.HYPERDRIVE.connectionString !== "string"
47+
) {
48+
return new Response("Hyperdrive binding is not configured properly", {
49+
status: 500,
50+
});
51+
}
52+
53+
return new Response("Hyperdrive binding works");
54+
}
4355
case "/hello-world": {
4456
const value = Math.floor(Date.now() * Math.random()).toString(36);
4557
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
@@ -6,6 +6,7 @@ declare namespace Cloudflare {
66
HELLO_WORLD: HelloWorldBinding;
77
WAE: AnalyticsEngineDataset;
88
RATE_LIMITER: RateLimit;
9+
HYPERDRIVE: Hyperdrive;
910
}
1011
}
1112
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
@@ -20,6 +20,12 @@
2020
"binding": "WAE",
2121
},
2222
],
23+
"hyperdrive": [
24+
{
25+
"binding": "HYPERDRIVE",
26+
"id": "test-hyperdrive-id",
27+
},
28+
],
2329
"unsafe": {
2430
"bindings": [
2531
{

0 commit comments

Comments
 (0)