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

Allow timing to be boolean, default to 'false' due to Pretender handling #1093

Open
ivangreene opened this issue Oct 27, 2023 · 6 comments
Open

Comments

@ivangreene
Copy link

ivangreene commented Oct 27, 2023

In Pretender, a delay value of zero will still cause the request to be handled async with a setTimeout: https://github.com/pretenderjs/pretender/blob/65fbf0a608f2e4b4fd79657a77a41f52077074a9/src/pretender.ts#L259-L276

The timing parameter should be typed as number | boolean so that false can be passed for synchronous handling, and it's worth considering making the default 'false' during tests. I found that with the setTimeout, even with a value of 0, my responses were taking about 500ms to return, whereas with false the same measurement is about 50ms

@ivangreene
Copy link
Author

To get around this in the meantime (it gets passed through to Pretender just fine):

server.timing = false as unknown as number;

@IanVS
Copy link
Collaborator

IanVS commented Oct 30, 2023

This should be fixed in https://github.com/miragejs/miragejs/releases/tag/v0.1.48, and 0 should be respected. Please try it out and let us know if it's working. It will still be async, but should not take anywhere near the default 400ms.

@ivangreene
Copy link
Author

@IanVS unfortunately v0.1.48 has not fixed the issue. Passing 0 to Pretender still causes the response to be handled async, which is causing the delay (a setTimeout with delay of 0 is still delayed by approx 500ms in my environment for some reason). False is the only value that causes it to be handled sync without a delay

@ivangreene
Copy link
Author

Here is a screenshot after debugging, confirming that 0 has been passed into Pretender but we are failing the condition I linked to and handling async still:
Screenshot 2023-10-30 at 9 53 14 AM

@IanVS
Copy link
Collaborator

IanVS commented Oct 30, 2023

It seems to me like you should not expect http requests, even mocked ones, to return synchronously, and it's very strange to me that a single tick of the event loop would take half a second, which is why I think something else must be going on. Out of curiosity, what timing do you get if you pass 1 as the delay?

@ivangreene
Copy link
Author

Passing 1 is similar; any value between 0 and 500 is about the same at around 500, and anything above that takes about as long as the timing

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

No branches or pull requests

2 participants