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

polly-js

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polly-js - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

2

package.json
{
"name": "polly-js",
"version": "1.5.0",
"version": "1.6.0",
"description": "Transient exception handling",

@@ -5,0 +5,0 @@ "main": "src/polly.js",

@@ -30,3 +30,3 @@ /**

try {
return cb();
return cb({count});
}

@@ -48,3 +48,3 @@ catch (ex) {

function execute() {
var original = cb();
var original = cb({count});

@@ -68,6 +68,7 @@ original.then(function (e) {

function executeForPromiseWithDelay(config, cb) {
var count = 0;
return new Promise(function (resolve, reject) {
function execute() {
var original = cb();
var original = cb({count});

@@ -80,2 +81,3 @@ original.then(function (e) {

if (delay && config.handleFn(e)) {
count++;
setTimeout(execute, delay);

@@ -99,3 +101,3 @@ } else {

count++;
fn(internalCallback);
fn(internalCallback, {count});
} else {

@@ -107,6 +109,7 @@ callback(err, data);

fn(internalCallback);
fn(internalCallback, {count});
}
function executeForNodeWithDelay(config, fn, callback) {
var count = 0;

@@ -116,4 +119,5 @@ function internalCallback(err, data) {

if (err && delay && config.handleFn(err)) {
count++;
setTimeout(function () {
fn(internalCallback);
fn(internalCallback, {count});
}, delay);

@@ -125,3 +129,3 @@ } else {

fn(internalCallback);
fn(internalCallback, {count});
}

@@ -128,0 +132,0 @@

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

.retry()
.executeForNode(function (cb) {
.executeForNode(function (cb, {count}) {
fs.readFile(path.join(__dirname, './hello.txt'), cb);

@@ -32,3 +32,3 @@ }, function (err, data) {

.retry()
.executeForNode(function (cb) {
.executeForNode(function (cb, {count}) {
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -44,8 +44,8 @@ }, function (err, data) {

it('should retry once after an error and still fail', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.retry()
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -56,3 +56,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(2);
actualRetryCount.should.equal(1);
done();

@@ -63,8 +63,8 @@ });

it('should retry five times after an error and still fail', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.retry(5)
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -75,3 +75,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(6);
actualRetryCount.should.equal(5);
done();

@@ -82,10 +82,10 @@ });

it('should retry once after an error and succeed', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.retry()
.executeForNode(function (cb) {
.executeForNode(function (cb, {count}) {
count++;
if (count === 1) {
actualRetryCount = count;
if (count < 1) {
cb(new Error("Wrong value"));

@@ -98,3 +98,3 @@ } else {

data.should.equal(42);
count.should.equal(2);
actualRetryCount.should.equal(1);
done();

@@ -105,9 +105,9 @@ });

it('should retry four times after an error and succeed', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.retry(5)
.executeForNode(function (cb) {
count++;
if (count < 5) {
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
if (count < 4) {
cb(new Error("Wrong value"));

@@ -120,3 +120,3 @@ } else {

data.should.equal(42);
count.should.equal(5);
actualRetryCount.should.equal(4);
done();

@@ -127,3 +127,3 @@ });

it('should retry five times if handling the error after an error and still fail', function (done) {
var count = 0;
var actualRetryCount = 0;

@@ -135,4 +135,4 @@ polly()

.retry(5)
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -143,3 +143,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(6);
actualRetryCount.should.equal(5);
done();

@@ -150,3 +150,3 @@ });

it('should not retry if not handling the error and still fail', function (done) {
var count = 0;
var actualRetryCount = 0;

@@ -158,4 +158,4 @@ polly()

.retry(5)
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -166,3 +166,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(1);
actualRetryCount.should.equal(0);
done();

@@ -169,0 +169,0 @@ });

@@ -35,9 +35,9 @@ 'use strict';

it('should retry once after an error and still fail', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.retry()
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
actualRetryCount = count;
reject(new Error("Wrong value"));

@@ -49,3 +49,3 @@ });

.then(function () {
count.should.equal(2);
actualRetryCount.should.equal(1);
});

@@ -55,9 +55,9 @@ });

it('should retry five times after an error and still fail', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.retry(5)
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
actualRetryCount = count;
reject(new Error("Wrong value"));

@@ -69,3 +69,3 @@ });

.then(function () {
count.should.equal(6);
actualRetryCount.should.equal(5);
});

@@ -75,10 +75,10 @@ });

it('should retry once after an error and succeed', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.retry()
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
if (count === 1) {
actualRetryCount = count;
if (count < 1) {
reject(new Error("Wrong value"));

@@ -92,3 +92,3 @@ } else {

.then(function () {
count.should.equal(2);
actualRetryCount.should.equal(1);
});

@@ -98,10 +98,10 @@ });

it('should retry four times after an error and succeed', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.retry(5)
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
if (count < 5) {
actualRetryCount = count;
if (count < 4) {
reject(new Error("Wrong value"));

@@ -115,3 +115,3 @@ } else {

.then(function () {
count.should.equal(5);
actualRetryCount.should.equal(4);
});

@@ -121,8 +121,8 @@ });

it('we can load html from Google', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.retry()
.executeForPromise(function () {
count++;
.executeForPromise(function ({count}) {
actualRetryCount = count;
return requestPromise('http://www.google.com');

@@ -132,3 +132,3 @@ })

.then(function () {
count.should.equal(1);
actualRetryCount.should.equal(0);
})

@@ -138,8 +138,8 @@ });

it('we can\'t load html from an invalid URL', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.retry()
.executeForPromise(function () {
count++;
.executeForPromise(function ({count}) {
actualRetryCount = count;
return requestPromise('http://www.this-is-no-site.com');

@@ -149,3 +149,3 @@ })

.then(function () {
count.should.equal(2);
actualRetryCount.should.equal(1);
})

@@ -155,3 +155,3 @@ });

it('should retry five times if handling the error after an error and still fail', function () {
var count = 0;
var actualRetryCount = 0;

@@ -163,5 +163,5 @@ return polly()

.retry(5)
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
actualRetryCount = count;
reject(new Error("Wrong value"));

@@ -173,3 +173,3 @@ });

.then(function () {
count.should.equal(6);
actualRetryCount.should.equal(5);
});

@@ -179,3 +179,3 @@ });

it('should not retry if not handling the error and still fail', function () {
var count = 0;
var actualRetryCount = 0;

@@ -187,5 +187,5 @@ return polly()

.retry(5)
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
actualRetryCount = count;
reject(new Error("Wrong value"));

@@ -197,5 +197,5 @@ });

.then(function () {
count.should.equal(1);
actualRetryCount.should.equal(0);
});
});
});

@@ -11,3 +11,4 @@ 'use strict';

.retry()
.execute(function () {
.execute(function ({count}) {
count.should.equal(1);
return 42;

@@ -31,3 +32,3 @@ });

it('should retry once after an error and still fail', function () {
var count = 0;
var actualRetryCount = 0;

@@ -37,4 +38,4 @@ try {

.retry()
.execute(function () {
count++;
.execute(function ({count}) {
actualRetryCount = count;
throw new Error("Wrong value");

@@ -46,7 +47,7 @@ });

count.should.equal(2);
actualRetryCount.should.equal(1);
});
it('should retry five times after an error and still fail', function () {
var count = 0;
var actualRetryCount = 0;

@@ -56,4 +57,4 @@ try {

.retry(5)
.execute(function () {
count++;
.execute(function ({count}) {
actualRetryCount = count;
throw new Error("Wrong value");

@@ -65,13 +66,13 @@ });

count.should.equal(6);
actualRetryCount.should.equal(5);
});
it('should retry once after an error and succeed', function () {
var count = 0;
var actualRetryCount = 0;
var result = polly()
.retry()
.execute(function () {
count++;
if (count === 1) {
.execute(function ({count}) {
actualRetryCount = count;
if (count < 1) {
throw new Error("Wrong value");

@@ -84,12 +85,12 @@ }

result.should.equal(42);
count.should.equal(2);
actualRetryCount.should.equal(1);
});
it('should retry four after an error and succeed', function () {
var count = 0;
var actualRetryCount = 0;
var result = polly()
.retry(5)
.execute(function () {
count++;
.execute(function ({count}) {
actualRetryCount = count;
if (count < 5) {

@@ -103,7 +104,7 @@ throw new Error("Wrong value");

result.should.equal(42);
count.should.equal(5);
actualRetryCount.should.equal(5);
});
it('should retry five times after an error and still fail when all should be handled', function () {
var count = 0;
var actualRetryCount = 0;

@@ -116,4 +117,4 @@ try {

.retry(5)
.execute(function () {
count++;
.execute(function ({count}) {
actualRetryCount = count;
throw new Error("Wrong value");

@@ -125,7 +126,7 @@ });

count.should.equal(6);
actualRetryCount.should.equal(5);
});
it('should not retry times after an error and still fail when none should be handled', function () {
var count = 0;
var actualRetryCount = 0;

@@ -138,4 +139,4 @@ try {

.retry(5)
.execute(function () {
count++;
.execute(function ({count}) {
actualRetryCount = count;
throw new Error("Wrong value");

@@ -147,7 +148,7 @@ });

count.should.equal(1);
actualRetryCount.should.equal(0);
});
it('should retry 2 times after an error and still fail when all should be handled', function () {
var count = 0;
var actualRetryCount = 0;

@@ -157,7 +158,7 @@ try {

.handle(function() {
return count <= 2;
return actualRetryCount < 2;
})
.retry(5)
.execute(function () {
count++;
.execute(function ({count}) {
actualRetryCount = count;
throw new Error("Wrong value");

@@ -169,7 +170,7 @@ });

count.should.equal(3);
actualRetryCount.should.equal(2);
});
it('ignore the handle call if it isnt parameter a function', function () {
var count = 0;
var actualRetryCount = 0;

@@ -180,4 +181,4 @@ try {

.retry(5)
.execute(function () {
count++;
.execute(function ({count}) {
actualRetryCount = count;
throw new Error("Wrong value");

@@ -189,5 +190,5 @@ });

count.should.equal(6);
actualRetryCount.should.equal(5);
});
});

@@ -46,8 +46,8 @@ 'use strict';

it('should retry once after an error and still fail', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.waitAndRetry()
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -58,3 +58,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(2);
actualRetryCount.should.equal(1);
done();

@@ -65,8 +65,8 @@ });

it('should retry five times after an error and still fail', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.waitAndRetry([1, 1, 1, 1, 1])
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -77,3 +77,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(6);
actualRetryCount.should.equal(5);
done();

@@ -84,8 +84,8 @@ });

it('should retry five times after an error and still fail', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.waitAndRetry(5)
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -96,3 +96,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(6);
actualRetryCount.should.equal(5);
done();

@@ -103,10 +103,10 @@ });

it('should retry once after an error and succeed', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.waitAndRetry()
.executeForNode(function (cb) {
.executeForNode(function (cb, {count}) {
count++;
if (count === 1) {
actualRetryCount = count;
if (actualRetryCount < 1) {
cb(new Error("Wrong value"));

@@ -119,3 +119,3 @@ } else {

data.should.equal(42);
count.should.equal(2);
actualRetryCount.should.equal(1);
done();

@@ -126,9 +126,9 @@ });

it('should retry four times after an error and succeed', function (done) {
var count = 0;
var actualRetryCount = 0;
polly()
.waitAndRetry(5)
.executeForNode(function (cb) {
count++;
if (count < 5) {
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
if (actualRetryCount < 4) {
cb(new Error("Wrong value"));

@@ -141,3 +141,3 @@ } else {

data.should.equal(42);
count.should.equal(5);
actualRetryCount.should.equal(4);
done();

@@ -148,3 +148,3 @@ });

it('should retry once because we are handling the no such file or directory error', function (done) {
var count = 0;
var actualRetryCount = 0;

@@ -156,4 +156,4 @@ polly()

.waitAndRetry()
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -164,3 +164,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(2);
actualRetryCount.should.equal(1);
done();

@@ -171,3 +171,3 @@ });

it('should not retry because we are not handling the no such file or directory error', function (done) {
var count = 0;
var actualRetryCount = 0;

@@ -179,4 +179,4 @@ polly()

.waitAndRetry()
.executeForNode(function (cb) {
count++;
.executeForNode(function (cb, {count}) {
actualRetryCount = count;
fs.readFile(path.join(__dirname, './not-there.txt'), cb);

@@ -187,3 +187,3 @@ }, function (err, data) {

should.not.exist(data);
count.should.equal(1);
actualRetryCount.should.equal(0);
done();

@@ -190,0 +190,0 @@ });

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

.waitAndRetry()
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return Promise.resolve(42);

@@ -41,9 +41,9 @@ })

it('should retry once after an error and still fail', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.waitAndRetry()
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
actualRetryCount = count;
reject(new Error("Wrong value"));

@@ -55,3 +55,3 @@ });

.then(function () {
count.should.equal(2);
actualRetryCount.should.equal(1);
});

@@ -61,9 +61,9 @@ });

it('should retry five times after an error and still fail', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.waitAndRetry([1, 1, 1, 1, 1])
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
actualRetryCount = count;
reject(new Error("Wrong value"));

@@ -75,3 +75,3 @@ });

.then(function () {
count.should.equal(6);
actualRetryCount.should.equal(5);
});

@@ -81,10 +81,10 @@ });

it('should retry once after an error and succeed', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.waitAndRetry()
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
if (count === 1) {
actualRetryCount = count;
if (actualRetryCount < 1) {
reject(new Error("Wrong value"));

@@ -98,3 +98,3 @@ } else {

.then(function () {
count.should.equal(2);
actualRetryCount.should.equal(1);
});

@@ -104,10 +104,10 @@ });

it('should retry four times specifying delays after an error and succeed', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.waitAndRetry([1, 1, 1, 1, 1])
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
if (count < 5) {
actualRetryCount = count;
if (actualRetryCount < 4) {
reject(new Error("Wrong value"));

@@ -121,3 +121,3 @@ } else {

.then(function () {
count.should.equal(5);
actualRetryCount.should.equal(4);
});

@@ -127,10 +127,10 @@ });

it('should retry four times specifying the number after an error and succeed', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.waitAndRetry(5)
.executeForPromise(function () {
.executeForPromise(function ({count}) {
return new Promise(function (resolve, reject) {
count++;
if (count < 5) {
actualRetryCount = count;
if (actualRetryCount < 4) {
reject(new Error("Wrong value"));

@@ -144,3 +144,3 @@ } else {

.then(function () {
count.should.equal(5);
actualRetryCount.should.equal(4);
});

@@ -150,8 +150,8 @@ });

it('we can load html from Google', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.waitAndRetry()
.executeForPromise(function () {
count++;
.executeForPromise(function ({count}) {
actualRetryCount = count;
return requestPromise('http://www.google.com');

@@ -161,3 +161,3 @@ })

.then(function () {
count.should.equal(1);
actualRetryCount.should.equal(0);
})

@@ -167,8 +167,8 @@ });

it('we can\'t load html from an invalid URL', function () {
var count = 0;
var actualRetryCount = 0;
return polly()
.waitAndRetry()
.executeForPromise(function () {
count++;
.executeForPromise(function ({count}) {
actualRetryCount = count;
return requestPromise('http://www.this-is-no-site.com');

@@ -178,5 +178,5 @@ })

.then(function () {
count.should.equal(2);
actualRetryCount.should.equal(1);
})
});
});

Sorry, the diff of this file is not supported yet

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