From edb37eab1f39d334a57aea7d743f59515ed663e6 Mon Sep 17 00:00:00 2001 From: mrloop Date: Tue, 28 Jan 2025 13:31:31 +0000 Subject: [PATCH] chore: update files linted --- package.json | 2 +- test/retry-only.js | 82 +++--- test/retry.js | 672 ++++++++++++++++++++++----------------------- 3 files changed, 378 insertions(+), 378 deletions(-) diff --git a/package.json b/package.json index 47e2145..1fa3473 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "test:smoke": "testem ci", "test:js": "qunit test/retry.js && qunit test/retry-only.js", "dev": "qunit --watch", - "lint": "eslint main.js" + "lint": "eslint main.js src test/*.js" }, "devDependencies": { "@release-it-plugins/lerna-changelog": "^7.0.0", diff --git a/test/retry-only.js b/test/retry-only.js index 0f363d1..412448e 100644 --- a/test/retry-only.js +++ b/test/retry-only.js @@ -1,60 +1,60 @@ -import setup from "qunit-retry"; -import QUnit from "qunit"; +import setup from 'qunit-retry' +import QUnit from 'qunit' -const retry = setup(QUnit.test); +const retry = setup(QUnit.test) -QUnit.module("retry.only", function () { - const calls = []; +QUnit.module('retry.only', function () { + const calls = [] - retry.only("count only retries", function (assert, currentRun) { - calls.push(["only", currentRun]); + retry.only('count only retries', function (assert, currentRun) { + calls.push(['only', currentRun]) - assert.equal(currentRun, 2); - }); + assert.equal(currentRun, 2) + }) - retry("count non-only retries", function (assert, currentRun) { - calls.push(["non-only", currentRun]); + retry('count non-only retries', function (assert, currentRun) { + calls.push(['non-only', currentRun]) - assert.equal(currentRun, 2); - }); + assert.equal(currentRun, 2) + }) - QUnit.test("verify calls", function (assert) { + QUnit.test('verify calls', function (assert) { assert.deepEqual(calls, [ - ["only", 1], - ["only", 2], - ]); - }); -}); + ['only', 1], + ['only', 2] + ]) + }) +}) -QUnit.module("retry.only.each", function () { - const calls = []; +QUnit.module('retry.only.each', function () { + const calls = [] retry.only.each( - "count only retries", - ["A", "B"], + 'count only retries', + ['A', 'B'], function (assert, data, currentRun) { - calls.push(["only", data, currentRun]); + calls.push(['only', data, currentRun]) - assert.equal(currentRun, 2); - }, - ); + assert.equal(currentRun, 2) + } + ) retry.each( - "count non-only retries", - ["A", "B"], + 'count non-only retries', + ['A', 'B'], function (assert, data, currentRun) { - calls.push(["non-only", data, currentRun]); + calls.push(['non-only', data, currentRun]) - assert.equal(currentRun, 2); - }, - ); + assert.equal(currentRun, 2) + } + ) - QUnit.test("verify calls", function (assert) { + QUnit.test('verify calls', function (assert) { assert.deepEqual(calls, [ - ["only", "A", 1], - ["only", "A", 2], - ["only", "B", 1], - ["only", "B", 2], - ]); - }); -}); + ['only', 'A', 1], + ['only', 'A', 2], + ['only', 'B', 1], + ['only', 'B', 2] + ]) + }) +}) diff --git a/test/retry.js b/test/retry.js index eaba85b..39dd001 100644 --- a/test/retry.js +++ b/test/retry.js @@ -1,516 +1,516 @@ -import setup from "qunit-retry"; -import QUnit from "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", + 'test retry five times', function (assert, currentRun) { - assert.equal(currentRun, 5); + assert.equal(currentRun, 5) }, - 5, - ); + 5 + ) retry( - "test retry five times with custom message", + 'test retry five times with custom message', function (assert, currentRun) { - assert.equal(currentRun, 5, "should equal 5"); + assert.equal(currentRun, 5, 'should equal 5') }, - 5, - ); + 5 + ) retry( - "test stopping at 3 retries", + 'test stopping at 3 retries', function (assert, currentRun) { - assert.equal(currentRun, 3); + assert.equal(currentRun, 3) }, - 5, - ); + 5 + ) retry( - "test stopping at 3 retries with custom message", + 'test stopping at 3 retries with custom message', function (assert, currentRun) { - assert.equal(currentRun, 3, "should equal 3"); + assert.equal(currentRun, 3, 'should equal 3') }, - 5, - ); + 5 + ) retry( - "test stopping at 1 try", + 'test stopping at 1 try', function (assert, currentRun) { - assert.equal(currentRun, 1); + assert.equal(currentRun, 1) }, - 5, - ); + 5 + ) retry( - "test stopping at 1 try with custom message", + 'test stopping at 1 try with custom message', function (assert, currentRun) { - assert.equal(currentRun, 1, "should equal 1"); - }, - ); + assert.equal(currentRun, 1, 'should equal 1') + } + ) - QUnit.test("verify retries", function (assert) { + 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", - ]); - }); -}); + 'should equal 1' + ]) + }) +}) retry( - "test default: retry runs twice - initial attempt plus one retry", + 'test default: retry runs twice - initial attempt plus one retry', function (assert, currentRun) { - assert.expect(1); - assert.equal(currentRun, 2); - }, -); + assert.expect(1) + assert.equal(currentRun, 2) + } +) retry( - "test retry five times", + 'test retry five times', function (assert, currentRun) { - assert.expect(1); - assert.equal(currentRun, 5); + assert.expect(1) + assert.equal(currentRun, 5) }, - 5, -); + 5 +) retry( - "test retry async", + 'test retry async', async function (assert, currentRun) { - assert.expect(1); - await timeout(100); - assert.equal(currentRun, 4); + assert.expect(1) + await timeout(100) + assert.equal(currentRun, 4) }, - 4, -); + 4 +) -QUnit.module("error handling", function () { +QUnit.module('error handling', function () { retry( - "rejected promise is handled", + 'rejected promise is handled', async function (assert, currentRun) { if (currentRun === 2) { - await Promise.reject(new Error("should be handled")); + await Promise.reject(new Error('should be handled')) } - assert.equal(currentRun, 5); + assert.equal(currentRun, 5) }, - 5, - ); + 5 + ) retry.todo( - "rejected promise on the last try is is not handled", + '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")); + await Promise.reject(new Error('should not be handled')) } - assert.equal(currentRun, 5); + assert.equal(currentRun, 5) }, - 5, - ); + 5 + ) retry( - "error is handled", + 'error is handled', async function (assert, currentRun) { if (currentRun === 2) { - throw new Error("should be handled"); + throw new Error('should be handled') } - assert.equal(currentRun, 5); + assert.equal(currentRun, 5) }, - 5, - ); + 5 + ) retry.todo( - "error on the last try is not handled", + 'error on the last try is not handled', async function (assert, currentRun) { if (currentRun === 5) { - throw new Error("should not be handled"); + throw new Error('should not be handled') } - assert.equal(currentRun, 5); + assert.equal(currentRun, 5) }, - 5, - ); + 5 + ) retry( - "failed assertion is handled", + 'failed assertion is handled', async function (assert, currentRun) { - assert.equal(currentRun, 5); - assert.ok(true); + assert.equal(currentRun, 5) + assert.ok(true) }, - 5, - ); + 5 + ) retry.todo( - "failed assertion on the last try is not handled", + 'failed assertion on the last try is not handled', async function (assert, currentRun) { - assert.ok(false); - assert.ok(true); + assert.ok(false) + assert.ok(true) }, - 5, - ); -}); + 5 + ) +}) -QUnit.module("hook context", function (hooks) { +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; + let execCount = 0 retry( - "count retries", + 'count retries', function (assert, currentRun) { - execCount = execCount + 1; - assert.equal(currentRun, 5); + execCount = execCount + 1 + assert.equal(currentRun, 5) }, - 5, - ); + 5 + ) - QUnit.test("execCount for retryTest", function (assert) { - assert.equal(execCount, 5); - }); -}); + QUnit.test('execCount for retryTest', function (assert) { + assert.equal(execCount, 5) + }) +}) -QUnit.module("hooks count", function () { +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++; - }); + await timeout(100) + afterCount++ + }) retry( - "count retries", + 'count retries', function (assert, currentRun) { - execCount++; + execCount++ assert.equal( beforeCount, currentRun, - "beforeCount should match currentRun", - ); + 'beforeCount should match currentRun' + ) assert.equal( afterCount, currentRun - 1, - "afterCount one less than currentRun", - ); - assert.equal(currentRun, 5); + '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 = []; + 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", + 'count retries', function (assert, currentRun) { - calls.push(["test", currentRun]); + calls.push(['test', currentRun]) - assert.equal(currentRun, 2); + assert.equal(currentRun, 2) }, - 2, - ); + 2 + ) - QUnit.test("verify calls", function (assert) { + QUnit.test('verify calls', function (assert) { assert.deepEqual(calls, [ - ["test", 1], - ["hook", 2], - ["test", 2], - ]); - }); -}); + ['test', 1], + ['hook', 2], + ['test', 2] + ]) + }) +}) -QUnit.module("assert.expect", function () { - const calls = []; +QUnit.module('assert.expect', function () { + const calls = [] retry( - "should pass with retries", + 'should pass with retries', function (assert, currentRun) { - calls.push(["with", currentRun]); + calls.push(['with', currentRun]) - assert.expect(3); - assert.ok(true); + assert.expect(3) + assert.ok(true) if (currentRun === 1) { - throw new Error("fail"); + throw new Error('fail') } - assert.ok(true); + assert.ok(true) if (currentRun === 2) { - throw new Error("fail"); + throw new Error('fail') } - assert.ok(true); + assert.ok(true) }, - 3, - ); + 3 + ) - retry("should pass without retries", function (assert, currentRun) { - calls.push(["without", currentRun]); + retry('should pass without retries', function (assert, currentRun) { + calls.push(['without', currentRun]) - assert.expect(2); - assert.ok(true); - assert.ok(true); - }); + assert.expect(2) + assert.ok(true) + assert.ok(true) + }) - retry.todo("should fail with incorrect count", function (assert, currentRun) { - calls.push(["incorrect", currentRun]); + retry.todo('should fail with incorrect count', function (assert, currentRun) { + calls.push(['incorrect', currentRun]) - assert.expect(2); - assert.ok(true); + assert.expect(2) + assert.ok(true) if (currentRun === 1) { - throw new Error("fail"); + throw new Error('fail') } - }); + }) - QUnit.test("verify calls", function (assert) { + 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); + ['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"); - }); - }); + if (currentRun === 2) throw new Error('fail') + }) + }) - QUnit.test("verify calls", function (assert) { - assert.deepEqual(calls, [1, 2]); - }); -}); + QUnit.test('verify calls', function (assert) { + assert.deepEqual(calls, [1, 2]) + }) +}) -QUnit.module("retry.todo", function () { - const calls = []; +QUnit.module('retry.todo', function () { + const calls = [] - retry.todo("count retries", function (assert, currentRun) { - calls.push(currentRun); + retry.todo('count retries', function (assert, currentRun) { + calls.push(currentRun) - assert.ok(false); - }); + assert.ok(false) + }) - QUnit.test("verify calls", function (assert) { - assert.deepEqual(calls, [1, 2]); - }); -}); + QUnit.test('verify calls', function (assert) { + assert.deepEqual(calls, [1, 2]) + }) +}) -QUnit.module("retry.skip", function () { - const calls = []; +QUnit.module('retry.skip', function () { + const calls = [] - retry.skip("count retries", function (assert, currentRun) { - calls.push(currentRun); + retry.skip('count retries', function (assert, currentRun) { + calls.push(currentRun) - assert.equal(currentRun, 2); - }); + assert.equal(currentRun, 2) + }) - QUnit.test("verify calls", function (assert) { - assert.deepEqual(calls, []); - }); -}); + QUnit.test('verify calls', function (assert) { + assert.deepEqual(calls, []) + }) +}) -QUnit.module("retry.if", function () { - const calls = []; +QUnit.module('retry.if', function () { + const calls = [] - retry.if("count true retries", true, function (assert, currentRun) { - calls.push([true, currentRun]); + retry.if('count true retries', true, function (assert, currentRun) { + calls.push([true, currentRun]) - assert.equal(currentRun, 2); - }); + assert.equal(currentRun, 2) + }) - retry.if("count false retries", false, function (assert, currentRun) { - calls.push([false, currentRun]); + retry.if('count false retries', false, function (assert, currentRun) { + calls.push([false, currentRun]) - assert.equal(currentRun, 2); - }); + assert.equal(currentRun, 2) + }) - QUnit.test("verify calls", function (assert) { + QUnit.test('verify calls', function (assert) { assert.deepEqual(calls, [ [true, 1], - [true, 2], - ]); - }); -}); + [true, 2] + ]) + }) +}) -QUnit.module("retry.each", function () { - const calls = []; +QUnit.module('retry.each', function () { + const calls = [] retry.each( - "count retries", - ["A", "B", "C"], + 'count retries', + ['A', 'B', 'C'], function (assert, data, currentRun) { - calls.push([data, currentRun]); + calls.push([data, currentRun]) - assert.equal(currentRun, 2); - }, - ); + assert.equal(currentRun, 2) + } + ) - QUnit.test("verify calls", function (assert) { + 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 = []; + ['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"], + 'count retries', + ['A', 'B', 'C'], function (assert, data, currentRun) { - calls.push([data, currentRun]); + calls.push([data, currentRun]) - assert.ok(false); - }, - ); + assert.ok(false) + } + ) - QUnit.test("verify calls", function (assert) { + 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 = []; + ['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"], + 'count retries', + ['A', 'B', 'C'], function (assert, data, currentRun) { - calls.push([data, currentRun]); + calls.push([data, currentRun]) - assert.equal(currentRun, 2); - }, - ); + assert.equal(currentRun, 2) + } + ) - QUnit.test("verify calls", function (assert) { - assert.deepEqual(calls, []); - }); -}); + QUnit.test('verify calls', function (assert) { + assert.deepEqual(calls, []) + }) +}) -QUnit.module("retry.if.each", function () { - const calls = []; +QUnit.module('retry.if.each', function () { + const calls = [] retry.if.each( - "count true retries", + 'count true retries', true, - ["A", "B"], + ['A', 'B'], function (assert, data, currentRun) { - calls.push([true, data, currentRun]); + calls.push([true, data, currentRun]) - assert.equal(currentRun, 2); - }, - ); + assert.equal(currentRun, 2) + } + ) retry.if.each( - "count false retries", + 'count false retries', false, - ["A", "B"], + ['A', 'B'], function (assert, data, currentRun) { - calls.push([false, data, currentRun]); + calls.push([false, data, currentRun]) - assert.equal(currentRun, 2); - }, - ); + assert.equal(currentRun, 2) + } + ) - QUnit.test("verify calls", function (assert) { + QUnit.test('verify calls', function (assert) { assert.deepEqual(calls, [ - [true, "A", 1], - [true, "A", 2], - [true, "B", 1], - [true, "B", 2], - ]); - }); -}); + [true, 'A', 1], + [true, 'A', 2], + [true, 'B', 1], + [true, 'B', 2] + ]) + }) +})