diff --git a/ember-file-upload/src/system/http-request.ts b/ember-file-upload/src/system/http-request.ts index c9d1985c..6279f4a3 100644 --- a/ember-file-upload/src/system/http-request.ts +++ b/ember-file-upload/src/system/http-request.ts @@ -29,11 +29,17 @@ function parseResponse(request: XMLHttpRequest): Response { } export default class HTTPRequest { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + onloadstart: (event?: ProgressEvent) => void | undefined; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore onprogress: (event?: ProgressEvent) => void | undefined; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore + onloadend: (event?: ProgressEvent) => void | undefined; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore ontimeout: (event?: ProgressEvent) => void | undefined; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore @@ -83,19 +89,19 @@ export default class HTTPRequest { }); this.request.onloadstart = bind(this, function (evt) { - this.onprogress?.(evt); + this.onloadstart?.(evt); }); this.request.onprogress = bind(this, function (evt) { this.onprogress?.(evt); }); this.request.onloadend = bind(this, function (evt) { - this.onprogress?.(evt); + this.onloadend?.(evt); }); if (this.request.upload) { - this.request.upload.onloadstart = this.request.onprogress; + this.request.upload.onloadstart = this.request.onloadstart; this.request.upload.onprogress = this.request.onprogress; - this.request.upload.onloadend = this.request.onprogress; + this.request.upload.onloadend = this.request.onloadend; } this.request.onload = bind(this, function () { diff --git a/ember-file-upload/src/system/upload.ts b/ember-file-upload/src/system/upload.ts index 1d953457..4bc2ecdc 100644 --- a/ember-file-upload/src/system/upload.ts +++ b/ember-file-upload/src/system/upload.ts @@ -87,13 +87,29 @@ export function upload( request.timeout = options.timeout; } - request.onprogress = function (evt) { + request.onloadstart = function (evt) { if (!evt) return; if (!evt.lengthComputable || evt.total === 0) return; file.loaded = evt.loaded; file.size = evt.total; - file.progress = (evt.loaded / evt.total) * 100; + file.progress = (file.loaded / file.size) * 100; + }; + + request.onprogress = function (evt) { + if (!evt) return; + if (!evt.lengthComputable || evt.total === 0) return; + + file.loaded = evt.loaded; + file.progress = (file.loaded / file.size) * 100; + }; + + request.onloadend = function (evt) { + if (!evt) return; + if (!evt.lengthComputable || evt.total === 0) return; + + file.loaded = file.size; + file.progress = (file.loaded / file.size) * 100; }; request.ontimeout = () => { diff --git a/test-app/tests/integration/progress-test.ts b/test-app/tests/integration/progress-test.ts index 2450947c..35162c8a 100644 --- a/test-app/tests/integration/progress-test.ts +++ b/test-app/tests/integration/progress-test.ts @@ -26,7 +26,7 @@ class FileTracker { }); } -module.skip('Integration | progress', function (hooks) { +module('Integration | progress', function (hooks) { setupRenderingTest(hooks); setupMirage(hooks);