-
Notifications
You must be signed in to change notification settings - Fork 3k
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 client to always use native setTimeout function. #1479
Conversation
…cket.io client to be used in testing infrastructure (such as Karma) where the clock may be mocked.
@vartan thanks for the pull request! There are several usages of |
Yeah, that seems like the right thing to do, I didn't realize that was split out of socket.io-client. Is there somewhere central you recommend I implement this? I'll take a look tomorrow. |
I sent a PR to engine.io-client, I'll refactor this one once that is submitted. thanks again. |
This allows to control the behavior of mocked timers (@sinonjs/fake-timers), depending on the value of the "useNativeTimers" option: - true: use native setTimeout function - false (default): use classic timers, that may be mocked The "installTimerFunctions" method will also be used in the `socket.io-client` package: ``` import { installTimerFunctions } from "engine.io-client/lib/util"; ``` Note: we could also have put the method in its own library, but that sounded a bit overkill Related: socketio/socket.io-client#1479
This allows to control the behavior of mocked timers (@sinonjs/fake-timers), depending on the value of the "useNativeTimers" option: - true: use native setTimeout function - false (default): use classic timers, that may be mocked The "installTimerFunctions" method will also be used in the `socket.io-client` package: ``` import { installTimerFunctions } from "engine.io-client/lib/util"; ``` Note: we could also have put the method in its own library, but that sounded a bit overkill Related: socketio/socket.io-client#1479
…cket.io client to be used in testing infrastructure (such as Karma) where the clock may be mocked.
6461b35
to
fe7127f
Compare
Hi Damien, I've updated this PR to use the changes in socketio/engine.io-client#672 |
I wonder if we should also bump up the version of engine.io-client to ensure the change is in |
friendly ping |
This allows to control the behavior of mocked timers (@sinonjs/fake-timers), depending on the value of the "useNativeTimers" option: - true: use native setTimeout function - false (default): use classic timers, that may be mocked Related: socketio/engine.io-client@5d1d5be
Merged as 4e1b656. I'll keep you updated once it is released. |
This was included in latest release: https://github.com/socketio/socket.io-client/releases/tag/4.2.0 Again, thanks for your work on this. |
This allows socket.io client to be used in testing infrastructure (such as Karma) where the clock may be mocked.
Note: the
socket.io.js
file is the generated output ofmake socket.io.js
, and should not be manually modified.The kind of change this PR does introduce
Current behaviour
If the test infrastructure socket attempts to reconnect while a mock clock is installed, it will never reconnect. This happens when Karma is configured to use socket.io.
New behaviour
If the socket attempts to reconnect while the mock clock is installed and
useNativeSetTimeout
is set, then it will not use the mocked clock and will reconnect normallyOther information (e.g. related issues)