-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Detect infinite loops and stop tests #9785
Comments
I would love to work on it ! 🚀 |
I started working on the feature by analysing Inspector API usage and how Rome is using it. I made a schema to represent the process, to know if I was going in the right direction. |
Thanks for picking this up @ayshiff! |
That could work, but I think ideally we'd want something with the inspector, I don't think we want to rely on some babel plugin to run |
Another downside of Babel plugin is you have to hardcode a number of iterations. |
I've been stuck in my progress for a moment. This is where I am:
The I will need some help on this one 👍 |
Hi @ayshiff and sorry this went under the radar for months. It sounds like you already got quite far and it'd be a shame to lose all this work. I was not involved in writing |
Hi @jeysal ! |
The Node.js runInContext() API is used by Jest to run scripts, and its options include a |
@octogonz happy to take a PR adding some sort of sane timeout (15 minutes? 30? 60? people might have looong running e2e tests or something) |
Would a CLI option be appropriate for something like this? Such as |
@SimenB please let me know if this work and whether implementing a |
I'm working on a I'm using jest 26: import { describe, expect, it, jest } from '@jest/globals'
import fakeTimers from '@sinonjs/fake-timers'
type ActionHandler<T = unknown> = () => Promise<T>
const sleep = {
now: (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
}
const shortPoll = {
do: function <T = unknown> (
action: ActionHandler<T>,
delayInMilliseconds: number
) {
const run = async () => {
await action()
await sleep.now(delayInMilliseconds)
await run()
}
void run()
}
}
describe('shortPoll', () => {
it('should execute action, wait delayInMilliseconds and repeat indefinitely', async () => {
const clock = fakeTimers.install()
const delay = 2000
const action = jest.fn()
shortPoll.do(action as ActionHandler, delay)
// by advancing the timer five times assume the function runs indefinitely
// also validate action() was called immediately without any timers when shortPoll was first called
// if you move sleep() before action() this test will report less invocation calls than expected
// if you move run() before sleep() the tests goes into infinite loop and never fails
const initialInvocation = 1
const totalCycles = 5
await clock.tickAsync(delay * totalCycles)
expect(action).toHaveBeenCalledTimes(initialInvocation + totalCycles)
clock.uninstall()
})
}) |
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 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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. |
🚀 Feature Proposal
Similar to Rome.
https://twitter.com/sebmck/status/1114672543133097984.
https://github.com/facebookexperimental/rome/blob/1add11d62d787ff646dcc52e8b35cb41c730a30e/packages/%40romejs/core/master/testing/TestRunner.ts#L342-L405
Motivation
Infinite loops can be hard to track down, we should try to help the user. We don't currently attach an inspector, but it shouldn't be too much work doing so
The text was updated successfully, but these errors were encountered: