-
-
Notifications
You must be signed in to change notification settings - Fork 473
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 delay modes (ctx.delay) #538
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 45a2e13:
|
b54496b
to
91e91b7
Compare
Failing to test an infinite delay scenario in Puppeteer, because it throws an exception |
I've added only the |
36e0978
to
45a2e13
Compare
Experienced a failing test. Passes locally. FAIL msw-api/setup-server/scenarios/fall-through.node.test.ts (60.105 s)
● falls through all relevant handler even if none returns response
: Timeout - Async callback was not invoked within the 60000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 60000 ms timeout specified by jest.setTimeout.Error:
41 | })
42 |
> 43 | test('falls through all relevant handler even if none returns response', async () => {
| ^
44 | const res = await fetch('https://test.mswjs.io/blog/article', {
45 | method: 'POST',
46 | })
at new Spec (../node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
at Object.<anonymous> (msw-api/setup-server/scenarios/fall-through.node.test.ts:43:1) |
Motivation
Using
ctx.delay(Infinity)
executes the response timer immediately instead of delaying the response indefinitely, as expected. That's due to howsetTimeout
(that powers response callback to the worker) operates in JavaScript. These changes aim to add support for infinite response delays and add some safeguards against using large integers as thectx.delay
inpt.Changes
ctx.delay
now supports delay modes—enums that abstract specific delay behaviors:real
, uses a random realistic server response time.infinite
, uses a maximum allowed integer as asetTimeout
duration to delay a response indefinitely (useful when emulating pending/loading states).ctx.delay
now throws an exception when givenInfinity
,Number.MAX_VALUE
,Number.MAX_SAFE_INTEGER
, or any integer value larger than the maximum allowedsetTimeout
duration.ctx.delay
now throws an exception when given an unknown delay mode.Usage