@@ -90,6 +90,23 @@ describe("Panic Hook with WASM Reinitialization", () => {
9090 expect ( responses [ 2 ] . status ) . toBe ( 200 ) ;
9191 }
9292
93+ // Test 4: JS error recovery - counter should NOT reset after a JS error
94+ {
95+ const uniqueId = `JSERR_${ Date . now ( ) } _${ Math . random ( ) } ` ;
96+
97+ const resp1 = await mf . dispatchFetch ( `${ mfUrl } durable/${ uniqueId } ` ) ;
98+ const match1 = ( await resp1 . text ( ) ) . match ( / u n s t o r e d _ c o u n t : ( \d + ) / ) ;
99+ const count1 = match1 ? parseInt ( match1 [ 1 ] ) : 0 ;
100+
101+ const jsErrorResp = await mf . dispatchFetch ( `${ mfUrl } test-js-error` ) ;
102+ expect ( jsErrorResp . status ) . toBe ( 500 ) ;
103+
104+ const resp2 = await mf . dispatchFetch ( `${ mfUrl } durable/${ uniqueId } ` ) ;
105+ const match2 = ( await resp2 . text ( ) ) . match ( / u n s t o r e d _ c o u n t : ( \d + ) / ) ;
106+ const count2 = match2 ? parseInt ( match2 [ 1 ] ) : 0 ;
107+ expect ( count2 ) . toBe ( count1 + 1 ) ;
108+ }
109+
93110 } else {
94111 // ===== PANIC=ABORT MODE TESTS (default) =====
95112 // In this mode, panics cause "Workers runtime canceled" and WASM reinitializes.
@@ -163,54 +180,38 @@ describe("Panic Hook with WASM Reinitialization", () => {
163180 expect ( recoveryResp . status ) . toBe ( 200 ) ;
164181 }
165182 }
183+ }
166184
167- // explicit abort() recovery test
168- {
169- await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
170- const resp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
171- expect ( await resp . text ( ) ) . toContain ( "unstored_count:" ) ;
172-
173- const abortResp = await mf . dispatchFetch ( `${ mfUrl } test-abort` ) ;
174- expect ( abortResp . status ) . toBe ( 500 ) ;
175-
176- const abortText = await abortResp . text ( ) ;
177- expect ( abortText ) . toContain ( "Workers runtime canceled" ) ;
178-
179- const normalResp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
180- expect ( await normalResp . text ( ) ) . toContain ( "unstored_count: 1" ) ;
181- }
182-
183- // JS error recovery test
184- {
185- await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
186- const resp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
187- expect ( await resp . text ( ) ) . toContain ( "unstored_count:" ) ;
185+ // // explicit abort() recovery test
186+ // {
187+ // await mf.dispatchFetch(`${mfUrl}durable/COUNTER`);
188+ // const resp = await mf.dispatchFetch(`${mfUrl}durable/COUNTER`);
189+ // expect(await resp.text()).toContain("unstored_count:");
188190
189- const jsErrorResp = await mf . dispatchFetch ( `${ mfUrl } test-js-error ` ) ;
190- expect ( jsErrorResp . status ) . toBe ( 500 ) ;
191+ // const abortResp = await mf.dispatchFetch(`${mfUrl}test-abort `);
192+ // expect(abortResp .status).toBe(500);
191193
192- const jsErrorText = await jsErrorResp . text ( ) ;
193- expect ( jsErrorText ) . toContain ( "Workers runtime canceled" ) ;
194+ // const abortText = await abortResp .text();
195+ // expect(abortText ).toContain("Workers runtime canceled");
194196
195- const normalResp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
196- expect ( await normalResp . text ( ) ) . toContain ( "unstored_count: 1" ) ;
197- }
197+ // const normalResp = await mf.dispatchFetch(`${mfUrl}durable/COUNTER`);
198+ // expect(await normalResp.text()).toContain("unstored_count: 1");
199+ // }
198200
199- // out of memory recovery test
200- {
201- await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
202- const resp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
203- expect ( await resp . text ( ) ) . toContain ( "unstored_count:" ) ;
201+ // out of memory recovery test
202+ {
203+ await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
204+ const resp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
205+ expect ( await resp . text ( ) ) . toContain ( "unstored_count:" ) ;
204206
205- const oomResp = await mf . dispatchFetch ( `${ mfUrl } test-oom` ) ;
206- expect ( oomResp . status ) . toBe ( 500 ) ;
207+ const oomResp = await mf . dispatchFetch ( `${ mfUrl } test-oom` ) ;
208+ expect ( oomResp . status ) . toBe ( 500 ) ;
207209
208- const oomText = await oomResp . text ( ) ;
209- expect ( oomText ) . toContain ( "Workers runtime canceled" ) ;
210+ const oomText = await oomResp . text ( ) ;
211+ expect ( oomText ) . toContain ( "Workers runtime canceled" ) ;
210212
211- const normalResp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
212- expect ( await normalResp . text ( ) ) . toContain ( "unstored_count: 1" ) ;
213- }
213+ const normalResp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
214+ expect ( await normalResp . text ( ) ) . toContain ( "unstored_count: 1" ) ;
214215 }
215216 } , 20_000 ) ;
216217} ) ;
0 commit comments