@@ -55,7 +55,7 @@ const createContext = () => {
5555 const egressPromise = new Promise ( resolve => {
5656 resolveEgress = resolve
5757 } )
58-
58+
5959 return {
6060 space : SpaceDID . from (
6161 'did:key:z6MkknBAHEGCWvBzAi4amdH5FXEXrdKoWF1UJuvc8Psm2Mda'
@@ -66,10 +66,11 @@ const createContext = () => {
6666 gatewaySigner,
6767 gatewayIdentity,
6868 delegationProofs : [ ] ,
69+ // @ts -ignore - Fake waitUntil to capture promisses and wait for them before making test asserts
6970 waitUntil : ( promise ) => {
7071 // Track the promise synchronously
71- const tracked = promise . catch ( error => {
72- // Ignore errors in waitUntil
72+ const tracked = promise . catch ( ( error ) => {
73+ console . error ( 'Error in waitUntil:' , error )
7374 } )
7475 waitUntilPromises . push ( tracked )
7576 // @ts -expect-error - Resolve the egress promise when all tracked promises complete
@@ -79,7 +80,7 @@ const createContext = () => {
7980 // Wait for egress tracking to complete
8081 waitForEgressTracking : ( ) => egressPromise ,
8182 path : '' ,
82- searchParams : new URLSearchParams ( ) ,
83+ searchParams : new URLSearchParams ( )
8384 }
8485}
8586
@@ -152,7 +153,6 @@ describe('withEgressTracker', async () => {
152153 it ( 'should record egress for a large file' , async ( ) => {
153154 const ctx = createContext ( )
154155 const largeContent = new Uint8Array ( 100 * 1024 * 1024 ) // 100 MB
155- const totalBytes = largeContent . byteLength
156156 const mockResponse = new Response (
157157 new ReadableStream ( {
158158 start ( controller ) {
@@ -184,7 +184,6 @@ describe('withEgressTracker', async () => {
184184 const ctx = createContext ( )
185185 const chunk1 = new TextEncoder ( ) . encode ( 'Hello, ' )
186186 const chunk2 = new TextEncoder ( ) . encode ( 'world!' )
187- const totalBytes = Buffer . byteLength ( chunk1 ) + Buffer . byteLength ( chunk2 )
188187
189188 const mockResponse = new Response (
190189 new ReadableStream ( {
@@ -227,7 +226,6 @@ describe('withEgressTracker', async () => {
227226 const carBytes = await bucket . get ( key )
228227 expect ( carBytes ) . to . be . not . undefined
229228 expect ( carBytes ) . to . be . instanceOf ( Uint8Array )
230- const expectedTotalBytes = carBytes . byteLength
231229
232230 // Mock a response with the CAR file content
233231 const mockResponse = new Response (
@@ -278,7 +276,6 @@ describe('withEgressTracker', async () => {
278276 it ( 'should correctly track egress for delayed responses' , async ( ) => {
279277 const ctx = createContext ( )
280278 const content = new TextEncoder ( ) . encode ( 'Delayed response content' )
281- const totalBytes = Buffer . byteLength ( content )
282279
283280 const mockResponse = new Response (
284281 new ReadableStream ( {
@@ -364,8 +361,6 @@ describe('withEgressTracker', async () => {
364361 const ctx = createContext ( )
365362 const content1 = new TextEncoder ( ) . encode ( 'Hello, world!' )
366363 const content2 = new TextEncoder ( ) . encode ( 'Goodbye, world!' )
367- const totalBytes1 = Buffer . byteLength ( content1 )
368- const totalBytes2 = Buffer . byteLength ( content2 )
369364
370365 const mockResponse1 = new Response (
371366 new ReadableStream ( {
@@ -420,7 +415,7 @@ describe('withEgressTracker', async () => {
420415 const queuedData1 = queueSendMock . args [ 0 ] [ 0 ]
421416 expect ( queuedData1 ) . to . have . property ( 'invocation' )
422417 expect ( queuedData1 . invocation ) . to . be . instanceOf ( Uint8Array )
423-
418+
424419 const queuedData2 = queueSendMock . args [ 1 ] [ 0 ]
425420 expect ( queuedData2 ) . to . have . property ( 'invocation' )
426421 expect ( queuedData2 . invocation ) . to . be . instanceOf ( Uint8Array )
@@ -538,12 +533,12 @@ describe('withEgressTracker', async () => {
538533 const response = await handler ( request , {
539534 ...env ,
540535 EGRESS_QUEUE : {
541- send : sinon . stub ( ) . throws ( " queue error" ) ,
542- sendBatch : sinon . stub ( ) . throws ( " queue error" )
536+ send : sinon . stub ( ) . throws ( ' queue error' ) ,
537+ sendBatch : sinon . stub ( ) . throws ( ' queue error' )
543538 }
544539 } , ctx )
545540 const responseBody = await response . text ( )
546- // Wait a bit to ensure flush callback has run and error was caught
541+ // @ts -ignore Wait a bit to ensure flush callback has run and error was caught
547542 await new Promise ( resolve => setImmediate ( resolve ) )
548543
549544 expect ( response . status ) . to . equal ( 200 )
0 commit comments