Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit cb29481

Browse files

File tree

1 file changed

+46
-52
lines changed

1 file changed

+46
-52
lines changed
 

‎packages/tre/test/plugins/do/index.spec.ts

+46-52
Original file line numberDiff line numberDiff line change
@@ -186,58 +186,52 @@ test("multiple Workers access same Durable Object data", async (t) => {
186186
});
187187

188188
test("can use Durable Object ID from one object in another", async (t) => {
189-
const opts: MiniflareOptions = {
190-
port: await getPort(),
191-
workers: [
192-
{
193-
name: "a",
194-
routes: ["*/id"],
195-
unsafeEphemeralDurableObjects: true,
196-
durableObjects: {
197-
OBJECT_B: { className: "b_B", unsafeUniqueKey: "b-B" },
198-
},
199-
modules: true,
200-
script: `
201-
export class b_B {}
202-
export default {
203-
fetch(request, env) {
204-
const id = env.OBJECT_B.newUniqueId();
205-
return new Response(id);
206-
}
207-
}
208-
`,
209-
},
210-
{
211-
name: "b",
212-
routes: ["*/*"],
213-
durableObjects: { OBJECT_B: "B" },
214-
modules: true,
215-
script: `
216-
export class B {
217-
constructor(state) {
218-
this.state = state;
219-
}
220-
fetch() {
221-
return new Response("id:" + this.state.id);
222-
}
223-
}
224-
export default {
225-
fetch(request, env) {
226-
const url = new URL(request.url);
227-
const id = env.OBJECT_B.idFromString(url.pathname.substring(1));
228-
const stub = env.OBJECT_B.get(id);
229-
return stub.fetch(request);
230-
}
231-
}
232-
`,
233-
},
234-
],
235-
};
236-
const mf = new Miniflare(opts);
237-
t.teardown(() => mf.dispose());
189+
const mf1 = new Miniflare({
190+
name: "a",
191+
routes: ["*/id"],
192+
unsafeEphemeralDurableObjects: true,
193+
durableObjects: {
194+
OBJECT_B: { className: "b_B", unsafeUniqueKey: "b-B" },
195+
},
196+
modules: true,
197+
script: `
198+
export class b_B {}
199+
export default {
200+
fetch(request, env) {
201+
const id = env.OBJECT_B.newUniqueId();
202+
return new Response(id);
203+
}
204+
}
205+
`,
206+
});
207+
const mf2 = new Miniflare({
208+
name: "b",
209+
routes: ["*/*"],
210+
durableObjects: { OBJECT_B: "B" },
211+
modules: true,
212+
script: `
213+
export class B {
214+
constructor(state) {
215+
this.state = state;
216+
}
217+
fetch() {
218+
return new Response("id:" + this.state.id);
219+
}
220+
}
221+
export default {
222+
fetch(request, env) {
223+
const url = new URL(request.url);
224+
const id = env.OBJECT_B.idFromString(url.pathname.substring(1));
225+
const stub = env.OBJECT_B.get(id);
226+
return stub.fetch(request);
227+
}
228+
}
229+
`,
230+
});
231+
t.teardown(() => Promise.all([mf1.dispose(), mf2.dispose()]));
238232

239-
let res = await mf.dispatchFetch("http://localhost/id");
240-
const id = await res.text();
241-
res = await mf.dispatchFetch(`http://localhost/${id}`);
233+
const idRes = await mf1.dispatchFetch("http://localhost/id");
234+
const id = await idRes.text();
235+
const res = await mf2.dispatchFetch(`http://localhost/${id}`);
242236
t.is(await res.text(), `id:${id}`);
243237
});

0 commit comments

Comments
 (0)
This repository has been archived.