The test "should optimize empty bodies by using the exact same memory reference" creates two separate UwsRequest instances but onDataCallback is a module-level variable that gets overwritten by each _initBodyParser call.
When req2._initBodyParser() is called, it overwrites the callback set by req1, so only req2 actually receives the empty data. The test passes because both requests end up returning the shared EMPTY_FROZEN_OBJECT sentinel, but not for the intended reason.
The test should verify that calling json() multiple times on the same request returns the cached result, not that two different requests return the same sentinel.
Where: src/http/core/request.spec.ts around line 450
The test should use a single request and call json() twice to verify caching works.
The test "should optimize empty bodies by using the exact same memory reference" creates two separate
UwsRequestinstances butonDataCallbackis a module-level variable that gets overwritten by each_initBodyParsercall.When
req2._initBodyParser()is called, it overwrites the callback set byreq1, so onlyreq2actually receives the empty data. The test passes because both requests end up returning the sharedEMPTY_FROZEN_OBJECTsentinel, but not for the intended reason.The test should verify that calling
json()multiple times on the same request returns the cached result, not that two different requests return the same sentinel.Where:
src/http/core/request.spec.tsaround line 450The test should use a single request and call
json()twice to verify caching works.