This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -440,6 +440,12 @@ class FileLoader {
440440 return this . file
441441 . then ( file => this . _reader . read ( file ) )
442442 . then ( data => {
443+ // Edge case: reader was aborted after file was read - double check for proper status.
444+ // It can happen when image was deleted during its upload.
445+ if ( this . status !== 'reading' ) {
446+ throw this . status ;
447+ }
448+
443449 this . status = 'idle' ;
444450
445451 return data ;
Original file line number Diff line number Diff line change @@ -582,6 +582,30 @@ describe( 'FileRepository', () => {
582582
583583 return promise ;
584584 } ) ;
585+
586+ it ( 'should abort upload if image is removed during the upload process' , ( ) => {
587+ const file = createNativeFileMock ( ) ;
588+ const loader = fileRepository . createLoader ( file ) ;
589+
590+ sinon . stub ( loader . _reader , 'read' ) . callsFake ( ( ) => {
591+ expect ( loader . status ) . to . equal ( 'reading' ) ;
592+
593+ // Reader is being aborted after file was read.
594+ // It can happen if an element (and its file that is being uploaded) will be removed during the upload process.
595+ loader . status = 'aborted' ;
596+ } ) ;
597+
598+ return loader . read ( )
599+ . then (
600+ ( ) => {
601+ throw new Error ( 'Supposed to be rejected.' ) ;
602+ } ,
603+ status => {
604+ expect ( status ) . to . equal ( 'aborted' ) ;
605+ expect ( loader . status ) . to . equal ( 'aborted' ) ;
606+ }
607+ ) ;
608+ } ) ;
585609 } ) ;
586610
587611 describe ( 'upload()' , ( ) => {
You can’t perform that action at this time.
0 commit comments