10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jest-circus と jest.retryTimes(n) で成功するまでリトライする

Posted at

jest のオプション見てたら retryTimes というのがあった。
https://jestjs.io/docs/ja/jest-object#jestretrytimes

しかし普通に書いただけだと動かない。https://github.com/facebook/jest/tree/master/packages/jest-circus と一緒に使えとのこと。 The next-gen test runner for Jest

※ jest のセットアップは省略

yarn add jest-circus -D

30% で成功するテストを 3回繰り返す。

import assert from "assert";

jest.retryTimes(3);
it("retry", () => {
  console.log("xxx", Date.now());
  assert.ok(Math.random() > 0.3);
});
❯ yarn jest --testRunner='jest-circus/runner' src
yarn run v1.17.3
 PASS  src/__tests__/retrySpecCheck.test.ts
  ● Console

    console.log src/__tests__/retrySpecCheck.test.ts:5
      xxx 1568271139936
    console.log src/__tests__/retrySpecCheck.test.ts:5
      xxx 1568271139949
    console.log src/__tests__/retrySpecCheck.test.ts:5
      xxx 1568271139951

flaky test 周りで便利

10
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?