-
Notifications
You must be signed in to change notification settings - Fork 248
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
Helper for delay in milliseconds #312
Conversation
Hi @prashanth-92! Thanks for your PR, but unfortunately your change doesn't actually introduce per-request delays. The added method instead sets the delay for all requests, so for example: mock.delayInMs(200).onGet("/foo").reply(200);
mock.delayInMs(0).onGet("/bar").reply(200); will cause no delay when a request to |
Hey @ctimmerm, yes my solution is setting the delay in the Just to see if I get this right, if we need to add it at an endpoint level, then we might need to introduce a state in the handlers per verb and then use delay it with a promise approach you mentioned in one of the comments. |
@ctimmerm I have a revised approach with delay per request. Can you please review it? |
Ping @ctimmerm If you have some time, please review this pull request |
Hey @ctimmerm when you have time, please review this pull request. I would really appreciate it. |
src/handle_request.js
Outdated
if(handler.length === 8){ | ||
delayPerRequest = handler[7]; | ||
} | ||
return adapter.delayResponse + delayPerRequest |
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.
Instead of adding it to the global delay, I think it would be more intuitive if it overrode the global delay instead.
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.
That actually makes sense, I have adjusted, please take a look.
Please re-review @ctimmerm |
Please re review. |
@ctimmerm please review. |
@ctimmerm Can you please re review? |
src/index.js
Outdated
return _this; | ||
} | ||
|
||
function withDelayInMs(delay){ |
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.
Naming inconstency: above method replyWithDelay
does not have InMs
suffix.
Rename to withDelay
?
I would also be interested to have |
The idea behind this pull request is to give a helper for introducing a delay time alone. Your new feature request can be addressed in another pull request. Feel free to open one. |
Hey guys, is this getting merged or nah? I just found a use case where I need a delay for a specific request. |
@ctimmerm If there are no concerns, can we merge this PR? I think it will be useful. |
d0e5c50
to
0926db6
Compare
hmm, a force push merged this accidentally and can't reopen. I'll merge this manually |
hah. reopen button shows up again. edit: nope. didn't work |
Released as v1.22.0 |
marcbachmann, prashanth-92 - I'm a bit late to the party but there's no documentation and I think the typescript definitions are missing... |
Also IMHO the API for this is now unintuitive (it looked like @ctimmerm had a good suggestion). Why the change to make this return the reply function rather than the request handler? |
Interested about that too. |
I opened a PR to add types to replyWithDelay |
#232 Attempts to provide a helper for adding a delay in milliseconds. The test shows a way to use the method.