Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
(android) Add unit tests for run and retryPromise #445
What does this PR do?
I noticed the test coverage for
The main tests I have written are in
I would like to continue to add unit tests to help improve the code coverage, but am submitting this PR first to check that I am on the right track. I have used ES2015 notation for the tests to keep it more readable - I don't anticipate this to be a problem since it is supported in all recent node versions.
What testing has been done on this change?
I have run the tests using
It looks like the tests fail on Appveyor because I am using ES2015 features and that the Appveyor set up includes Node 4, which doesn't support these features. The tests pass on Node 6 and 8. I suggest removing Node 4 from there and adding 10. Would that be OK?
Yes, node 4 is no longer supported so we're slowly going through all the repos and dropping it from CI while adding node 10.
I think that's what we should do here, but please do it as its own pull request to avoid this one getting cluttered with unrelated changes :)
referenced this pull request
May 31, 2018
@@ Coverage Diff @@ ## master #445 +/- ## ========================================== + Coverage 44.27% 47.63% +3.36% ========================================== Files 17 17 Lines 1694 1694 Branches 311 311 ========================================== + Hits 750 807 +57 + Misses 944 887 -57
There is one issue though: the handling of promises in tests. Right now, failing tests would time out and you wouldn't get to see the error that caused the rejection.
To fix this, all async tests should return a promise instead of using the done callback. That way, Jasmine automatically handles resolution and rejection of these promises.
Thanks a lot for the contribution!
@raphinesse I updated Jasmine to the latest version (3.1.0) without any issues. I know it is suggested to squash commits in this repo, but I put the updating of this version in a second commit as I think it makes sense to keep it separate.
As for the tests themselves, I have rewritten them to return the promises instead of calling done. There are some asynchronous tests where calling done is needed (such as testing that the promise is rejected). For those tests, I have added handling for the failure cases to ensure that all the tests fail in a meaningful way (that is, avoiding timeouts where possible).
I've done a more thorough review. I also included fixes for all my comments in an additional commit. It looks like a whole lot of changes, but most of them are simple Q -> Promise transformations. Please see my review comments for explanations to my changes.
Thanks again for your contribution and please do let me know if you're comfortable with the changes I made. I'm looking forward to your forthcoming test PRs
Another note: when we finally have unbundled dependencies, we probably should replace
So next time when you come across an untested homemade util, before investing time to write tests for it, consider looking for a lib that does the same job and include it instead. Having to maintain less code is always preferable.
Thanks for the detailed review, I really appreciate it. I would have looked into replacing
I have replied to most of your comments. On the topic of spying on
I am happy with your changes, and again very much appreciate your input. I will work on writing some more tests in another branch during the week.
By the way, I rebased the branch with master as there was a conflict in
Given the temporary nature of global spies, please feel free to revert back to using them if you want. My bad for not knowing better.
For me, this is good to go. I'd probably squash all commits, but I don't really care either way here. @dpogue what do you say?
Thanks again for this great PR and any following ones