@@ -186,58 +186,52 @@ test("multiple Workers access same Durable Object data", async (t) => {
186
186
} ) ;
187
187
188
188
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 ( ) ] ) ) ;
238
232
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 } ` ) ;
242
236
t . is ( await res . text ( ) , `id:${ id } ` ) ;
243
237
} ) ;
0 commit comments