Comparing version 5.6.6 to 5.7.0
198
lib/test.js
@@ -18,2 +18,3 @@ 'use strict'; | ||
var every = require('array.prototype.every'); | ||
var mockProperty = require('mock-property'); | ||
@@ -30,2 +31,3 @@ var isEnumerable = callBound('Object.prototype.propertyIsEnumerable'); | ||
var $shift = callBound('Array.prototype.shift'); | ||
var $slice = callBound('Array.prototype.slice'); | ||
@@ -46,8 +48,7 @@ var nextTick = typeof setImmediate !== 'undefined' | ||
var arg = arguments[i]; | ||
var t = typeof arg; | ||
if (t === 'string') { | ||
if (typeof arg === 'string') { | ||
name = arg; | ||
} else if (t === 'object') { | ||
} else if (typeof arg === 'object') { | ||
opts = arg || opts; | ||
} else if (t === 'function') { | ||
} else if (typeof arg === 'function') { | ||
cb = arg; | ||
@@ -123,14 +124,17 @@ } | ||
var self = this; | ||
Promise.resolve(callbackReturn).then(function onResolve() { | ||
if (!self.calledEnd) { | ||
Promise.resolve(callbackReturn).then( | ||
function onResolve() { | ||
if (!self.calledEnd) { | ||
self.end(); | ||
} | ||
}, | ||
function onError(err) { | ||
if (err instanceof Error || objectToString(err) === '[object Error]') { | ||
self.ifError(err); | ||
} else { | ||
self.fail(err); | ||
} | ||
self.end(); | ||
} | ||
})['catch'](function onError(err) { | ||
if (err instanceof Error || objectToString(err) === '[object Error]') { | ||
self.ifError(err); | ||
} else { | ||
self.fail(err); | ||
} | ||
self.end(); | ||
}); | ||
); | ||
return; | ||
@@ -209,2 +213,168 @@ } | ||
function wrapFunction(original) { | ||
if (typeof original !== 'undefined' && typeof original !== 'function') { | ||
throw new TypeError('`original` must be a function or `undefined`'); | ||
} | ||
var bound = original && callBind.apply(original); | ||
var calls = []; | ||
var wrapObject = { | ||
__proto__: null, | ||
wrapped: function wrapped() { | ||
var args = $slice(arguments); | ||
var completed = false; | ||
try { | ||
var returned = original ? bound(this, arguments) : void undefined; | ||
$push(calls, { args: args, receiver: this, returned: returned }); | ||
completed = true; | ||
return returned; | ||
} finally { | ||
if (!completed) { | ||
$push(calls, { args: args, receiver: this, threw: true }); | ||
} | ||
} | ||
}, | ||
calls: calls, | ||
results: function results() { | ||
try { | ||
return calls; | ||
} finally { | ||
calls = []; | ||
wrapObject.calls = calls; | ||
} | ||
} | ||
}; | ||
return wrapObject; | ||
} | ||
Test.prototype.capture = function capture(obj, method) { | ||
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) { | ||
throw new TypeError('`obj` must be an object'); | ||
} | ||
if (typeof method !== 'string' && typeof method !== 'symbol') { | ||
throw new TypeError('`method` must be a string or a symbol'); | ||
} | ||
var implementation = arguments.length > 2 ? arguments[2] : void undefined; | ||
if (typeof implementation !== 'undefined' && typeof implementation !== 'function') { | ||
throw new TypeError('`implementation`, if provided, must be a function'); | ||
} | ||
var wrapper = wrapFunction(implementation); | ||
var restore = mockProperty(obj, method, { value: wrapper.wrapped }); | ||
this.teardown(restore); | ||
wrapper.results.restore = restore; | ||
return wrapper.results; | ||
}; | ||
Test.prototype.captureFn = function captureFn(original) { | ||
if (typeof original !== 'function') { | ||
throw new TypeError('`original` must be a function'); | ||
} | ||
var wrapObject = wrapFunction(original); | ||
wrapObject.wrapped.calls = wrapObject.calls; | ||
return wrapObject.wrapped; | ||
}; | ||
Test.prototype.intercept = function intercept(obj, property) { | ||
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) { | ||
throw new TypeError('`obj` must be an object'); | ||
} | ||
if (typeof property !== 'string' && typeof property !== 'symbol') { | ||
throw new TypeError('`property` must be a string or a symbol'); | ||
} | ||
var desc = arguments.length > 2 ? arguments[2] : { __proto__: null }; | ||
if (typeof desc !== 'undefined' && (!desc || typeof desc !== 'object')) { | ||
throw new TypeError('`desc`, if provided, must be an object'); | ||
} | ||
if ('configurable' in desc && !desc.configurable) { | ||
throw new TypeError('`desc.configurable`, if provided, must be `true`, so that the interception can be restored later'); | ||
} | ||
var isData = 'writable' in desc || 'value' in desc; | ||
var isAccessor = 'get' in desc || 'set' in desc; | ||
if (isData && isAccessor) { | ||
throw new TypeError('`value` and `writable` can not be mixed with `get` and `set`'); | ||
} | ||
var strictMode = arguments.length > 3 ? arguments[3] : true; | ||
if (typeof strictMode !== 'boolean') { | ||
throw new TypeError('`strictMode`, if provided, must be a boolean'); | ||
} | ||
var calls = []; | ||
var getter = desc.get && callBind.apply(desc.get); | ||
var setter = desc.set && callBind.apply(desc.set); | ||
var value = !isAccessor ? desc.value : void undefined; | ||
var writable = !!desc.writable; | ||
function getInterceptor() { | ||
var args = $slice(arguments); | ||
if (isAccessor) { | ||
if (getter) { | ||
var completed = false; | ||
try { | ||
var returned = getter(this, arguments); | ||
completed = true; | ||
$push(calls, { type: 'get', success: true, value: returned, args: args, receiver: this }); | ||
return returned; | ||
} finally { | ||
if (!completed) { | ||
$push(calls, { type: 'get', success: false, threw: true, args: args, receiver: this }); | ||
} | ||
} | ||
} | ||
} | ||
$push(calls, { type: 'get', success: true, value: value, args: args, receiver: this }); | ||
return value; | ||
} | ||
function setInterceptor(v) { | ||
var args = $slice(arguments); | ||
if (isAccessor && setter) { | ||
var completed = false; | ||
try { | ||
var returned = setter(this, arguments); | ||
completed = true; | ||
$push(calls, { type: 'set', success: true, value: v, args: args, receiver: this }); | ||
return returned; | ||
} finally { | ||
if (!completed) { | ||
$push(calls, { type: 'set', success: false, threw: true, args: args, receiver: this }); | ||
} | ||
} | ||
} | ||
var canSet = isAccessor || writable; | ||
if (canSet) { | ||
value = v; | ||
} | ||
$push(calls, { type: 'set', success: !!canSet, value: value, args: args, receiver: this }); | ||
if (!canSet && strictMode) { | ||
throw new TypeError('Cannot assign to read only property \'' + property + '\' of object \'' + inspect(obj) + '\''); | ||
} | ||
return value; | ||
} | ||
var restore = mockProperty(obj, property, { | ||
nonEnumerable: !!desc.enumerable, | ||
get: getInterceptor, | ||
set: setInterceptor | ||
}); | ||
this.teardown(restore); | ||
function results() { | ||
try { | ||
return calls; | ||
} finally { | ||
calls = []; | ||
} | ||
} | ||
results.restore = restore; | ||
return results; | ||
}; | ||
Test.prototype._end = function _end(err) { | ||
@@ -211,0 +381,0 @@ var self = this; |
{ | ||
"name": "tape", | ||
"version": "5.6.6", | ||
"version": "5.7.0", | ||
"description": "tap-producing test harness for node and browsers", | ||
@@ -30,3 +30,3 @@ "main": "index.js", | ||
"@ljharb/through": "^2.3.9", | ||
"array.prototype.every": "^1.1.4", | ||
"array.prototype.every": "^1.1.5", | ||
"call-bind": "^1.0.2", | ||
@@ -44,2 +44,3 @@ "deep-equal": "^2.2.2", | ||
"minimist": "^1.2.8", | ||
"mock-property": "^1.0.0", | ||
"object-inspect": "^1.12.3", | ||
@@ -50,7 +51,7 @@ "object-is": "^1.1.5", | ||
"resolve": "^2.0.0-next.4", | ||
"string.prototype.trim": "^1.2.7" | ||
"string.prototype.trim": "^1.2.8" | ||
}, | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.1.0", | ||
"array.prototype.flatmap": "^1.3.1", | ||
"array.prototype.flatmap": "^1.3.2", | ||
"aud": "^2.0.3", | ||
@@ -64,2 +65,3 @@ "auto-changelog": "^2.4.0", | ||
"falafel": "^2.2.5", | ||
"intl-fallback-symbol": "^1.0.0", | ||
"jackspeak": "=2.1.1", | ||
@@ -78,3 +80,3 @@ "js-yaml": "^3.14.0", | ||
"prepublishOnly": "safe-publish-latest", | ||
"prepublish": "!(type not-in-publish) || not-in-publish || npm run prepublishOnly", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"prelint:files": "git ls-files 2>/dev/null | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' || echo '*.md *.js test/*.js'", | ||
@@ -81,0 +83,0 @@ "eclint": "FILES=\"$(npm run --silent prelint:files)\" eclint check \"${FILES:=package.json}\"", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
393081
164
7455
639
22
18
+ Addedmock-property@^1.0.0
+ Addedmock-property@1.1.0(transitive)
Updatedarray.prototype.every@^1.1.5
Updatedstring.prototype.trim@^1.2.8