auto-release-sinon
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,59 +0,55 @@ | ||
var sinon = require('sinon'); | ||
var _ = require('lodash'); | ||
var toRestore = []; | ||
var toWrap = { | ||
stub: null, | ||
spy: null, | ||
useFakeTimers: function (clock) { | ||
// timeouts are indexed by their id in an array, | ||
// the holes make the .length property "wrong" | ||
clock.timeoutCount = function () { | ||
return clock.timeoutList().length; | ||
}; | ||
function own(obj, fn) { | ||
if (typeof obj !== 'object') return; | ||
clock.timeoutList = function () { | ||
return clock.timeouts ? clock.timeouts.filter(Boolean) : []; | ||
}; | ||
} | ||
}; | ||
Object.keys(obj).forEach(function (k) { | ||
fn(obj[k], k, obj); | ||
}); | ||
} | ||
_.forOwn(toWrap, function (modify, method) { | ||
var orig = sinon[method]; | ||
sinon[method] = function () { | ||
var obj = orig.apply(sinon, arguments); | ||
module.exports = function hook(sinon, afterEach) { | ||
// after each test this list is cleared | ||
if (obj.restore) toRestore.push(obj); | ||
var toRestore = []; | ||
var toWrap = { | ||
stub: null, | ||
spy: null, | ||
useFakeTimers: function (clock) { | ||
// timeouts are indexed by their id in an array, | ||
// the holes make the .length property "wrong" | ||
clock.timeoutCount = function () { | ||
return clock.timeoutList().length; | ||
}; | ||
if (typeof modify === 'function') modify(obj); | ||
return obj; | ||
clock.timeoutList = function () { | ||
return clock.timeouts ? clock.timeouts.filter(Boolean) : []; | ||
}; | ||
} | ||
}; | ||
_.forOwn(orig, function (val, name) { | ||
sinon[method][name] = val; | ||
}); | ||
}); | ||
own(toWrap, function (modify, method) { | ||
var orig = sinon[method]; | ||
sinon[method] = function () { | ||
var obj = orig.apply(sinon, arguments); | ||
// helper | ||
sinon.decorateWithSpy = _.restParam(function (props) { | ||
return function ($delegate) { | ||
props.forEach(function (prop) { | ||
sinon.spy($delegate, prop); | ||
}); | ||
// after each test this list is cleared | ||
if (obj.restore) toRestore.push(obj); | ||
return $delegate; | ||
}; | ||
}); | ||
if (typeof modify === 'function') modify(obj); | ||
afterEach(function () { | ||
if (!toRestore.length) return; | ||
return obj; | ||
}; | ||
_.each(toRestore, function (obj) { | ||
obj.restore(); | ||
own(orig, function (val, name) { | ||
sinon[method][name] = val; | ||
}); | ||
}); | ||
toRestore = []; | ||
}); | ||
afterEach(function () { | ||
toRestore.splice(0).forEach(function (obj) { | ||
obj.restore(); | ||
}); | ||
}); | ||
return sinon; | ||
}; |
{ | ||
"name": "auto-release-sinon", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Basic sinon wrapper that automatically releases it's stubs, works with mocha's BDD interface", | ||
@@ -24,3 +24,12 @@ "main": "autoReleaseSinon.js", | ||
}, | ||
"homepage": "https://github.com/spalger/auto-release-sinon#readme" | ||
"homepage": "https://github.com/spalger/auto-release-sinon#readme", | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"sinon": "^1.15.4" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.1.0", | ||
"mocha": "^2.2.5", | ||
"sinon": "^1.15.4" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
2977
6
61
1
8
1
3