@@ -346,13 +346,11 @@ describe('Firebase Storage > Upload Task', () => {
346346
347347 // This is to test to make sure that when you pause in the middle of a request that you do not get an error
348348 async function runProgressPauseTest ( blob : FbsBlob ) : Promise < void > {
349- const pausedDeferred = new Deferred ( ) ;
350349 let callbackCount = 0 ;
351350 // Usually the first request is to create the resumable upload and the second is to upload.
352351 // Upload requests are not retryable, and this callback is to make sure we pause before the response comes back.
353352 function shouldRespondCallback ( ) : boolean {
354353 if ( callbackCount ++ === 1 ) {
355- pausedDeferred . resolve ( ) ;
356354 task . pause ( ) ;
357355 return false ;
358356 }
@@ -384,6 +382,7 @@ describe('Firebase Storage > Upload Task', () => {
384382 ( func as any as ( ...args : any [ ] ) => void ) . apply ( null , _args ) ;
385383 } catch ( e ) {
386384 reject ( e ) ;
385+ pausedStateCompleted . reject ( e ) ;
387386 // also throw to further unwind the stack
388387 throw e ;
389388 }
@@ -394,9 +393,12 @@ describe('Firebase Storage > Upload Task', () => {
394393 const fixedAssertEquals = promiseAssertWrapper ( assert . equal ) ;
395394 const fixedAssertFalse = promiseAssertWrapper ( assert . isFalse ) ;
396395 const fixedAssertTrue = promiseAssertWrapper ( assert . isTrue ) ;
396+ const fixedAssertFail = promiseAssertWrapper ( assert . fail ) ;
397397
398398 const events : string [ ] = [ ] ;
399399 const progress : number [ ] [ ] = [ ] ;
400+ // Promise for when we are finally in the pause state
401+ const pausedStateCompleted = new Deferred ( ) ;
400402 let complete = 0 ;
401403 function addCallbacks ( task : UploadTask ) : void {
402404 let lastState : string ;
@@ -412,6 +414,7 @@ describe('Firebase Storage > Upload Task', () => {
412414 lastState !== TaskState . PAUSED &&
413415 state === TaskState . PAUSED
414416 ) {
417+ pausedStateCompleted . resolve ( ) ;
415418 events . push ( 'pause' ) ;
416419 }
417420
@@ -422,7 +425,7 @@ describe('Firebase Storage > Upload Task', () => {
422425 lastState = state ;
423426 } ,
424427 ( ) => {
425- reject ( 'Failed to Upload ' ) ;
428+ fixedAssertFail ( 'Failed to upload ' ) ;
426429 } ,
427430 ( ) => {
428431 events . push ( 'complete' ) ;
@@ -435,6 +438,8 @@ describe('Firebase Storage > Upload Task', () => {
435438
436439 let completeTriggered = false ;
437440
441+ // We should clean this up and just add all callbacks in one function call.
442+ // Keeps track of all events that were logged before and asserts on them.
438443 task . on ( TaskEvent . STATE_CHANGED , undefined , undefined , ( ) => {
439444 fixedAssertFalse ( completeTriggered ) ;
440445 completeTriggered = true ;
@@ -468,9 +473,7 @@ describe('Firebase Storage > Upload Task', () => {
468473 fixedAssertTrue ( lastIsAll ) ;
469474 resolve ( null ) ;
470475 } ) ;
471- await pausedDeferred . promise ;
472- // Need to wait until the state has settled [i.e. from pausing to pause] and allow for any potential errors to propagate.
473- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
476+ await pausedStateCompleted . promise ;
474477 task . resume ( ) ;
475478 return promise ;
476479 }
@@ -723,7 +726,7 @@ describe('Firebase Storage > Upload Task', () => {
723726 expect ( clock . countTimers ( ) ) . to . eq ( 0 ) ;
724727 clock . restore ( ) ;
725728 } ) ;
726- it ( 'does not error when pausing inflight request' , async ( ) => {
729+ it . only ( 'does not error when pausing inflight request' , async ( ) => {
727730 // Kick off upload
728731 await runProgressPauseTest ( bigBlob ) ;
729732 } ) ;
0 commit comments