Ckeditor5: Improve the CC in the Upload package

Created on 3 Dec 2019  Â·  4Comments  Â·  Source: ckeditor/ckeditor5

The CC is not 100% and we should figure out what to do about it. This issue is strictly about CC but more details about some general problems in the package can be found in #5875.

A follow-up of https://github.com/ckeditor/ckeditor5/issues/5848.

upload task

Most helpful comment

OK, I spent a bit of time on this code and I'm 99% sure that this state is impossible to be reached. Whenever the file reader is aborted, the promise is rejected so we end up in catch() and not in then(). 

In the past, you could do abort() while loading a file and that didn't correctly reject the file promise. I think that we fixed this with @jodator some time ago and that's why then() is no longer reached with the aborted status.

I'll remove this condition.

All 4 comments

OK, I spent a bit of time on this code and I'm 99% sure that this state is impossible to be reached. Whenever the file reader is aborted, the promise is rejected so we end up in catch() and not in then(). 

In the past, you could do abort() while loading a file and that didn't correctly reject the file promise. I think that we fixed this with @jodator some time ago and that's why then() is no longer reached with the aborted status.

I'll remove this condition.

This appeared on CI after we merged https://github.com/ckeditor/ckeditor5-upload/pull/106 😂. So it seems that I was wrong.

It's this test:

    it.only( 'should abort upload if image is removed', () => {
        const file = createNativeFileMock();
        setModelData( model, '<paragraph>{}foo bar</paragraph>' );
        editor.execute( 'imageUpload', { file } );

        const abortSpy = sinon.spy( loader, 'abort' );

        expect( loader.status ).to.equal( 'reading' );

        return loader.file.then( () => {
            nativeReaderMock.mockSuccess( base64Sample );

            const image = doc.getRoot().getChild( 0 );
            model.change( writer => {
                writer.remove( image );
            } );

            expect( loader.status ).to.equal( 'aborted' );
            sinon.assert.calledOnce( abortSpy );
        } );
    } );

This is odd because CI passed for the PR...

And I ran it locally and it is clean

SUMMARY:
✔ 102 tests completed

=============================== Coverage summary ===============================
Statements   : 100% ( 215/215 )
Branches     : 100% ( 64/64 )
Functions    : 100% ( 79/79 )
Lines        : 100% ( 208/208 )
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MansoorJafari picture MansoorJafari  Â·  3Comments

MCMicS picture MCMicS  Â·  3Comments

hamenon picture hamenon  Â·  3Comments

pjasiun picture pjasiun  Â·  3Comments

oleq picture oleq  Â·  3Comments