Some of my test files in Jest are flaky. Identifying individual files and adding jest.retryTimes(2)
to the top of those files helps. I would like to add that as a global setting rather than needing to add that line to the top of every file.
Is there a way to configure Jest so that it will always retry failed tests rather than needing to add that setting in each file?
Thanks!
Some of my test files in Jest are flaky. Identifying individual files and adding jest.retryTimes(2)
to the top of those files helps. I would like to add that as a global setting rather than needing to add that line to the top of every file.
Is there a way to configure Jest so that it will always retry failed tests rather than needing to add that setting in each file?
Thanks!
Share Improve this question asked Jul 27, 2022 at 20:32 Sam KingSam King 2,19822 silver badges31 bronze badges1 Answer
Reset to default 6You can use setupFilesAfterEnv:[array]
in your jest config file https://jestjs.io/docs/configuration#setupfilesafterenv-array
Make a setup file (e.g setup-jest.js) and include the jest.retryTimes(2)
in there.
// setup-jest.js
jest.retryTimes(2)
// jest.config.js
module.exports = {
setupFilesAfterEnv: ['<rootDir>/setup-jest.js'],
...
};