|
5 | 5 | DurableObject, |
6 | 6 | DurableObjectError, |
7 | 7 | DurableObjectNamespace, |
| 8 | + DurableObjectState, |
8 | 9 | DurableObjectsPlugin, |
9 | 10 | } from "@miniflare/durable-objects"; |
10 | 11 | import { |
@@ -226,6 +227,30 @@ test("DurableObjectsPlugin: setup: includes namespaces for all objects", async ( |
226 | 227 | t.is(await res1.text(), "object1"); |
227 | 228 | t.is(await res2.text(), "object2"); |
228 | 229 | }); |
| 230 | +test("DurableObjectsPlugin: setup: name removed from id passed to object constructors", async (t) => { |
| 231 | + // https://github.com/cloudflare/miniflare/issues/219 |
| 232 | + class TestObject implements DurableObject { |
| 233 | + constructor(readonly state: DurableObjectState) {} |
| 234 | + fetch = () => new Response(String(this.state.id.name)); |
| 235 | + } |
| 236 | + |
| 237 | + const factory = new MemoryStorageFactory(); |
| 238 | + const plugin = new DurableObjectsPlugin(ctx, { |
| 239 | + durableObjects: { TEST_OBJECT: "TestObject" }, |
| 240 | + }); |
| 241 | + |
| 242 | + const result = await plugin.setup(factory); |
| 243 | + plugin.beforeReload(); |
| 244 | + plugin.reload({}, { TestObject }, new Map()); |
| 245 | + |
| 246 | + const ns: DurableObjectNamespace = result.bindings?.TEST_OBJECT; |
| 247 | + const id = ns.idFromName("name"); |
| 248 | + t.is(id.name, "name"); |
| 249 | + const stub = ns.get(id); |
| 250 | + t.is(stub.id.name, "name"); |
| 251 | + const res = await stub.fetch("/"); |
| 252 | + t.is(await res.text(), "undefined"); |
| 253 | +}); |
229 | 254 |
|
230 | 255 | test("DurableObjectsPlugin: beforeReload: deletes all instances", async (t) => { |
231 | 256 | const factory = new MemoryStorageFactory(); |
|
0 commit comments