Skip to content

Commit

Permalink
Docs: Document "Storage interface" at QUnit.config.storage
Browse files Browse the repository at this point in the history
Storing failures and looking them up during rerun, requires only get,
set, and remove.

But, to clean up unknown past-failures after a success, we also use
`key()` and `length` to find any key that matches our naming scheme.
  • Loading branch information
Krinkle committed Jul 22, 2024
1 parent deccc52 commit c73e8e5
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion docs/api/config/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,47 @@ The Storage object to use for remembering failed tests between runs.

This is used to power the [reorder feature](./reorder.md). In [browser environments](../../browser.md) this will use `sessionStorage` if supported by the browser.

In Node.js and other non-browser environments, there is no storage object available for this purpose by default. You can attach your own preferred form of persistence between test runs, by assigning an object to `QUnit.config.storage` that implements `getItem`, `setItem` and `removeItem` methods, similar to the [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
In Node.js and other non-browser environments, there is no storage object available for this purpose by default. You can attach your own preferred form of persistence between test runs, by assigning an object to `QUnit.config.storage` that implements at least the below subset of the [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).

## Storage interface

```js
storage = {
/**
* @param {string} key
* @param {string} value
*/
setItem (key, value) {
},

/**
* @param {string} key
* @return {string|null}
*/
getItem (key) {
},

/**
* @param {string} key
*/
removeItem (key) {
},

/**
* Get name of key at given offset, e.g. by iterating from 0 to `length`.
*
* @param {number} index
* @return {string|null}
*/
key (index) {
},

/**
* How many keys exist.
*
* @type {number}
*/
get length () {
}
};
```

0 comments on commit c73e8e5

Please sign in to comment.