最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set Jest test retries globally - Stack Overflow

programmeradmin4浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

You 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'],
  ...
};
发布评论

评论列表(0)

  1. 暂无评论