@@ -22,7 +22,6 @@ class StallTestHttpStack extends TestHttpStack {
2222 this . progressSequences = new Map ( )
2323 this . progressPromises = new Map ( )
2424 this . nextProgressSequence = null
25- this . customProgressHandler = null
2625 }
2726
2827 /**
@@ -40,14 +39,6 @@ class StallTestHttpStack extends TestHttpStack {
4039 this . nextProgressSequence = sequence
4140 }
4241
43- /**
44- * Set a custom progress handler for the next PATCH request
45- * @param {Function } handler - Custom handler function
46- */
47- setCustomProgressHandler ( handler ) {
48- this . customProgressHandler = handler
49- }
50-
5142 supportsProgressEvents ( ) {
5243 return true
5344 }
@@ -80,28 +71,6 @@ class StallTestHttpStack extends TestHttpStack {
8071 return
8172 }
8273
83- // Handle custom progress handlers
84- if ( this . customProgressHandler ) {
85- const customHandler = this . customProgressHandler
86- this . customProgressHandler = null
87-
88- const originalSetProgressHandler = req . setProgressHandler . bind ( req )
89- req . setProgressHandler = ( handler ) => {
90- customHandler . progressHandler = handler
91- originalSetProgressHandler ( handler )
92- }
93-
94- const originalSend = req . send . bind ( req )
95- req . send = async ( body ) => {
96- const result = originalSend ( body )
97- if ( customHandler . onSend ) {
98- await customHandler . onSend ( body , customHandler . progressHandler )
99- }
100- return result
101- }
102- return
103- }
104-
10574 // Handle progress sequences
10675 if ( this . nextProgressSequence ) {
10776 this . progressSequences . set ( req , this . nextProgressSequence )
@@ -373,27 +342,22 @@ describe('tus-stall-detection', () => {
373342 retryDelays : null ,
374343 } )
375344
376- let progressCallCount = 0
377- testStack . setCustomProgressHandler ( {
378- onSend : async ( body , progressHandler ) => {
379- if ( progressHandler && body ) {
380- const totalSize = await getBodySize ( body )
381- // Send progress events for first 30% of upload then stop
382- for ( let i = 0 ; i <= 3 ; i ++ ) {
383- progressCallCount ++
384- progressHandler ( Math . floor ( totalSize * 0.1 * i ) )
385- await wait ( 50 )
386- }
387- }
388- } ,
389- } )
345+ // Create a progress sequence that stops at 30% of the file
346+ const fileSize = file . size
347+ const progressSequence = [
348+ { bytes : 0 , delay : 10 } ,
349+ { bytes : Math . floor ( fileSize * 0.1 ) , delay : 50 } ,
350+ { bytes : Math . floor ( fileSize * 0.2 ) , delay : 50 } ,
351+ { bytes : Math . floor ( fileSize * 0.3 ) , delay : 50 } ,
352+ // No more progress events after 30%
353+ ]
390354
355+ testStack . setNextProgressSequence ( progressSequence )
391356 upload . start ( )
392357 await handleUploadCreation ( testStack )
393358
394359 const error = await options . onError . toBeCalled ( )
395360 expect ( error . message ) . toContain ( 'Upload stalled' )
396- expect ( progressCallCount ) . toBeGreaterThan ( 0 )
397361 expect ( options . onProgress . calls . count ( ) ) . toBeGreaterThan ( 0 )
398362 } )
399363
0 commit comments