Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest threshold for a test to be reported as slow

Tags:

jestjs

I use jest to drive selenium tests and it reports a test that takes 12 seconds as being slow (the duration is highlighted in red). In this context 12 seconds is fine.

How can I configure the threshold to 30 seconds?

like image 286
Sylvain Avatar asked Feb 26 '19 19:02

Sylvain


3 Answers

Late 2020 update - previous answers are outdated

Configure the slowTestThreshold in seconds, as shown in the docs

// jest.config.js
module.exports = {
    /* ... */
    slowTestThreshold: 30,
    /* ... */
}
like image 117
andrestone Avatar answered Oct 10 '22 10:10

andrestone


Jest is currently hard-coded to consider any test running over 5 seconds as long:

if (runTime !== null && runTime > 5) {
  testDetail.push(LONG_TEST_COLOR(runTime + 's'));
}

Looks like you would need to fork the repo or submit a PR if you wanted to change that.

like image 24
Brian Adams Avatar answered Oct 10 '22 10:10

Brian Adams


Jest migrated from milliseconds to seconds

Jest allows configuration property slowTestThreshold which you can set in milliseconds.

Jest allows configuration property slowTestThreshold which you can set in seconds.

example jest.config.js

module.exports = async () => {
  return {
    slowTestThreshold: 30
  };
};

this will show error if tests run for more than 30 seconds

like image 20
Bharat D Bhadresha Avatar answered Oct 10 '22 09:10

Bharat D Bhadresha