promise-retry
Advanced tools
Comparing version 0.2.9 to 1.0.0
@@ -5,3 +5,3 @@ 'use strict'; | ||
var retry = require('retry'); | ||
var Promise = require('bluebird'); | ||
var promiseTry = require('promise-try'); | ||
@@ -31,3 +31,3 @@ var hasOwn = Object.prototype.hasOwnProperty; | ||
promise = Promise.try(function () { | ||
promise = promiseTry(function () { | ||
return fn(function (err) { | ||
@@ -44,3 +44,3 @@ if (isRetryError(err)) { | ||
promise.done(resolve, function (err) { | ||
promise.then(resolve, function (err) { | ||
if (isRetryError(err)) { | ||
@@ -47,0 +47,0 @@ err = err.retried; |
{ | ||
"name": "promise-retry", | ||
"version": "0.2.9", | ||
"version": "1.0.0", | ||
"description": "Retries a function that returns a promise, leveraging the power of the retry module.", | ||
@@ -20,3 +20,2 @@ "main": "index.js", | ||
"backoff", | ||
"bluebird", | ||
"repeat", | ||
@@ -29,9 +28,10 @@ "replay" | ||
"expect.js": "^0.3.1", | ||
"mocha": "^2.1.0" | ||
"mocha": "^2.3.4", | ||
"sleep-promise": "^1.0.0" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^2.6.2", | ||
"err-code": "^0.1.2", | ||
"retry": "^0.6.1" | ||
"err-code": "^1.0.0", | ||
"promise-try": "^1.0.1", | ||
"retry": "^0.8.0" | ||
} | ||
} |
@@ -1,3 +0,15 @@ | ||
# node-promise-retry [![Build Status](https://travis-ci.org/IndigoUnited/node-promise-retry.svg?branch=master)](https://travis-ci.org/IndigoUnited/node-promise-retry) | ||
# node-promise-retry | ||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] | ||
[npm-url]:https://npmjs.org/package/promise-retry | ||
[downloads-image]:http://img.shields.io/npm/dm/promise-retry.svg | ||
[npm-image]:http://img.shields.io/npm/v/promise-retry.svg | ||
[travis-url]:https://travis-ci.org/IndigoUnited/node-promise-retry | ||
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-promise-retry.svg | ||
[david-dm-url]:https://david-dm.org/IndigoUnited/node-promise-retry | ||
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-promise-retry.svg | ||
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-promise-retry#info=devDependencies | ||
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-promise-retry.svg | ||
Retries a function that returns a promise, leveraging the power of the [retry](https://github.com/tim-kos/node-retry) module to the promises world. | ||
@@ -4,0 +16,0 @@ |
126
test/test.js
'use strict'; | ||
var expect = require('expect.js'); | ||
var Promise = require('bluebird'); | ||
var promiseRetry = require('../'); | ||
var promiseDelay = require('sleep-promise'); | ||
describe('promise-retry', function () { | ||
it('should call fn again if retry was called', function (done) { | ||
it('should call fn again if retry was called', function () { | ||
var count = 0; | ||
promiseRetry(function (retry) { | ||
return promiseRetry(function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
return promiseDelay(10) | ||
.then(function () { | ||
@@ -28,14 +28,13 @@ if (count <= 2) { | ||
throw new Error('should not fail'); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should call fn with the attempt number', function (done) { | ||
it('should call fn with the attempt number', function () { | ||
var count = 0; | ||
promiseRetry(function (retry, number) { | ||
return promiseRetry(function (retry, number) { | ||
count += 1; | ||
expect(count).to.equal(number); | ||
return Promise.delay(10) | ||
return promiseDelay(10) | ||
.then(function () { | ||
@@ -54,14 +53,15 @@ if (count <= 2) { | ||
throw new Error('should not fail'); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should not retry on fulfillment if retry was not called', function (done) { | ||
it('should not retry on fulfillment if retry was not called', function () { | ||
var count = 0; | ||
promiseRetry(function () { | ||
return promiseRetry(function () { | ||
count += 1; | ||
return Promise.delay(10) | ||
.thenReturn('final'); | ||
return promiseDelay(10) | ||
.then(function () { | ||
return 'final'; | ||
}); | ||
}) | ||
@@ -73,14 +73,15 @@ .then(function (value) { | ||
throw new Error('should not fail'); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should not retry on rejection if retry was not called', function (done) { | ||
it('should not retry on rejection if retry was not called', function () { | ||
var count = 0; | ||
promiseRetry(function () { | ||
return promiseRetry(function () { | ||
count += 1; | ||
return Promise.delay(10) | ||
.thenThrow(new Error('foo')); | ||
return promiseDelay(10) | ||
.then(function () { | ||
throw new Error('foo'); | ||
}); | ||
}) | ||
@@ -92,14 +93,15 @@ .then(function () { | ||
expect(count).to.be(1); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should not retry on rejection if nr of retries is 0', function (done) { | ||
it('should not retry on rejection if nr of retries is 0', function () { | ||
var count = 0; | ||
promiseRetry(function (retry) { | ||
return promiseRetry(function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
.thenThrow(new Error('foo')) | ||
return promiseDelay(10) | ||
.then(function () { | ||
throw new Error('foo'); | ||
}) | ||
.catch(retry); | ||
@@ -112,14 +114,15 @@ }, { retries : 0 }) | ||
expect(count).to.be(1); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should reject the promise if the retries were exceeded', function (done) { | ||
it('should reject the promise if the retries were exceeded', function () { | ||
var count = 0; | ||
promiseRetry(function (retry) { | ||
return promiseRetry(function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
.thenThrow(new Error('foo')) | ||
return promiseDelay(10) | ||
.then(function () { | ||
throw new Error('foo'); | ||
}) | ||
.catch(retry); | ||
@@ -132,11 +135,10 @@ }, { retries: 2, factor: 1 }) | ||
expect(count).to.be(3); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should pass options to the underlying retry module', function (done) { | ||
it('should pass options to the underlying retry module', function () { | ||
var count = 0; | ||
promiseRetry(function (retry) { | ||
return Promise.delay(10) | ||
return promiseRetry(function (retry) { | ||
return promiseDelay(10) | ||
.then(function () { | ||
@@ -155,8 +157,7 @@ if (count < 2) { | ||
expect(err.message).to.be('foo'); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should convert direct fulfillments into promises', function (done) { | ||
promiseRetry(function () { | ||
it('should convert direct fulfillments into promises', function () { | ||
return promiseRetry(function () { | ||
return 'final'; | ||
@@ -168,7 +169,6 @@ }, { factor: 1 }) | ||
throw new Error('should not fail'); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should convert direct rejections into promises', function (done) { | ||
it('should convert direct rejections into promises', function () { | ||
promiseRetry(function () { | ||
@@ -181,8 +181,7 @@ throw new Error('foo'); | ||
expect(err.message).to.be('foo'); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should not crash on undefined rejections', function (done) { | ||
promiseRetry(function () { | ||
it('should not crash on undefined rejections', function () { | ||
return promiseRetry(function () { | ||
throw undefined; | ||
@@ -204,13 +203,12 @@ }, { retries: 1, factor: 1 }) | ||
expect(err).to.be(undefined); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should retry if retry() was called with undefined', function (done) { | ||
it('should retry if retry() was called with undefined', function () { | ||
var count = 0; | ||
promiseRetry(function (retry) { | ||
return promiseRetry(function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
return promiseDelay(10) | ||
.then(function () { | ||
@@ -229,13 +227,12 @@ if (count <= 2) { | ||
throw new Error('should not fail'); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should work with several retries in the same chain', function (done) { | ||
it('should work with several retries in the same chain', function () { | ||
var count = 0; | ||
promiseRetry(function (retry) { | ||
return promiseRetry(function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
return promiseDelay(10) | ||
.then(function () { | ||
@@ -253,13 +250,12 @@ retry(new Error('foo')); | ||
expect(count).to.be(2); | ||
}) | ||
.done(done, done); | ||
}); | ||
}); | ||
it('should allow options to be passed first', function (done) { | ||
it('should allow options to be passed first', function () { | ||
var count = 0; | ||
promiseRetry({ factor: 1 }, function (retry) { | ||
return promiseRetry({ factor: 1 }, function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
return promiseDelay(10) | ||
.then(function () { | ||
@@ -277,4 +273,4 @@ if (count <= 2) { | ||
throw new Error('should not fail'); | ||
}).done(done, done); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15491
0
93
3
269
+ Addedpromise-try@^1.0.1
+ Addederr-code@1.1.2(transitive)
+ Addedpromise-try@1.0.1(transitive)
+ Addedretry@0.8.0(transitive)
- Removedbluebird@^2.6.2
- Removedbluebird@2.11.0(transitive)
- Removederr-code@0.1.2(transitive)
- Removedretry@0.6.1(transitive)
Updatederr-code@^1.0.0
Updatedretry@^0.8.0