|
1 | 1 | import Retry from './src/retry.js' |
2 | 2 |
|
3 | | -export default function setup (testFn, defaultMaxRuns = 2) { |
| 3 | +export default function setup (testFn, { maxRuns: defaultMaxRuns = 2, beforeRetry } = {}) { |
4 | 4 | const retry = function (name, callback, maxRuns = defaultMaxRuns) { |
5 | | - return new Retry([name], callback, maxRuns, testFn) |
| 5 | + return new Retry([name], callback, maxRuns, testFn, beforeRetry) |
6 | 6 | } |
7 | 7 | retry.todo = function (name, callback, maxRuns = defaultMaxRuns) { |
8 | | - return new Retry([name], callback, maxRuns, testFn.todo) |
| 8 | + return new Retry([name], callback, maxRuns, testFn.todo, beforeRetry) |
9 | 9 | } |
10 | 10 | retry.skip = function (name, callback, maxRuns = defaultMaxRuns) { |
11 | | - return new Retry([name], callback, maxRuns, testFn.skip) |
| 11 | + return new Retry([name], callback, maxRuns, testFn.skip, beforeRetry) |
12 | 12 | } |
13 | 13 | retry.if = function (name, condition, callback, maxRuns = defaultMaxRuns) { |
14 | | - return new Retry([name, condition], callback, maxRuns, testFn.if) |
| 14 | + return new Retry([name, condition], callback, maxRuns, testFn.if, beforeRetry) |
15 | 15 | } |
16 | 16 | retry.only = function (name, callback, maxRuns = defaultMaxRuns) { |
17 | | - return new Retry([name], callback, maxRuns, testFn.only) |
| 17 | + return new Retry([name], callback, maxRuns, testFn.only, beforeRetry) |
18 | 18 | } |
19 | 19 |
|
20 | 20 | retry.each = function (name, dataset, callback, maxRuns = defaultMaxRuns) { |
21 | | - return new Retry([name, dataset], callback, maxRuns, testFn.each) |
| 21 | + return new Retry([name, dataset], callback, maxRuns, testFn.each, beforeRetry) |
22 | 22 | } |
23 | 23 | retry.todo.each = function (name, dataset, callback, maxRuns = defaultMaxRuns) { |
24 | | - return new Retry([name, dataset], callback, maxRuns, testFn.todo.each) |
| 24 | + return new Retry([name, dataset], callback, maxRuns, testFn.todo.each, beforeRetry) |
25 | 25 | } |
26 | 26 | retry.skip.each = function (name, dataset, callback, maxRuns = defaultMaxRuns) { |
27 | | - return new Retry([name, dataset], callback, maxRuns, testFn.skip.each) |
| 27 | + return new Retry([name, dataset], callback, maxRuns, testFn.skip.each, beforeRetry) |
28 | 28 | } |
29 | 29 | retry.if.each = function (name, condition, dataset, callback, maxRuns = defaultMaxRuns) { |
30 | | - return new Retry([name, condition, dataset], callback, maxRuns, testFn.if.each) |
| 30 | + return new Retry([name, condition, dataset], callback, maxRuns, testFn.if.each, beforeRetry) |
31 | 31 | } |
32 | 32 | retry.only.each = function (name, dataset, callback, maxRuns = defaultMaxRuns) { |
33 | | - return new Retry([name, dataset], callback, maxRuns, testFn.only.each) |
| 33 | + return new Retry([name, dataset], callback, maxRuns, testFn.only.each, beforeRetry) |
34 | 34 | } |
35 | 35 | return retry |
36 | 36 | } |
0 commit comments