diff --git a/lib/browser/api/net.js b/lib/browser/api/net.js index fe5abe465fb9..99c6f09487c5 100644 --- a/lib/browser/api/net.js +++ b/lib/browser/api/net.js @@ -454,7 +454,7 @@ class ClientRequest extends Writable { } getUploadProgress () { - return { ...this._uploadProgress } || { active: false } + return this._uploadProgress ? { ...this._uploadProgress } : { active: false } } } diff --git a/spec-main/api-net-spec.ts b/spec-main/api-net-spec.ts index faf5852f3d19..f9e4ceb60ece 100644 --- a/spec-main/api-net-spec.ts +++ b/spec-main/api-net-spec.ts @@ -1205,6 +1205,17 @@ describe('net module', () => { }) }) + it('should report upload progress', async () => { + const serverUrl = await respondOnce.toSingleURL((request, response) => { + response.end() + }) + const netRequest = net.request({ url: serverUrl, method: 'POST' }) + expect(netRequest.getUploadProgress()).to.deep.equal({ active: false }) + netRequest.end(Buffer.from('hello')) + const [position, total] = await emittedOnce(netRequest, 'upload-progress') + expect(netRequest.getUploadProgress()).to.deep.equal({ active: true, started: true, current: position, total }) + }) + it('should emit error event on server socket destroy', async () => { const serverUrl = await respondOnce.toSingleURL((request) => { request.socket.destroy()