superagent-mocker
superagent-mocker copied to clipboard
Slowing down the response
I'm looking at how we can simulate as much as possible what our real/production environment in offline development scenarios. Inline with this, we are fully faking out the server to be used during client dev work.
With this in mind, it would be nice if the api facilitated some way in which once could control when superagents end callback gets called? In my case I would call it from within a setTimeout.
Pretty nice idea! Give me some time to figure out the way to make it out.
Great!
Yay! @avanderhoorn, is it ok for you?
var mock = require('superagent-mocker');
// set just number
mock.timeout = 100;
// Or function to get random
mock.timeout = function () {
return Math.random() * 1e4 |0;
}
https://github.com/rambler-digital-solutions/superagent-mocker#timeout
Yep that is nice! I had originally thought about it being configurable on an endpoint by endpoint basis so endpoints that take longer than other, etc could be accounted for but I'll take what I can get and having it work globally does save having to manually setup each one. I also like being able to pass in a function instead of just a int, so nice touch there. :shipit:
@avanderhoorn do you want make pull request? :D
Ya, might be up for it, how would you want the API to look?
Awesome! What do you think about chained API like superagent?
require('superagent-mocker')
.get('/topics/:id', function(req) {
return {
id: req.params.id,
content: 'Hello World!'
};
})
.timeout(100)
// or
.timeout(function() { return Math.random() * 1e4 |0; })
btw, I can release new version with mock.timeout, but if you want to add ability to set timeout to each endpoint, I will wait your PR before
@avanderhoorn published with 0.2.0
Fantastic! Which commit # was it?
9db610c0a6825fb69aad2a39ba7d97f3ea024602 but still without ability to setup it for endpoint. You can make PR for it.