{"library":"qunit-retry","title":"QUnit Retry","description":"qunit-retry is a utility package for QUnit that provides a drop-in replacement for the standard `QUnit.test` function, enabling automatic retries for failing tests. This is particularly useful for handling intermittent failures in test environments, such as those caused by unreliable third-party services or network flakiness, rather than masking legitimate bugs. The current stable version is `3.0.1`. The library is actively maintained, with recent major and patch releases indicating ongoing development. Key features include the ability to configure the maximum number of retries globally or per test, support for `QUnit.test`'s full API (including `test.each` and `test.only`), and a `beforeRetry` hook to reset the testing environment between retry attempts. It distinguishes itself by seamlessly integrating into existing QUnit setups with minimal code changes, making it an efficient solution for improving test suite stability against non-deterministic external factors.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install qunit-retry"],"cli":null},"imports":["import setup from 'qunit-retry';","import setup from 'https://unpkg.com/qunit-retry/main.js';","import type { SetupOptions } from 'qunit-retry';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import setup from \"qunit-retry\";\nimport QUnit from \"qunit\"; // QUnit is expected to be installed and configured\n\n// Simulate an occasionally failing asynchronous service\nlet internalAttemptCount = 0;\nasync function occasionallyFailingServiceTestResult() {\n  internalAttemptCount++;\n  // Simulate failure on the first attempt only\n  if (internalAttemptCount <= 1) {\n    console.log(`Service attempt ${internalAttemptCount}: Simulating failure.`);\n    throw new Error(\"Simulated transient service error.\");\n  }\n  console.log(`Service attempt ${internalAttemptCount}: Succeeding.`);\n  return 42;\n}\n\n// Configure qunit-retry with QUnit's test function\n// The 'retry' function replaces QUnit.test, adding retry logic\nconst retry = setup(QUnit.test, {\n  // Global maxRuns: allow 1 initial attempt + 2 retries\n  maxRuns: 3,\n  beforeRetry: (details) => {\n    // Reset any state needed for the test to run clean again\n    console.log(`Retrying test \"${details.name}\" (attempt ${details.runNumber}/${details.maxRuns})...`);\n    internalAttemptCount = 0; // Reset our mock service's internal state\n  }\n});\n\n// Define a test that uses the 'retry' function\nretry(\"a test relying on 3rd party service that occasionally fails\", async function(assert) {\n  assert.expect(1); // Indicate one assertion is expected\n  const result = await occasionallyFailingServiceTestResult();\n  assert.equal(result, 42, \"The service should eventually return 42 after retries.\");\n});\n\n// Example of a test that should pass without retries\nretry(\"a stable test\", async function(assert) {\n  assert.expect(1);\n  const result = 42; // Directly successful\n  assert.equal(result, 42, \"This stable test should pass immediately.\");\n});","lang":"typescript","description":"This quickstart demonstrates how to set up `qunit-retry` with QUnit, including global `maxRuns` configuration and a `beforeRetry` hook for resetting test state between retries. It uses a mock service to show a test failing initially but succeeding on retry.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}