Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/worker/test/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ declare global {
namespace Cloudflare {
interface Env extends AppEnv {
TEST_MIGRATIONS: D1Migration[];
BUCKET: R2Bucket; // tests always provide R2; override the app's optional binding
// The harness always injects R2 (vitest.config.ts `miniflare.r2Buckets`), so override
// the app's optional `BUCKET?` to non-optional here. R2-absent behavior is exercised by
// tests that locally set `env.BUCKET = undefined`.
BUCKET: R2Bucket;
}
}
}
5 changes: 5 additions & 0 deletions packages/worker/test/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { env } from "cloudflare:test";
import { describe, expect, it } from "vitest";

describe("test harness", () => {
// R2 is OPTIONAL in production (wrangler.toml's [[r2_buckets]] may be removed). The test
// harness guarantees BUCKET regardless by injecting it via vitest.config.ts `miniflare.r2Buckets`
// — decoupled from wrangler.toml — so the storage suite runs even on a fork that dropped R2.
// The R2-absent runtime path is covered separately by tests that set `env.BUCKET = undefined`
// (e.g. settle.test.ts, retention.test.ts, upload.test.ts, admin.test.ts).
it("binds D1 and R2", () => {
expect(env.DB).toBeDefined();
expect(env.BUCKET).toBeDefined();
Expand Down
9 changes: 9 additions & 0 deletions packages/worker/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ export default defineConfig(async () => {
wrangler: { configPath: "./wrangler.toml" },
miniflare: {
bindings: { TEST_MIGRATIONS: migrations },
// Declare the Worker's bindings here, not via wrangler.toml, so the test
// harness is decoupled from deployment-specific config. R2 is OPTIONAL in
// production (wrangler.toml's [[r2_buckets]] may be removed — see env.ts
// `BUCKET?`), so a fork that drops it must still get a working test bucket;
// otherwise `env.BUCKET` is undefined and the storage suite breaks. miniflare
// options take precedence over (and merge with) the wrangler config, while
// compatibility_date/flags + vars still come from wrangler.toml.
d1Databases: ["DB"],
r2Buckets: ["BUCKET"],
},
}),
],
Expand Down