Comparing version 1.1.0 to 1.1.2
@@ -91,3 +91,3 @@ const ms = require('ms'); | ||
if (typeof protectedPromise !== 'function') { | ||
throw new Error('expected a function returning a promise as the first argument'); | ||
throw new Error('expecting a function returning a promise but got ' + {}.toString.call(protectedPromise)); | ||
} | ||
@@ -99,2 +99,7 @@ | ||
const promise = protectedPromise.apply(null, args); | ||
if (!promise || !promise.then) { | ||
throw new Error('expecting function to return a promise but got ' + {}.toString.call(promise)); | ||
} | ||
promise.then(function () { | ||
@@ -101,0 +106,0 @@ const resultArgs = [null].concat(Array.from(arguments)); |
@@ -6,6 +6,4 @@ const DisyuntorError = function DisyuntorError(message) { | ||
DisyuntorError.prototype = Object.create(Error); | ||
DisyuntorError.prototype.constructor = DisyuntorError; | ||
DisyuntorError.prototype.name = 'DisyuntorError'; | ||
DisyuntorError.prototype = new Error(); | ||
module.exports = DisyuntorError; |
{ | ||
"name": "disyuntor", | ||
"description": "A circuit-breaker implementation with exponential backoff.", | ||
"version": "1.1.0", | ||
"version": "1.1.2", | ||
"author": "José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)", | ||
@@ -12,3 +12,3 @@ "repository": { | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "./node_modules/.bin/istanbul cover _mocha" | ||
}, | ||
@@ -23,4 +23,5 @@ "dependencies": { | ||
"chai": "~2.3.0", | ||
"istanbul": "~0.4.5", | ||
"mocha": "~2.2.5" | ||
} | ||
} |
@@ -5,4 +5,20 @@ const disyuntor = require('./..'); | ||
const Promise = require('bluebird'); | ||
const DisyuntorError = require('../lib/DisyuntorError'); | ||
describe('disyuntor (promise)', function () { | ||
it('should throw an error if func is undefined', function () { | ||
assert.throw(() => { | ||
disyuntor.promise(); | ||
}, /expecting a function returning a promise but got \[object Undefined\]/); | ||
}); | ||
it('should throw an error if func does not return a promise', function () { | ||
disyuntor | ||
.promise(() => {}, { name: 'null.fail' })() | ||
.catch(err => { | ||
assert.equal(err.message, 'expecting function to return a promise but got [object Undefined]'); | ||
}); | ||
}); | ||
describe('when the protected promise never ends', function () { | ||
@@ -39,2 +55,4 @@ var monitorCalls = []; | ||
sut().catch(err2 => { | ||
assert.instanceOf(err2, Error); | ||
assert.instanceOf(err2, DisyuntorError); | ||
assert.match(err2.message, /test\.func: the circuit-breaker is open/); | ||
@@ -41,0 +59,0 @@ assert.closeTo(Date.now() - startTime, 1, 2); |
@@ -20,5 +20,5 @@ const disyuntor = require('./..'); | ||
monitorCalls = []; | ||
sut = disyuntor(() => {}, { | ||
sut = disyuntor(cb => setTimeout(cb, 500), { | ||
name: 'test.func', | ||
timeout: 10, | ||
timeout: '10ms', | ||
maxFailures: 1, | ||
@@ -25,0 +25,0 @@ cooldown: 200, |
19378
420
5