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

feat(msw): make delay optional #1360

Merged
merged 1 commit into from
May 9, 2024

Conversation

AllieJonsson
Copy link
Contributor

Status

READY

Description

This allows disabling the delay call in mocked api calls, which makes the MockHandler sync instead of async.
As per request of Nate on discord

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

Make sure delay still can be set by both number and function and that the MockHandler is async.
Try changing the delay settings to false and make sure the MockHandlers become synchronous and no call to delay is made.

@@ -5,7 +5,7 @@ export const getDelay = (
options?: GlobalMockOptions,
): GlobalMockOptions['delay'] => {
const overrideDelay =
typeof override?.mock?.delay === 'number'
override?.mock?.delay !== undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit unsure about this, but it feels like override always should override when present, and not only when it's overridden by a number?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Not sure why this decision was made?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it was missed when support for functions was added?

@AllieJonsson AllieJonsson force-pushed the fix/optional-delay branch from ecf6f5f to d7b10f3 Compare May 8, 2024 07:16
@melloware melloware added this to the 6.28.0 milestone May 8, 2024
@melloware melloware added enhancement New feature or request mock Related to mock generation labels May 8, 2024
@melloware melloware requested a review from soartec-lab May 8, 2024 13:01
@AllieJonsson AllieJonsson changed the title fix(msw): make delay optional feat(msw): make delay optional May 8, 2024
Copy link
Member

@soartec-lab soartec-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AffeJonsson
Thank you for the nice update. I made a comment in one place, so please check it.

Comment on lines +100 to +105
return http.${verb}('${route}', ${
delay === false
? '() => {'
: `async () => {
await delay(${isFunction(delay) ? `(${delay})()` : delay});`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the definition itself is unnecessary if delay is false, but what do you think?

Suggested change
return http.${verb}('${route}', ${
delay === false
? '() => {'
: `async () => {
await delay(${isFunction(delay) ? `(${delay})()` : delay});`
}
return http.${verb}('${route}', ${
delay === isFunction(delay) || isNumber(delay)
? `async () => {
await delay(${isFunction(delay) ? `(${delay})()` : delay});`
: ''
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the second argument to http.get must be a function, so we cannot remove the () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the mock handler looks with delay: false
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's nice. That's what I wanted.

Copy link
Member

@soartec-lab soartec-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@soartec-lab soartec-lab merged commit 393a6d8 into orval-labs:master May 9, 2024
2 checks passed
@melloware melloware modified the milestones: 6.28.0, 6.29.0 May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mock Related to mock generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants