Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slowing down the response #8

Open
avanderhoorn opened this issue Jul 31, 2015 · 11 comments
Open

Slowing down the response #8

avanderhoorn opened this issue Jul 31, 2015 · 11 comments

Comments

@avanderhoorn
Copy link

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.

@A A added the question label Jul 31, 2015
@A
Copy link
Owner

A commented Jul 31, 2015

Pretty nice idea! Give me some time to figure out the way to make it out.

@A A added the enhancement label Jul 31, 2015
@avanderhoorn
Copy link
Author

Great!

A added a commit that referenced this issue Aug 2, 2015
A added a commit that referenced this issue Aug 2, 2015
@A
Copy link
Owner

A commented Aug 2, 2015

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

@avanderhoorn
Copy link
Author

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:

@A
Copy link
Owner

A commented Aug 3, 2015

@avanderhoorn do you want make pull request? :D

@avanderhoorn
Copy link
Author

Ya, might be up for it, how would you want the API to look?

@A
Copy link
Owner

A commented Aug 3, 2015

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; })

@A
Copy link
Owner

A commented Aug 3, 2015

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

@A A added the v1.0 label Aug 10, 2015
@A
Copy link
Owner

A commented Oct 6, 2015

@avanderhoorn published with 0.2.0

@avanderhoorn
Copy link
Author

Fantastic! Which commit # was it?

@A
Copy link
Owner

A commented Oct 7, 2015

9db610c but still without ability to setup it for endpoint. You can make PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants