Socket
Socket
Sign inDemoInstall

tape

Package Overview
Dependencies
Maintainers
3
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tape - npm Package Compare versions

Comparing version 4.16.2 to 4.17.0

test/capture.js

2

index.js

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

var createResult = require('./lib/results');
var through = require('through');
var through = require('@ljharb/through');

@@ -10,0 +10,0 @@ var canEmitExit = typeof process !== 'undefined' && process

'use strict';
var through = require('through');
var through = require('@ljharb/through');
var fs = require('fs');

@@ -5,0 +5,0 @@

@@ -6,4 +6,4 @@ 'use strict';

var inherits = require('inherits');
var through = require('through');
var resumer = require('resumer');
var through = require('@ljharb/through');
var resumer = require('@ljharb/resumer');
var inspect = require('object-inspect');

@@ -10,0 +10,0 @@ var callBound = require('call-bind/callBound');

@@ -11,5 +11,8 @@ 'use strict';

var trim = require('string.prototype.trim');
var callBind = require('call-bind');
var callBound = require('call-bind/callBound');
var forEach = require('for-each');
var inspect = require('object-inspect');
var mockProperty = require('mock-property');
var isEnumerable = callBound('Object.prototype.propertyIsEnumerable');

@@ -19,2 +22,4 @@ var toLowerCase = callBound('String.prototype.toLowerCase');

var objectToString = callBound('Object.prototype.toString');
var $push = callBound('Array.prototype.push');
var $slice = callBound('Array.prototype.slice');

@@ -35,8 +40,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;

@@ -178,2 +182,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 (err) {

@@ -180,0 +350,0 @@ var self = this;

{
"name": "tape",
"version": "4.16.2",
"version": "4.17.0",
"description": "tap-producing test harness for node and browsers",

@@ -15,2 +15,4 @@ "main": "index.js",

"dependencies": {
"@ljharb/resumer": "~0.0.1",
"@ljharb/through": "~2.3.9",
"call-bind": "~1.0.2",

@@ -25,13 +27,12 @@ "deep-equal": "~1.1.1",

"is-regex": "~1.1.4",
"minimist": "~1.2.7",
"minimist": "~1.2.8",
"mock-property": "~1.0.0",
"object-inspect": "~1.12.3",
"resolve": "~1.22.1",
"resumer": "~0.0.0",
"string.prototype.trim": "~1.2.7",
"through": "~2.3.8"
"resolve": "~1.22.6",
"string.prototype.trim": "~1.2.8"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.0.1",
"array.prototype.flatmap": "^1.3.1",
"aud": "^2.0.2",
"@ljharb/eslint-config": "^21.1.0",
"array.prototype.flatmap": "^1.3.2",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",

@@ -44,2 +45,3 @@ "concat-stream": "^1.6.2",

"falafel": "^2.2.5",
"jackspeak": "=2.1.1",
"js-yaml": "^3.14.0",

@@ -57,3 +59,3 @@ "npm-run-posix-or-windows": "^2.0.2",

"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'",

@@ -60,0 +62,0 @@ "eclint": "FILES=\"$(npm run --silent prelint:files)\" eclint check \"${FILES:=package.json}\"",

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

var expectedExitCodeFailure = (/^0\.10\.\d+$/).test(process.versions.node);
var expectedStackTraceBug = (/^3\.[012]\.\d+$/).test(process.versions.node); // https://github.com/nodejs/node/issues/2581
var expectedExitCodeOnError = (/^0\.(?:9|10)/).test(process.versions.node) ? 8 : 1; // node v0.9 sets this exit code to 8, for some reason
tap.test(
'Should throw error when --no-only is passed via cli and there is a .only test',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
{ todo: expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {

@@ -26,3 +26,3 @@ tt.plan(3);

tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
tt.equal(err.code, expectedExitCodeOnError);
});

@@ -34,3 +34,3 @@ }

'Should throw error when NODE_TAPE_NO_ONLY_TEST is passed via envs and there is an .only test',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
{ todo: expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {

@@ -45,3 +45,3 @@ tt.plan(3);

tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
tt.equal(err.code, expectedExitCodeOnError);
});

@@ -53,3 +53,3 @@ }

'Should override NODE_TAPE_NO_ONLY_TEST env if --no-only is passed from cli',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
{ todo: expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {

@@ -64,3 +64,3 @@ tt.plan(3);

tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
tt.equal(err.code, expectedExitCodeOnError);
});

@@ -67,0 +67,0 @@ }

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

var forEach = require('for-each');
var through = require('through');
var through = require('@ljharb/through');

@@ -9,0 +9,0 @@ tap.test('object results', function (assert) {

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

var tape = require('../');
var through = require('through');
var through = require('@ljharb/through');

@@ -8,0 +8,0 @@ tap.test('test.comment() in objectMode', function (assert) {

Sorry, the diff of this file is too big to display

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