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!
You can use setupFilesAfterEnv:[array]
in your jest config file https://jestjs.io/docs/configuration#setupfilesafterenv-array
Make a setup file (eg 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'],
...
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.