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

Make maxLoops for fake timers configurable #8257

Closed
mxmzb opened this issue Apr 1, 2019 · 7 comments · Fixed by #12572
Closed

Make maxLoops for fake timers configurable #8257

mxmzb opened this issue Apr 1, 2019 · 7 comments · Fixed by #12572

Comments

@mxmzb
Copy link

mxmzb commented Apr 1, 2019

🚀 Feature Proposal

I'd like to be able to configure maxLoops (see https://github.com/facebook/jest/blob/master/packages/jest-fake-timers/src/jestFakeTimers.ts#L88) myself when using jest.useFakeTimers()

Motivation

I am writing a timer app, which actually may count to more than 100.000ms and it would still make sense. Unable to test this though to this limitation.

Pitch

The line already expects an argument which seems to be able to come from somewhere, but the API isn't making this really publically accessible. I don't see a reason why this should not be an optional param in jest.useFakeTimers().

@mxmzb
Copy link
Author

mxmzb commented Apr 2, 2019

As a current workaround, it is possible to stack jest.advanceTimersByTime(), e.g.

jest.advanceTimersByTime(100000);
jest.advanceTimersByTime(100000);

Also, weirdly enough, the number in the code (https://github.com/facebook/jest/blob/master/packages/jest-fake-timers/src/jestFakeTimers.ts#L88) says 100000 but you actually hit the limit at 1000000.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@davidmccabe
Copy link
Contributor

Another reason to make this configurable is to speed up debugging in cases where an infinite loop exists. It can take a long time for 100,000 iterations to go by!

@github-actions github-actions bot removed the Stale label Mar 5, 2022
@SimenB
Copy link
Member

SimenB commented Mar 5, 2022

I think taking an options bag to useFakeTimers (or in timers in config) should be fine. Would also unblock e.g. #12452 (I've seen others as well, my searching is failing me, tho).

Anybody wanna work on a PR for this? I think modern or legacy today should be normalized to {strategy: 'modern'} or something.

Jest 28 is a good time to make such a breaking change to config 🙂

@mrazauskas
Copy link
Contributor

Hm.. The original issue is rather puzzling. maxLoops option is mentioned as possible solution (this is the count timers that will be run), but the workaround is done through calling jest.advanceTimersByTime(100000) (here we have milliseconds, not the count of timers).

@mxmzb This is an old issue, of course. Could you to take a look, please? I am working on the implementation of timerLimit (just a different name for maxLoops) option in #12572, but can this really solve your problem?

@SimenB
Copy link
Member

SimenB commented Apr 5, 2022

@github-actions
Copy link

github-actions bot commented May 6, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants