-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
node test mock timer promisified setTimeout & setInterval don't always return the specified value #50307
Comments
For setTimeoutPromisified: To ensure that the specified value is returned, even if it's falsy, we can modify the line to check if result is 'undefined': For setIntervalPromisified:
So, first we can store the original value like: Then, in the callback, emit the originalValue instead of the incremented startTime: |
Disagree. It should always return the same value the the original
That would work. I don't know what the original intention behind returning these other values was. If they are not needed, I'd just remove them completely. If they are needed for some reason, they need to be communicated in some other way... |
This seems like a pretty straightforward bug @nodejs/test_runner @ErickWendel where we should check if result is passed instead of using Your report and diagnosis seems correct @mika-fischer thank you for opening a good report. Would you be interested in opening a PR to align |
Should we use |
That the fakes should all return the same types of results as the originals (even though I personally don't like these overloads) - the whole point of fake timers is that they match the originals. |
Yes, I can do a PR tomorrow. |
promisified setInterval can be passed a value that is returned by the async iterable. The mocked promisified setInterval used this value for its own purposes. This brings the mocked version in line with the original. Fixes: nodejs#50307
See #50331 Turns out setTimeout was already fixed in main |
promisified setInterval can be passed a value that is returned by the async iterable. The mocked promisified setInterval used this value for its own purposes. This brings the mocked version in line with the original. Fixes: nodejs#50307
promisified setInterval can be passed a value that is returned by the async iterable. The mocked promisified setInterval used this value for its own purposes. This brings the mocked version in line with the original. Fixes: nodejs#50307
For completeness, the setTimeout issue was already fixed here |
Version
v20.5.1
Platform
Microsoft Windows NT 10.0.22621.0 x64
Subsystem
test
What steps will reproduce the bug?
Mocked promisified
setTimeout
&setInterval
don't return falsy values, and instead return numbers.The reason for
setTimeout
is here. It works correctly for truthy values, but returns an id for falsy values.setInterval
completely captures the value parameter for its own purposes so that it never resturns the value given tosetInterval
(see here).fails with
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
The mocked functions should return the value specified by the caller.
What do you see instead?
The mocked functions (sometimes) return something else.
Additional information
No response
The text was updated successfully, but these errors were encountered: