-
Notifications
You must be signed in to change notification settings - Fork 58
Adding upload progress reporting, issue #285 #326
Conversation
CI failures seem to be an unrelated issue 😄 |
Codecov Report
@@ Coverage Diff @@
## master #326 +/- ##
==========================================
+ Coverage 93.97% 94.05% +0.07%
==========================================
Files 39 40 +1
Lines 2142 2202 +60
Branches 407 408 +1
==========================================
+ Hits 2013 2071 +58
- Misses 51 52 +1
- Partials 78 79 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one minor nit from me, this looks reasonable though I'm sure someone else should also review this.
docs/request.md
Outdated
}); | ||
``` | ||
|
||
Note that while the node provider will emit a single `upload` event when it is done uploading, it cannot emit more granular upload events with `string` or `Buffer` body types. To receive more frequent upload events, you can use the `bodyStream` option to provide a `Readable` with the body content. Upload events will be emitted as the data is read from the stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node -> Node.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments.
@@ -35,6 +35,16 @@ const request: { | |||
}); | |||
}); | |||
|
|||
[ 'POST', 'PUT' ].forEach(method => { | |||
Object.defineProperty(request, method.toLowerCase(), { | |||
value(url: string, options: RequestOptions = {}): UploadObservableTask<Response> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a test for request options default to nothing, therefore we are missing a branch in our testing.
src/request/SubscriptionPool.ts
Outdated
this._observers.push(subscription); | ||
|
||
return () => { | ||
this._observers.splice(this._observers.indexOf(subscription), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not being covered in the tests.
} | ||
|
||
complete() { | ||
this._observers.forEach(observer => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not covered in testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now
src/request/providers/node.ts
Outdated
import Response from '../Response'; | ||
import TimeoutError from '../TimeoutError'; | ||
import { Readable } from 'stream'; | ||
import { UploadObserverEvent } from '../interfaces'; | ||
import Observable from '../../Observable'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov says this file isn't covered at all.
value(url: string, options: RequestOptions = {}): UploadObservableTask<Response> { | ||
options = Object.create(options); | ||
options.method = method; | ||
return <UploadObservableTask<Response>> request(url, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it isn't a big deal, we are trying to move to return request(url, options) as UploadObservableTask<Response>;
The TypeScript team is recommending it to avoid issues with JSX. Though we don't plan to use JSX, it still feels cleaner/more readable.
edd9752
to
b6749ed
Compare
@dylans Updated to use |
@kitsonk OK, I've refactored to use Observables for everything. See the README for details, but basically |
} | ||
|
||
complete() { | ||
this._observers.forEach(observer => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now
|
||
// when the queue is full, get rid of the first ones | ||
while (this._queue.length > this._queueMaxLength) { | ||
this._queue.shift(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not covered in testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should cover the missing line and branches.
@kitsonk Added a few more tests for better coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My feedback has been addressed... obviously Kit needs to verify that his feedback has as well before this is landed.
We might be able to get rid of |
The only thing I am missing is the full coverage on this line. If it isn't testable, then we don't need the default argument. |
@kitsonk That line should be covered now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy camper now! 😂 ⛺️
Type: feature
The following has been addressed in the PR:
Description:
Adds upload progress monitoring to the node & XHR request providers. It is implemented as a request option because by the time the returned promise is resolved, the uploads have already finished. Basic usage is,
XHR
was easy as it emits upload events already. The node uploader was a bit more tricky, as there doesn't seem to be a way to find out how much data node has uploaded when usingrequest.write
. As such, I've added support for passing a readable stream to the node provider. As data is read from the stream, it is written to the request, and upload progress can be reported.Resolves #285