{"action":"created","issue":{"url":"https://api.github.com/repos/IndigoUnited/node-request-progress/issues/9","labels_url":"https://api.github.com/repos/IndigoUnited/node-request-progress/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/IndigoUnited/node-request-progress/issues/9/comments","events_url":"https://api.github.com/repos/IndigoUnited/node-request-progress/issues/9/events","html_url":"https://github.com/IndigoUnited/node-request-progress/issues/9","id":117378589,"number":9,"title":"Add unit tests","user":{"login":"jviotti","id":2192773,"avatar_url":"https://avatars.githubusercontent.com/u/2192773?v=3","gravatar_id":"","url":"https://api.github.com/users/jviotti","html_url":"https://github.com/jviotti","followers_url":"https://api.github.com/users/jviotti/followers","following_url":"https://api.github.com/users/jviotti/following{/other_user}","gists_url":"https://api.github.com/users/jviotti/gists{/gist_id}","starred_url":"https://api.github.com/users/jviotti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jviotti/subscriptions","organizations_url":"https://api.github.com/users/jviotti/orgs","repos_url":"https://api.github.com/users/jviotti/repos","events_url":"https://api.github.com/users/jviotti/events{/privacy}","received_events_url":"https://api.github.com/users/jviotti/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-17T15:28:16Z","updated_at":"2015-11-29T21:16:29Z","closed_at":"2015-11-29T21:16:29Z","body":"I have some thoughts about how to test this module:\r\n\r\n1- Since the module never pipes `request` directly (only listens/emits events), we can easily mock it as an `EventEmitter` instance and avoid using the real `node-request` module (which could be accomplished with something like [nock](https://github.com/pgte/nock)).\r\n\r\n2- The testing process will then go like this:\r\n\r\n- Subscribe to the `progress` event.\r\n- Set `throttle` to a value that basically cancels throttling, so we can get a `progress` event for each `data` we put in.\r\n- Emit a `data` event and assert on the resulting `progress` state.\r\n\r\n3- The `eta` calculation would be a little bit tricker to implement, given is time dependant. I've used [timekeeper](https://github.com/vesln/timekeeper) with success in situations similar to this. This module can be injected in the middle of the \"emit data\", \"receive progress\" cycle.\r\n\r\nI also suggest going for black box unit testing for this module, since otherwise it'd require some refactoring to get started.\r\n"},"comment":{"url":"https://api.github.com/repos/IndigoUnited/node-request-progress/issues/comments/160472615","html_url":"https://github.com/IndigoUnited/node-request-progress/issues/9#issuecomment-160472615","issue_url":"https://api.github.com/repos/IndigoUnited/node-request-progress/issues/9","id":160472615,"user":{"login":"satazor","id":1017236,"avatar_url":"https://avatars.githubusercontent.com/u/1017236?v=3","gravatar_id":"","url":"https://api.github.com/users/satazor","html_url":"https://github.com/satazor","followers_url":"https://api.github.com/users/satazor/followers","following_url":"https://api.github.com/users/satazor/following{/other_user}","gists_url":"https://api.github.com/users/satazor/gists{/gist_id}","starred_url":"https://api.github.com/users/satazor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satazor/subscriptions","organizations_url":"https://api.github.com/users/satazor/orgs","repos_url":"https://api.github.com/users/satazor/repos","events_url":"https://api.github.com/users/satazor/events{/privacy}","received_events_url":"https://api.github.com/users/satazor/received_events","type":"User","site_admin":false},"created_at":"2015-11-29T21:16:29Z","updated_at":"2015-11-29T21:16:29Z","body":"I've landed `0.4.0` with the `eta` + `lengthHeader` support. Still the unit tests are still very welcome. Thanks for your work."}}