| 1 | import { |
| 2 | DurableObjectNamespace, |
| 3 | Text, |
| 4 | } from "@alchemy.run/cloudflare-runtime/core/bindings"; |
| 5 | import * as Options from "@alchemy.run/cloudflare-test-tools/e2e/Options"; |
| 6 | import wakuFramework from "@alchemy.run/frontend-frameworks/waku"; |
| 7 | |
| 8 | export const FIXTURE_MESSAGE = "hello-from-waku-do-binding"; |
| 9 | |
| 10 | /** |
| 11 | * A waku app plus the user's own Durable Object hosted on the SAME worker. |
| 12 | * The user's `main` module (src/worker-entry.ts) wraps waku's emitted fetch |
| 13 | * handler (via `virtual:waku/server-entry`) and additionally exports |
| 14 | * `class Counter` (a SQLite DO). See README for how the user-entry seam |
| 15 | * threads through the waku cloudflare target. |
| 16 | */ |
| 17 | export default Options.make({ |
| 18 | target: { |
| 19 | cloudflare: { |
| 20 | worker: { |
| 21 | // The user-entry seam: takes precedence over waku's pinned rsc |
| 22 | // entry, mirroring Website.Vite's `main` ("Custom Worker Entry" |
| 23 | // JSDoc in packages/alchemy/src/Cloudflare/Website/Vite.ts). The |
| 24 | // module wraps waku's server entry and re-exports the Counter DO |
| 25 | // class. |
| 26 | main: "./src/worker-entry.ts", |
| 27 | compatibilityDate: "2026-03-10", |
| 28 | compatibilityFlags: ["nodejs_als"], |
| 29 | worker: { |
| 30 | name: "fixtures-waku-durable-objects", |
| 31 | bindings: [ |
| 32 | Text.local("MESSAGE", FIXTURE_MESSAGE), |
| 33 | // Bind the namespace for a DO class exported by THIS worker. |
| 34 | DurableObjectNamespace.local({ |
| 35 | binding: "COUNTER", |
| 36 | className: "Counter", |
| 37 | }), |
| 38 | ], |
| 39 | // The dev runtime's DO declaration (workerd durableObjectNamespaces). |
| 40 | durableObjectNamespaces: [{ className: "Counter", sql: true }], |
| 41 | assets: { |
| 42 | htmlHandling: "drop-trailing-slash", |
| 43 | notFoundHandling: "none", |
| 44 | }, |
| 45 | }, |
| 46 | }, |
| 47 | preview: { |
| 48 | compatibilityDate: "2026-03-10", |
| 49 | compatibilityFlags: ["nodejs_als"], |
| 50 | bindings: { MESSAGE: FIXTURE_MESSAGE }, |
| 51 | // Miniflare's DO declaration for the preview server: binding name -> |
| 52 | // class exported by the built worker bundle. |
| 53 | durableObjects: { COUNTER: { className: "Counter", useSQLite: true } }, |
| 54 | assets: { |
| 55 | routerConfig: { |
| 56 | has_user_worker: true, |
| 57 | invoke_user_worker_ahead_of_assets: false, |
| 58 | }, |
| 59 | assetConfig: { |
| 60 | html_handling: "drop-trailing-slash", |
| 61 | not_found_handling: "none", |
| 62 | has_static_routing: false, |
| 63 | }, |
| 64 | }, |
| 65 | }, |
| 66 | }, |
| 67 | }, |
| 68 | framework: (options) => wakuFramework({ ...options, port: 3110 }), |
| 69 | }); |