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

Fix nock compatibility with fake timers #4428

Open
Gudahtt opened this issue Jun 14, 2024 · 1 comment
Open

Fix nock compatibility with fake timers #4428

Gudahtt opened this issue Jun 14, 2024 · 1 comment
Assignees
Labels
bug Something isn't working team-wallet-framework

Comments

@Gudahtt
Copy link
Member

Gudahtt commented Jun 14, 2024

The nock library is not compatible with the fake timers we use in unit tests because it uses the Node.js timers API. This API is not mocked correctly by the version of Jest we are using.

Jest uses @sinon/fake-timers internally, which didn't support mocking the Node.js timers API until v11.0.0 (see sinonjs/fake-timers#467) This package is updated in Jest as part of the v30 release, which is currently under development.

Elsewhere we have worked around this problem by patching the nock library to use global timers rather than the timers API. Global timers are mocked correctly by our fake timers. We should implement the same fix here, so that fake timers work more predictably. We can remove this workaround when we update to Jest v30.

See here for how we did this in the extension repository: MetaMask/metamask-extension#24805

I suspect that we haven't seen this issue come up in core yet because all of our nock delays use very small intervals, so we don't notice that they aren't correctly mocked.

@Gudahtt Gudahtt added bug Something isn't working team-wallet-framework labels Jun 14, 2024
@Gudahtt Gudahtt self-assigned this Jul 16, 2024
@golergka
Copy link

golergka commented Oct 2, 2024

Thank you! I ran into the same problem and solving it using your patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working team-wallet-framework
Projects
None yet
Development

No branches or pull requests

2 participants