Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-retry

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-retry - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

2

index.js

@@ -30,3 +30,3 @@ 'use strict';

if (operation.retry(err)) {
if (operation.retry(err || new Error())) {
return;

@@ -33,0 +33,0 @@ }

{
"name": "promise-retry",
"version": "0.2.5",
"version": "0.2.6",
"description": "Retries a function that returns a promise, leveraging the power of the retry module.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,10 +8,11 @@ 'use strict';

describe('promise-retry', function () {
it('should retry if retry was called', function (done) {
it('should call fn again if retry was called', function (done) {
var count = 0;
promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
.then(function () {
if (count < 2) {
count += 1;
if (count <= 2) {
retry(new Error('foo'));

@@ -25,3 +26,5 @@ }

expect(value).to.be('final');
expect(count).to.be(2);
expect(count).to.be(3);
}, function () {
throw new Error('should not fail');
})

@@ -31,6 +34,8 @@ .done(done, done);

it('should not retry if retry was not called', function (done) {
it('should not retry on fulfillment if retry was not called', function (done) {
var count = 0;
promiseRetry(function () {
count += 1;
return Promise.delay(10)

@@ -41,3 +46,5 @@ .thenReturn('final');

expect(value).to.be('final');
expect(count).to.be(0);
expect(count).to.be(1);
}, function () {
throw new Error('should not fail');
})

@@ -47,7 +54,11 @@ .done(done, done);

it('should reject the promise if the retries were exceeded', function (done) {
it('should not retry on rejection if retry was not called', function (done) {
var count = 0;
promiseRetry(function () {
count += 1;
return Promise.delay(10)
.thenThrow(new Error('foo'));
}, { retries: 1, factor: 1 })
})
.then(function () {

@@ -57,2 +68,3 @@ throw new Error('should not succeed');

expect(err.message).to.be('foo');
expect(count).to.be(1);
})

@@ -62,2 +74,21 @@ .done(done, done);

it('should reject the promise if the retries were exceeded', function (done) {
var count = 0;
promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
.thenThrow(new Error('foo'))
.catch(retry);
}, { retries: 2, factor: 1 })
.then(function () {
throw new Error('should not succeed');
}, function (err) {
expect(err.message).to.be('foo');
expect(count).to.be(3);
})
.done(done, done);
});
it('should pass options to the underlying retry module', function (done) {

@@ -85,11 +116,4 @@ var count = 0;

it('should convert values into promises', function (done) {
var count = 0;
promiseRetry(function (retry) {
if (count < 2) {
count += 1;
retry(new Error('foo'));
}
it('should convert direct fulfillments into promises', function (done) {
promiseRetry(function () {
return 'final';

@@ -99,3 +123,4 @@ }, { factor: 1 })

expect(value).to.be('final');
expect(count).to.be(2);
}, function () {
throw new Error('should not fail');
})

@@ -105,3 +130,3 @@ .done(done, done);

it('should convert errors into promises', function (done) {
it('should convert direct rejections into promises', function (done) {
promiseRetry(function () {

@@ -118,3 +143,3 @@ throw new Error('foo');

it('should not fail on undefined rejections', function (done) {
it('should not crash on undefined rejections', function (done) {
promiseRetry(function () {

@@ -141,4 +166,32 @@ throw undefined;

it('should retry if retry() was called with undefined', function (done) {
var count = 0;
promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
.then(function () {
if (count <= 2) {
retry();
}
return 'final';
});
}, { factor: 1 })
.then(function (value) {
expect(value).to.be('final');
expect(count).to.be(3);
}, function () {
throw new Error('should not fail');
})
.done(done, done);
});
it('should work with several retries in the same chain', function (done) {
var count = 0;
promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)

@@ -156,2 +209,3 @@ .then(function () {

expect(err.message).to.be('foo');
expect(count).to.be(2);
})

@@ -158,0 +212,0 @@ .done(done, done);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc