diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 100% rename from .eslintrc.js rename to .eslintrc.cjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc428dd..971c2e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: # filtering branches here prevents duplicate builds from pull_request and push branches: - main + - master - "v*" # always run CI for tags tags: @@ -25,7 +26,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout Code - uses: actions/checkout@v4 + uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} diff --git a/index.d.ts b/main.d.ts similarity index 87% rename from index.d.ts rename to main.d.ts index 3c48aee..3aa97f1 100644 --- a/index.d.ts +++ b/main.d.ts @@ -23,4 +23,8 @@ * }); */ -declare function retry(name: string, callback: (assert: Object) => void | Promise, maxRuns?: number): void; +declare function retry( + name: string, + callback: (assert: Object) => void | Promise, + maxRuns?: number, +): void; diff --git a/package.json b/package.json index 9cfc86d..bac6a4d 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,8 @@ }, "license": "ISC", "author": "mrloop", - "exports": { - "require": "./index.js", - "import": "./main.js", - "default": "./main.js" - }, - "main": "index.js", + "type": "module", + "exports": "./main.js", "module": "main.js", "types": "./index.d.ts", "scripts": { @@ -30,9 +26,6 @@ "dev": "qunit --watch", "lint": "eslint index.js" }, - "dependencies": { - "esm": "^3.2.25" - }, "devDependencies": { "@release-it-plugins/lerna-changelog": "^7.0.0", "dotenv": "^8.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 98ddf5c..9c1d193 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,10 +7,6 @@ settings: importers: .: - dependencies: - esm: - specifier: ^3.2.25 - version: 3.2.25 devDependencies: '@release-it-plugins/lerna-changelog': specifier: ^7.0.0 @@ -1033,10 +1029,6 @@ packages: deprecated: This version is no longer supported. Please see https://eslint.org/version-support for other options. hasBin: true - esm@3.2.25: - resolution: {integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==} - engines: {node: '>=6'} - espree@7.3.1: resolution: {integrity: sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==} engines: {node: ^10.12.0 || >=12.0.0} @@ -3761,8 +3753,6 @@ snapshots: transitivePeerDependencies: - supports-color - esm@3.2.25: {} - espree@7.3.1: dependencies: acorn: 7.4.1 diff --git a/test/retry-only.js b/test/retry-only.js index 9375fd6..0f363d1 100644 --- a/test/retry-only.js +++ b/test/retry-only.js @@ -1,44 +1,60 @@ -const setup = require('../index.js') -const QUnit = require('qunit') - -const retry = setup(QUnit.test) - -QUnit.module('retry.only', function () { - const calls = [] - - retry.only('count only retries', function (assert, currentRun) { - calls.push(['only', currentRun]) - - assert.equal(currentRun, 2) - }) - - retry('count non-only retries', function (assert, currentRun) { - calls.push(['non-only', currentRun]) - - assert.equal(currentRun, 2) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [['only', 1], ['only', 2]]) - }) -}) - -QUnit.module('retry.only.each', function () { - const calls = [] - - retry.only.each('count only retries', ['A', 'B'], function (assert, data, currentRun) { - calls.push(['only', data, currentRun]) - - assert.equal(currentRun, 2) - }) - - retry.each('count non-only retries', ['A', 'B'], function (assert, data, currentRun) { - calls.push(['non-only', data, currentRun]) - - assert.equal(currentRun, 2) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [['only', 'A', 1], ['only', 'A', 2], ['only', 'B', 1], ['only', 'B', 2]]) - }) -}) +import setup from "qunit-retry"; +import QUnit from "qunit"; + +const retry = setup(QUnit.test); + +QUnit.module("retry.only", function () { + const calls = []; + + retry.only("count only retries", function (assert, currentRun) { + calls.push(["only", currentRun]); + + assert.equal(currentRun, 2); + }); + + retry("count non-only retries", function (assert, currentRun) { + calls.push(["non-only", currentRun]); + + assert.equal(currentRun, 2); + }); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + ["only", 1], + ["only", 2], + ]); + }); +}); + +QUnit.module("retry.only.each", function () { + const calls = []; + + retry.only.each( + "count only retries", + ["A", "B"], + function (assert, data, currentRun) { + calls.push(["only", data, currentRun]); + + assert.equal(currentRun, 2); + }, + ); + + retry.each( + "count non-only retries", + ["A", "B"], + function (assert, data, currentRun) { + calls.push(["non-only", data, currentRun]); + + assert.equal(currentRun, 2); + }, + ); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + ["only", "A", 1], + ["only", "A", 2], + ["only", "B", 1], + ["only", "B", 2], + ]); + }); +}); diff --git a/test/retry.js b/test/retry.js index 4e9abac..eaba85b 100644 --- a/test/retry.js +++ b/test/retry.js @@ -1,373 +1,516 @@ -const setup = require('../index.js') -const QUnit = require('qunit') +import setup from "qunit-retry"; +import QUnit from "qunit"; const timeout = function (ms) { - return new Promise(resolve => setTimeout(resolve, ms)) -} + return new Promise((resolve) => setTimeout(resolve, ms)); +}; -const retry = setup(QUnit.test) +const retry = setup(QUnit.test); -QUnit.module('test retries and result message', hooks => { - const messages = [] +QUnit.module("test retries and result message", (hooks) => { + const messages = []; hooks.afterEach(function () { if (QUnit.config.current.assertions.length) { - messages.push(QUnit.config.current.assertions[0].message) + messages.push(QUnit.config.current.assertions[0].message); } - }) - - retry('test retry five times', function (assert, currentRun) { - assert.equal(currentRun, 5) - }, 5) - - retry('test retry five times with custom message', function (assert, currentRun) { - assert.equal(currentRun, 5, 'should equal 5') - }, 5) - - retry('test stopping at 3 retries', function (assert, currentRun) { - assert.equal(currentRun, 3) - }, 5) - - retry('test stopping at 3 retries with custom message', function (assert, currentRun) { - assert.equal(currentRun, 3, 'should equal 3') - }, 5) - - retry('test stopping at 1 try', function (assert, currentRun) { - assert.equal(currentRun, 1) - }, 5) - - retry('test stopping at 1 try with custom message', function (assert, currentRun) { - assert.equal(currentRun, 1, 'should equal 1') - }) - - QUnit.test('verify retries', function (assert) { + }); + + retry( + "test retry five times", + function (assert, currentRun) { + assert.equal(currentRun, 5); + }, + 5, + ); + + retry( + "test retry five times with custom message", + function (assert, currentRun) { + assert.equal(currentRun, 5, "should equal 5"); + }, + 5, + ); + + retry( + "test stopping at 3 retries", + function (assert, currentRun) { + assert.equal(currentRun, 3); + }, + 5, + ); + + retry( + "test stopping at 3 retries with custom message", + function (assert, currentRun) { + assert.equal(currentRun, 3, "should equal 3"); + }, + 5, + ); + + retry( + "test stopping at 1 try", + function (assert, currentRun) { + assert.equal(currentRun, 1); + }, + 5, + ); + + retry( + "test stopping at 1 try with custom message", + function (assert, currentRun) { + assert.equal(currentRun, 1, "should equal 1"); + }, + ); + + QUnit.test("verify retries", function (assert) { assert.deepEqual(messages.slice(0, 6), [ - '(Tried 5 times)', - 'should equal 5\n(Tried 5 times)', - '(Tried 3 times)', - 'should equal 3\n(Tried 3 times)', + "(Tried 5 times)", + "should equal 5\n(Tried 5 times)", + "(Tried 3 times)", + "should equal 3\n(Tried 3 times)", undefined, - 'should equal 1' - ]) - }) -}) - -retry('test default: retry runs twice - initial attempt plus one retry', function (assert, currentRun) { - assert.expect(1) - assert.equal(currentRun, 2) -}) - -retry('test retry five times', function (assert, currentRun) { - assert.expect(1) - assert.equal(currentRun, 5) -}, 5) - -retry('test retry async', async function (assert, currentRun) { - assert.expect(1) - await timeout(100) - assert.equal(currentRun, 4) -}, 4) - -QUnit.module('error handling', function () { - retry('rejected promise is handled', async function (assert, currentRun) { - if (currentRun === 2) { - await Promise.reject(new Error('should be handled')) - } - assert.equal(currentRun, 5) - }, 5) - - retry.todo('rejected promise on the last try is is not handled', async function (assert, currentRun) { - if (currentRun === 5) { - await Promise.reject(new Error('should not be handled')) - } - assert.equal(currentRun, 5) - }, 5) - - retry('error is handled', async function (assert, currentRun) { - if (currentRun === 2) { - throw new Error('should be handled') - } - assert.equal(currentRun, 5) - }, 5) - - retry.todo('error on the last try is not handled', async function (assert, currentRun) { - if (currentRun === 5) { - throw new Error('should not be handled') - } - assert.equal(currentRun, 5) - }, 5) - - retry('failed assertion is handled', async function (assert, currentRun) { - assert.equal(currentRun, 5) - assert.ok(true) - }, 5) - - retry.todo('failed assertion on the last try is not handled', async function (assert, currentRun) { - assert.ok(false) - assert.ok(true) - }, 5) -}) - -QUnit.module('hook context', function (hooks) { + "should equal 1", + ]); + }); +}); + +retry( + "test default: retry runs twice - initial attempt plus one retry", + function (assert, currentRun) { + assert.expect(1); + assert.equal(currentRun, 2); + }, +); + +retry( + "test retry five times", + function (assert, currentRun) { + assert.expect(1); + assert.equal(currentRun, 5); + }, + 5, +); + +retry( + "test retry async", + async function (assert, currentRun) { + assert.expect(1); + await timeout(100); + assert.equal(currentRun, 4); + }, + 4, +); + +QUnit.module("error handling", function () { + retry( + "rejected promise is handled", + async function (assert, currentRun) { + if (currentRun === 2) { + await Promise.reject(new Error("should be handled")); + } + assert.equal(currentRun, 5); + }, + 5, + ); + + retry.todo( + "rejected promise on the last try is is not handled", + async function (assert, currentRun) { + if (currentRun === 5) { + await Promise.reject(new Error("should not be handled")); + } + assert.equal(currentRun, 5); + }, + 5, + ); + + retry( + "error is handled", + async function (assert, currentRun) { + if (currentRun === 2) { + throw new Error("should be handled"); + } + assert.equal(currentRun, 5); + }, + 5, + ); + + retry.todo( + "error on the last try is not handled", + async function (assert, currentRun) { + if (currentRun === 5) { + throw new Error("should not be handled"); + } + assert.equal(currentRun, 5); + }, + 5, + ); + + retry( + "failed assertion is handled", + async function (assert, currentRun) { + assert.equal(currentRun, 5); + assert.ok(true); + }, + 5, + ); + + retry.todo( + "failed assertion on the last try is not handled", + async function (assert, currentRun) { + assert.ok(false); + assert.ok(true); + }, + 5, + ); +}); + +QUnit.module("hook context", function (hooks) { hooks.beforeEach(function () { - this.sharedValue = 'myContext' - }) - - QUnit.test('qunit test', function (assert) { - assert.equal(this.sharedValue, 'myContext') - }) - - retry('retry matches qunit test behaviour', function (assert, currentRun) { - assert.equal(this.sharedValue, 'myContext') - assert.equal(currentRun, 2) - }) - - retry('environment it reset on each retry', function (assert, currentRun) { - assert.equal(this.localValue, undefined) - this.localValue = 'local' - assert.equal(currentRun, 2) - }) -}) - -QUnit.module('currentRun count', function () { + this.sharedValue = "myContext"; + }); + + QUnit.test("qunit test", function (assert) { + assert.equal(this.sharedValue, "myContext"); + }); + + retry("retry matches qunit test behaviour", function (assert, currentRun) { + assert.equal(this.sharedValue, "myContext"); + assert.equal(currentRun, 2); + }); + + retry("environment it reset on each retry", function (assert, currentRun) { + assert.equal(this.localValue, undefined); + this.localValue = "local"; + assert.equal(currentRun, 2); + }); +}); + +QUnit.module("currentRun count", function () { // tests are order dependent // count retries in retryTest // assert correct count in another test - let execCount = 0 - - retry('count retries', function (assert, currentRun) { - execCount = execCount + 1 - assert.equal(currentRun, 5) - }, 5) - - QUnit.test('execCount for retryTest', function (assert) { - assert.equal(execCount, 5) - }) -}) - -QUnit.module('hooks count', function () { + let execCount = 0; + + retry( + "count retries", + function (assert, currentRun) { + execCount = execCount + 1; + assert.equal(currentRun, 5); + }, + 5, + ); + + QUnit.test("execCount for retryTest", function (assert) { + assert.equal(execCount, 5); + }); +}); + +QUnit.module("hooks count", function () { // tests are order dependent // count retries in retryTest // assert correct count in another test - let execCount = 0 - let beforeCount = 0 - let afterCount = 0 + let execCount = 0; + let beforeCount = 0; + let afterCount = 0; - QUnit.module('count hooks async', function (hooks) { + QUnit.module("count hooks async", function (hooks) { hooks.beforeEach(async function () { - await timeout(100) - beforeCount++ - }) + await timeout(100); + beforeCount++; + }); hooks.afterEach(async function () { - await timeout(100) - afterCount++ - }) - - retry('count retries', function (assert, currentRun) { - execCount++ - assert.equal(beforeCount, currentRun, 'beforeCount should match currentRun') - assert.equal(afterCount, currentRun - 1, 'afterCount one less than currentRun') - assert.equal(currentRun, 5) - }, 5) - }) - - QUnit.test('test hooks count', function (assert) { - assert.equal(execCount, 5) - assert.equal(beforeCount, 5) - assert.equal(afterCount, 5) - }) -}) - -QUnit.module('default max runs', function () { - const calls = [] - const retryThrice = setup(QUnit.test, { maxRuns: 3 }) - - retryThrice('count retries', function (assert, currentRun) { - calls.push(currentRun) - - assert.equal(currentRun, 3) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [1, 2, 3]) - }) -}) - -QUnit.module('beforeRetry hook', function () { - const calls = [] + await timeout(100); + afterCount++; + }); + + retry( + "count retries", + function (assert, currentRun) { + execCount++; + assert.equal( + beforeCount, + currentRun, + "beforeCount should match currentRun", + ); + assert.equal( + afterCount, + currentRun - 1, + "afterCount one less than currentRun", + ); + assert.equal(currentRun, 5); + }, + 5, + ); + }); + + QUnit.test("test hooks count", function (assert) { + assert.equal(execCount, 5); + assert.equal(beforeCount, 5); + assert.equal(afterCount, 5); + }); +}); + +QUnit.module("default max runs", function () { + const calls = []; + const retryThrice = setup(QUnit.test, { maxRuns: 3 }); + + retryThrice("count retries", function (assert, currentRun) { + calls.push(currentRun); + + assert.equal(currentRun, 3); + }); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [1, 2, 3]); + }); +}); + +QUnit.module("beforeRetry hook", function () { + const calls = []; const retryWithHook = setup(QUnit.test, { beforeRetry: function (assert, currentRun) { - calls.push(['hook', currentRun]) + calls.push(["hook", currentRun]); + }, + }); + + retryWithHook( + "count retries", + function (assert, currentRun) { + calls.push(["test", currentRun]); + + assert.equal(currentRun, 2); + }, + 2, + ); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + ["test", 1], + ["hook", 2], + ["test", 2], + ]); + }); +}); + +QUnit.module("assert.expect", function () { + const calls = []; + + retry( + "should pass with retries", + function (assert, currentRun) { + calls.push(["with", currentRun]); + + assert.expect(3); + assert.ok(true); + if (currentRun === 1) { + throw new Error("fail"); + } + assert.ok(true); + if (currentRun === 2) { + throw new Error("fail"); + } + assert.ok(true); + }, + 3, + ); + + retry("should pass without retries", function (assert, currentRun) { + calls.push(["without", currentRun]); + + assert.expect(2); + assert.ok(true); + assert.ok(true); + }); + + retry.todo("should fail with incorrect count", function (assert, currentRun) { + calls.push(["incorrect", currentRun]); + + assert.expect(2); + assert.ok(true); + if (currentRun === 1) { + throw new Error("fail"); } - }) - - retryWithHook('count retries', function (assert, currentRun) { - calls.push(['test', currentRun]) - - assert.equal(currentRun, 2) - }, 2) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [['test', 1], ['hook', 2], ['test', 2]]) - }) -}) - -QUnit.module('assert.expect', function () { - const calls = [] - - retry('should pass with retries', function (assert, currentRun) { - calls.push(['with', currentRun]) - - assert.expect(3) - assert.ok(true) - if (currentRun === 1) { throw new Error('fail') } - assert.ok(true) - if (currentRun === 2) { throw new Error('fail') } - assert.ok(true) - }, 3) - - retry('should pass without retries', function (assert, currentRun) { - calls.push(['without', currentRun]) - - assert.expect(2) - assert.ok(true) - assert.ok(true) - }) - - retry.todo('should fail with incorrect count', function (assert, currentRun) { - calls.push(['incorrect', currentRun]) - - assert.expect(2) - assert.ok(true) - if (currentRun === 1) { throw new Error('fail') } - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [['with', 1], ['with', 2], ['with', 3], ['without', 1], ['incorrect', 1], ['incorrect', 2]]) - }) -}) - -QUnit.module('assert.throws', function () { - const calls = [] - - retry('count retries', function (assert, currentRun) { - calls.push(currentRun) + }); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + ["with", 1], + ["with", 2], + ["with", 3], + ["without", 1], + ["incorrect", 1], + ["incorrect", 2], + ]); + }); +}); + +QUnit.module("assert.throws", function () { + const calls = []; + + retry("count retries", function (assert, currentRun) { + calls.push(currentRun); assert.throws(() => { - if (currentRun === 2) throw new Error('fail') - }) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [1, 2]) - }) -}) - -QUnit.module('retry.todo', function () { - const calls = [] - - retry.todo('count retries', function (assert, currentRun) { - calls.push(currentRun) - - assert.ok(false) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [1, 2]) - }) -}) - -QUnit.module('retry.skip', function () { - const calls = [] - - retry.skip('count retries', function (assert, currentRun) { - calls.push(currentRun) - - assert.equal(currentRun, 2) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, []) - }) -}) - -QUnit.module('retry.if', function () { - const calls = [] - - retry.if('count true retries', true, function (assert, currentRun) { - calls.push([true, currentRun]) - - assert.equal(currentRun, 2) - }) - - retry.if('count false retries', false, function (assert, currentRun) { - calls.push([false, currentRun]) - - assert.equal(currentRun, 2) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [[true, 1], [true, 2]]) - }) -}) - -QUnit.module('retry.each', function () { - const calls = [] - - retry.each('count retries', ['A', 'B', 'C'], function (assert, data, currentRun) { - calls.push([data, currentRun]) - - assert.equal(currentRun, 2) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [['A', 1], ['A', 2], ['B', 1], ['B', 2], ['C', 1], ['C', 2]]) - }) -}) - -QUnit.module('retry.todo.each', function () { - const calls = [] - - retry.todo.each('count retries', ['A', 'B', 'C'], function (assert, data, currentRun) { - calls.push([data, currentRun]) - - assert.ok(false) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [['A', 1], ['A', 2], ['B', 1], ['B', 2], ['C', 1], ['C', 2]]) - }) -}) - -QUnit.module('retry.skip.each', function () { - const calls = [] - - retry.skip.each('count retries', ['A', 'B', 'C'], function (assert, data, currentRun) { - calls.push([data, currentRun]) - - assert.equal(currentRun, 2) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, []) - }) -}) - -QUnit.module('retry.if.each', function () { - const calls = [] - - retry.if.each('count true retries', true, ['A', 'B'], function (assert, data, currentRun) { - calls.push([true, data, currentRun]) - - assert.equal(currentRun, 2) - }) - - retry.if.each('count false retries', false, ['A', 'B'], function (assert, data, currentRun) { - calls.push([false, data, currentRun]) - - assert.equal(currentRun, 2) - }) - - QUnit.test('verify calls', function (assert) { - assert.deepEqual(calls, [[true, 'A', 1], [true, 'A', 2], [true, 'B', 1], [true, 'B', 2]]) - }) -}) + if (currentRun === 2) throw new Error("fail"); + }); + }); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [1, 2]); + }); +}); + +QUnit.module("retry.todo", function () { + const calls = []; + + retry.todo("count retries", function (assert, currentRun) { + calls.push(currentRun); + + assert.ok(false); + }); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [1, 2]); + }); +}); + +QUnit.module("retry.skip", function () { + const calls = []; + + retry.skip("count retries", function (assert, currentRun) { + calls.push(currentRun); + + assert.equal(currentRun, 2); + }); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, []); + }); +}); + +QUnit.module("retry.if", function () { + const calls = []; + + retry.if("count true retries", true, function (assert, currentRun) { + calls.push([true, currentRun]); + + assert.equal(currentRun, 2); + }); + + retry.if("count false retries", false, function (assert, currentRun) { + calls.push([false, currentRun]); + + assert.equal(currentRun, 2); + }); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + [true, 1], + [true, 2], + ]); + }); +}); + +QUnit.module("retry.each", function () { + const calls = []; + + retry.each( + "count retries", + ["A", "B", "C"], + function (assert, data, currentRun) { + calls.push([data, currentRun]); + + assert.equal(currentRun, 2); + }, + ); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + ["A", 1], + ["A", 2], + ["B", 1], + ["B", 2], + ["C", 1], + ["C", 2], + ]); + }); +}); + +QUnit.module("retry.todo.each", function () { + const calls = []; + + retry.todo.each( + "count retries", + ["A", "B", "C"], + function (assert, data, currentRun) { + calls.push([data, currentRun]); + + assert.ok(false); + }, + ); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + ["A", 1], + ["A", 2], + ["B", 1], + ["B", 2], + ["C", 1], + ["C", 2], + ]); + }); +}); + +QUnit.module("retry.skip.each", function () { + const calls = []; + + retry.skip.each( + "count retries", + ["A", "B", "C"], + function (assert, data, currentRun) { + calls.push([data, currentRun]); + + assert.equal(currentRun, 2); + }, + ); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, []); + }); +}); + +QUnit.module("retry.if.each", function () { + const calls = []; + + retry.if.each( + "count true retries", + true, + ["A", "B"], + function (assert, data, currentRun) { + calls.push([true, data, currentRun]); + + assert.equal(currentRun, 2); + }, + ); + + retry.if.each( + "count false retries", + false, + ["A", "B"], + function (assert, data, currentRun) { + calls.push([false, data, currentRun]); + + assert.equal(currentRun, 2); + }, + ); + + QUnit.test("verify calls", function (assert) { + assert.deepEqual(calls, [ + [true, "A", 1], + [true, "A", 2], + [true, "B", 1], + [true, "B", 2], + ]); + }); +});