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

Defining test timeout as a config parameter #6216

Closed
thymikee opened this issue May 21, 2018 · 18 comments
Closed

Defining test timeout as a config parameter #6216

thymikee opened this issue May 21, 2018 · 18 comments

Comments

@thymikee
Copy link
Collaborator

🚀 Feature Proposal

I'd like to propose introducing a new config parameter config called timeout, that would accept a number or a string.

Motivation

To set a global timeout different than Jest's default, one must use a setupTestFrameworkScriptFile config and create a new file. This is a bit cumbersome, isn't it?

It would also play nice with the API we have for already: jest.setTimeout(number).

Example

"jest": {
  "timeout": 60000
}

Pitch

Why does this feature belong in the
Jest core platform?

It is a config change, duh.

@SimenB
Copy link
Member

SimenB commented May 21, 2018

Makes sense. Should the name be testTimeout or something to be clear this is not a global test suite timeout, but per test?

@thymikee
Copy link
Collaborator Author

I was taking that into consideration, and just decided to go jest.setTimeout() way, as we don't currently have mechanisms to limit per-suite or per-all-suites timeouts. We can add them later and name accordingly though.

@restfulhead
Copy link

restfulhead commented Jun 6, 2018

Could this parameter be added to the CLI as well? Reason for this is that when I use a debugger to step through code, I would like to set it to infinite (or very high). But I don't want to change this setting in our config, because then this change might be committed by accident...

Or is it possible to point to a different config via another cli parameter?

@SimenB
Copy link
Member

SimenB commented Jun 7, 2018

Having a flag like 'disable timeouts' on the cli to help debugging makes more sense to me than being able to set a timeout

@felixfbecker
Copy link

I can't believe this doesn't exist? How is it even possible to use a step debugger if every test times out after 5s?

@bluedusk
Copy link

bluedusk commented Mar 6, 2019

So still no way to set default timeout value ?

@krzkaczor
Copy link

@bluedusk you can always just drop somewhere jest.setTimeout(2137*1000); or something similar.

@krzkaczor
Copy link

krzkaczor commented Mar 15, 2019

I think that users should be able to:

  • make timeout part of the config. Can be useful when all tests are expected to be slow (imagine using jest to drive e2e tests)
  • provide timeout as CLI parameter / disable timeouts - mostly useful when working with the debugger.

@thymikee what do you think about it? I can try implementing these.

@thymikee
Copy link
Collaborator Author

@SimenB @krzkaczor so we could have a single --timeout flag that would take a number or Infinity for no-timeout at all, what do you think?

@krzkaczor
Copy link

@thymikee I think 0 is more obvious (mocha does it as well).

@ert78gb
Copy link
Contributor

ert78gb commented May 12, 2019

Anyone working on this issue? If no, I pick up.

@MajorBreakfast
Copy link
Contributor

@ert78gb Is this issue covered by your PR?

@ert78gb
Copy link
Contributor

ert78gb commented Sep 23, 2019

Yes and it is landed in 24.9.0

@thymikee
Copy link
Collaborator Author

Looks like we can close this :)

@thernstig
Copy link
Contributor

I am confused as to what this is supposed to do. I tried the config like this:

module.exports = {
  verbose: true
  projects: [
    {
      displayName: 'E2E',
      preset: 'jest-playwright-preset',
      rootDir: 'tests/',
      testTimeout: 100,
      setupFilesAfterEnv: [
        '<rootDir>/jest.setup.js',
      ],
    },
  ],
};

I have tests taking more than 100 ms obviously, but it still does not time out in any way. How come?

And what is the difference between the config testTimeout and jest.setTimeout(). Reading this thread it sounds like testTimeout is per test case i.e. per it() and that jest.setTimeout() is per "test file" since you refer to it as global. But in the docs it sounds like both are per "test case" (i.e. per it()), see https://jestjs.io/docs/en/jest-object#jestsettimeouttimeout and https://jestjs.io/docs/en/jest-object#jestsettimeouttimeout

@jeysal
Copy link
Contributor

jeysal commented Mar 6, 2020

It can be described both as 'per test' and 'per test file' - using jest.setTimeout() you set it for each individual test in the entire test file. If you know a way to make this clearer in the docs feel free to shoot over a PR 😄
Also, if tests exceed your timeout limit, note that it only applies to asynchronous operations. If a test synchronously takes a long time to run (heavy computations or lots of sync Node APIs, Jest can do nothing to stop it (that is not how the Node event loop works).

@thernstig
Copy link
Contributor

thernstig commented Mar 6, 2020

Good info! I have one since before, I suppose I should take one for the team and try to push a PR.

I'm running tests in asynchronous operations. Setting testTimeout: 100, like above still did not work to time out the test cases, but jest.setTimeout(100) did. I.e. it doesn't work, at least not with projects.

@github-actions
Copy link

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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants