https://github.com/mrloop/qunit-retry
Drop in replacement for qunit `test` which retries a failed test.
https://github.com/mrloop/qunit-retry
qunit retries testing
Last synced: about 1 month ago
JSON representation
Drop in replacement for qunit `test` which retries a failed test.
- Host: GitHub
- URL: https://github.com/mrloop/qunit-retry
- Owner: mrloop
- License: isc
- Created: 2019-02-09T12:50:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-28T13:32:56.000Z (8 months ago)
- Last Synced: 2025-08-20T21:55:42.153Z (about 2 months ago)
- Topics: qunit, retries, testing
- Language: JavaScript
- Homepage:
- Size: 411 KB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
qunit-retry
==============================================================================[![Latest NPM release][npm-badge]][npm-badge-url]
[npm-badge]: https://img.shields.io/npm/v/qunit-retry.svg
[npm-badge-url]: https://www.npmjs.com/package/qunit-retryDrop in replacement for [QUnit](https://qunitjs.com/) [test](https://api.qunitjs.com/QUnit/test) to `retry` test upon failure.
```js
import setup from "qunit-retry";
import QUnit from "qunit";const retry = setup(QUnit.test);
// retry this test on failure as third party service occasionally fails
// we need to test against third party service
// we can live with occasional third party service failure
retry("a test relying on 3rd party service that occasionally fails", async function(assert) {
var result = await occasionallyFailingServiceTestResult();
assert.equal(result, 42);
});
```It provides the same API as `QUnit.test`, including `test.each`, `test.only` etc. The only difference is that the test will be retried upon failure.
Use very sparingly, for a suite of 2024 tests, using this for a single acceptance test.
Blog post about `qunit-retry` available [here](https://blog.mrloop.com/javascript/2019/02/26/qunit-retry.html).
### Set Max Runs
The default maximum number of retries is 2 (one attempt and one retry). To change it globally, pass the `maxRuns` option to the `setup` function:
```js
import setup from "qunit-retry";
import QUnit from "qunit";const retry = setup(QUnit.test, { maxRuns: 3 });
```To change it for a single test, pass the number of retries as the third argument:
```js
// retry this test **two times** (in addition to one initial attempt)
// on failure as third party service occasionally fails
// we need to test against third party service
// we can live with occasional third party service failure
retry("a test relying on 3rd party service that occasionally fails", async function(assert) {
var result = await occasionallyFailingServiceTestResult();
assert.equal(result, 42);
}, 3);
```**Note:** It is generally advised to use the retry sparingly and this advice extends to setting a large number of retries.
### Resetting environment between retries
If you need to reset the environment between retries, you can pass a `beforeRetry` function to the `setup` function:
```js
import setup from "qunit-retry";
import QUnit from "qunit";const retry = setup(QUnit.test, { beforeRetry: () => resetEnvironment() });
```Install
------------------------------------------------------------------------------### npm
```bash
npm install --save-dev qunit-retry
```or using [`yarn`](https://yarnpkg.com/):
```bash
yarn add --dev qunit-retry
```or using [`pnpm`](https://pnpm.js.org/):
```bash
pnpm add --save-dev qunit-retry
```### Node
```js
import setup from "qunit-retry";
import QUnit from "qunit";const retry = setup(QUnit.test);
```### Directly in browser
```html
import setup from 'https://unpkg.com/qunit-retry/main.js'
const retry = setup(QUnit.test)
retry("a test relying on 3rd party service that occasionally fails", async function(assert) {
var result = await occasionallyFailingServiceTestResult();
assert.equal(result, 42);
});```
Contributing
------------------------------------------------------------------------------### How to Run Tests
```bash
pnpm test
```### How to Run Linting
```bash
pnpm lint
```License
------------------------------------------------------------------------------qunit-retry is developed by and ©
[mrloop](http://mrloop.com) and contributors. It is released under the
[ISC License](https://github.com/mrloop/qunit-retry/blob/master/LICENSE.md).