Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "polly-js", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Transient exception handling", | ||
"main": "src/polly.js", | ||
"scripts": { | ||
"test": "mocha tests", | ||
"test:watch": "npm test -- --watch" | ||
"test": "istanbul cover ./node_modules/mocha/bin/_mocha tests", | ||
"test:watch": "mocha tests --watch", | ||
"report-coverage": "cat ./coverage/lcov.info | ./node_modules/.bin/codecov" | ||
}, | ||
@@ -32,4 +33,6 @@ "repository": { | ||
"chai-as-promised": "^5.1.0", | ||
"codecov.io": "^0.1.6", | ||
"gulp": "^3.9.0", | ||
"gulp-mocha": "^2.1.3", | ||
"istanbul": "^0.3.21", | ||
"mocha": "^2.3.2", | ||
@@ -36,0 +39,0 @@ "request-promise": "^0.4.3" |
# polly-js | ||
Transient exception handling for JavaScript | ||
[](https://npmjs.org/package/polly-js) | ||
[](https://www.npmjs.org/package/polly-js) | ||
[](http://npm-stat.com/charts.html?package=polly-js&from=2015-09-01) | ||
[](https://david-dm.org/mauricedb/polly-js) | ||
[](https://travis-ci.org/mauricedb/polly-js) | ||
[](http://codecov.io/github/mauricedb/polly-js?branch=master) | ||
@@ -21,3 +23,2 @@ Polly-js is a library to help developers recover from transient errors using policies like retry or wait and retry. | ||
.executeForPromise(function () { | ||
count++; | ||
return requestPromise('http://www.google.com'); | ||
@@ -24,0 +25,0 @@ }) |
@@ -5,3 +5,17 @@ /** | ||
module.exports = (function () { | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], factory); | ||
} else if (typeof exports === 'object') { | ||
// Node. Does not work with strict CommonJS, but | ||
// only CommonJS-like environments that support module.exports, | ||
// like Node. | ||
module.exports = factory(); | ||
} else { | ||
// Browser globals (root is window) | ||
root.polly = factory(); | ||
} | ||
}(this, function () { | ||
'use strict'; | ||
@@ -49,5 +63,5 @@ function execute(config, cb) { | ||
return { | ||
retry: function () { | ||
retry: function (count) { | ||
var config = { | ||
count: 1 | ||
count: count || 1 | ||
}; | ||
@@ -61,2 +75,2 @@ | ||
} | ||
}()); | ||
})); |
@@ -5,2 +5,4 @@ /** | ||
'use strict'; | ||
var chai = require('chai'); | ||
@@ -57,2 +59,19 @@ var chaiAsPromised = require('chai-as-promised'); | ||
it('should retry five times after an error and still fail', function () { | ||
var count = 0; | ||
try { | ||
polly | ||
.retry(5) | ||
.execute(function () { | ||
count++; | ||
throw new Error("Wrong value"); | ||
}); | ||
} | ||
catch (ex) { | ||
} | ||
count.should.equal(6); | ||
}); | ||
it('should retry once after an error and succeed', function () { | ||
@@ -62,3 +81,4 @@ var count = 0; | ||
var result = polly | ||
.retry().execute(function () { | ||
.retry() | ||
.execute(function () { | ||
count++; | ||
@@ -75,2 +95,20 @@ if (count === 1) { | ||
}); | ||
it('should retry four after an error and succeed', function () { | ||
var count = 0; | ||
var result = polly | ||
.retry(5) | ||
.execute(function () { | ||
count++; | ||
if (count < 5) { | ||
throw new Error("Wrong value"); | ||
} | ||
return 42; | ||
}); | ||
result.should.equal(42); | ||
count.should.equal(5); | ||
}); | ||
}); | ||
@@ -118,2 +156,20 @@ | ||
it('should retry five times after an error and still fail', function () { | ||
var count = 0; | ||
return polly | ||
.retry(5) | ||
.executeForPromise(function () { | ||
return new Promise(function (resolve, reject) { | ||
count++; | ||
reject(new Error("Wrong value")); | ||
}); | ||
}) | ||
.should.eventually | ||
.be.rejected | ||
.then(function () { | ||
count.should.equal(6); | ||
}); | ||
}); | ||
it('should retry once after an error and succeed', function () { | ||
@@ -138,3 +194,23 @@ var count = 0; | ||
}); | ||
}); | ||
it('should retry four times after an error and succeed', function () { | ||
var count = 0; | ||
return polly | ||
.retry(5) | ||
.executeForPromise(function () { | ||
return new Promise(function (resolve, reject) { | ||
count++; | ||
if (count < 5) { | ||
reject(new Error("Wrong value")); | ||
} else { | ||
resolve(42); | ||
} | ||
}); | ||
}) | ||
.should.eventually.equal(42) | ||
.then(function () { | ||
count.should.equal(5); | ||
}); | ||
}); | ||
@@ -141,0 +217,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
265586
19
278
36
0
8