Skip to content

Convience library to apply different timeout strategies to retried tests

License

Notifications You must be signed in to change notification settings

joostvanwollingen/cypress-backoff

Repository files navigation

cypress-backoff

npm

Convience library to apply different timeout strategies to retried tests. Inspired by Filip Hric.

This repository is not maintained by the Cypress developers.

Installation & usage

  1. Install the module.

    npm install cypress-backoff
  2. Add the retries to cypress.config.js.

    ...
    module.exports = defineConfig({
        retries: 5,
    ...
  3. Import the module

    const backoff = require('cypress-backoff')
  4. Add your preferred timeout and strategy in the beforeEach block of your test

    beforeEach(() => {
        backoff.linear(1000)
    }

Available strategies

linear

Provide the desired timeout increase in milliseconds.

The timeout will increase with this number for every next attempt, i.e. 1000, 2000, 3000...

backoff.linear(1000)

exponential

Provide the desired timeout in milliseconds and exponential rate as an integer.

The timeout will be calculated as $T = timeout * exponentialrate^r$

backoff.exponential(1000, 2)

fixed

Provide an array with the desired timeout for each subsequent retry. If you allow more retries than elements specified the last element will be used.

backoff.fixed([1000, 2000, 3000])

fibonacci

Provide the desired timeout which will be multiplied by the fibonacci number of the retry.

backoff.fibonacci(1000)

custom

Provide a custom function that accepts the retry count as a parameter and returns the desired timeout.

backoff.custom((retryCount) => {return retryCount*2000})

JSDoc function documentation

The documentation of each of the functions can be found here.

About

Convience library to apply different timeout strategies to retried tests

Topics

Resources

License

Stars

Watchers

Forks