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

Support declarative response delays #399

Open
diego-aquino opened this issue Sep 8, 2024 · 0 comments
Open

Support declarative response delays #399

diego-aquino opened this issue Sep 8, 2024 · 0 comments
Labels
feature New feature or request
Milestone

Comments

@diego-aquino
Copy link
Member

diego-aquino commented Sep 8, 2024

Users currently can implement response delays by using a computed response handler:

const handler = interceptor
  .get('/users')
  .respond(async () => {
    await new Promise((resolve) => setTimeout(resolve, 1000))
    return { status: 200, body: [] } 
  })

We could also allow declarative delays.

Proposal

A new handler method to declare a fixed or ranged delay. If a range is provided, a random value is selected within that interval.

const handler = interceptor
  .get('/users')
  .delay(200) // a fixed delay of 200ms will be used for each request
  .respond({ status: 200, body: [] })
// ...
const handler = interceptor
  .get('/users')
  .delay((request) => {
    return request.url.includes('slow=true') ? { min: 200, max: 1000 } : 0
  })
  .respond({ status: 200, body: [] })
// ...

Providing a way to use default delays per interceptor and for all interceptors is also a good idea.

@diego-aquino diego-aquino added the feature New feature or request label Sep 8, 2024
@diego-aquino diego-aquino moved this to Backlog in Zimic Sep 8, 2024
@diego-aquino diego-aquino added this to the v0.15.0 milestone Sep 8, 2024
@diego-aquino diego-aquino moved this from Backlog to To do in Zimic Sep 8, 2024
@diego-aquino diego-aquino removed this from the v0.15.0 milestone Nov 15, 2024
@diego-aquino diego-aquino moved this from To do to Backlog in Zimic Nov 16, 2024
@diego-aquino diego-aquino modified the milestones: v0.15.0, v0.13.0 Dec 30, 2024
@diego-aquino diego-aquino moved this from Backlog to To do in Zimic Dec 30, 2024
@diego-aquino diego-aquino modified the milestones: v0.13.0, v0.14.0 Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: To do
Development

No branches or pull requests

1 participant