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

empower

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

empower - npm Package Compare versions

Comparing version 0.1.6 to 0.2.0

8

Gruntfile.js

@@ -27,6 +27,12 @@ module.exports = function(grunt) {

ui: 'tdd',
reporter: 'spec'
reporter: 'dot'
},
src: ['test/**/*.js']
}
},
watch: {
unit: {
files: ['test/**/*.js', 'lib/**/*.js'],
tasks: ['test']
}
}

@@ -33,0 +39,0 @@ });

116

lib/empower.js

@@ -34,3 +34,16 @@ /**

formatter: defaultFormatter,
lineSeparator: '\n'
lineSeparator: '\n',
targetMethods: {
oneArg: [
'ok'
],
twoArgs: [
'equal',
'notEqual',
'strictEqual',
'notStrictEqual',
'deepEqual',
'notDeepEqual'
]
}
};

@@ -67,2 +80,7 @@ }

function isEmpowered (assertObjectOrFunction) {
return (typeof assertObjectOrFunction._capt === 'function') && (typeof assertObjectOrFunction._expr === 'function');
}
function empowerAssertObject (assertObject, config) {

@@ -72,4 +90,3 @@ if (typeof assertObject.ok !== 'function') {

}
var baseAssert = config.destructive ? assertObject.ok : bind(assertObject.ok, assertObject),
enhancement = enhance(baseAssert, config),
var enhancement = enhance(assertObject, config),
target = config.destructive ? assertObject : Object.create(assertObject);

@@ -93,14 +110,6 @@ return extend(target, enhancement);

function isEmpowered (assertObjectOrFunction) {
return (typeof assertObjectOrFunction._capt === 'function') && (typeof assertObjectOrFunction._expr === 'function');
}
function enhance (target, config) {
var events = [],
enhancement = {};
function enhance (baseAssert, config) {
var events = [];
function PowerAssertContext (arg) {
this.context = arg;
}
function _capt (value, kind, location) {

@@ -111,27 +120,68 @@ events.push({value: value, kind: kind, location: location});

function _expr (result, location, content) {
function _expr (value, location, content) {
var captured = events;
events = [];
return new PowerAssertContext({result: result, location: location, content: content, events: captured});
return { powerAssertContext: {value: value, location: location, content: content, events: captured} };
}
function empoweredAssert (value, message) {
var context, powerAssertText;
if (value instanceof PowerAssertContext) {
context = value.context;
if (!context.result) {
powerAssertText = config.formatter.format(context).join(config.lineSeparator);
baseAssert(context.result, message ? message + ' ' + powerAssertText : powerAssertText);
config.targetMethods.oneArg.forEach(function (methodName) {
if (typeof target[methodName] === 'function') {
enhancement[methodName] = decorateOneArg(bind(target[methodName], target), config);
}
});
config.targetMethods.twoArgs.forEach(function (methodName) {
if (typeof target[methodName] === 'function') {
enhancement[methodName] = decorateTwoArgs(bind(target[methodName], target), config);
}
});
enhancement._capt = _capt;
enhancement._expr = _expr;
return enhancement;
}
function isEspoweredValue (value) {
return (typeof value !== 'undefined') && (typeof value.powerAssertContext !== 'undefined');
}
function decorateOneArg (baseAssert, config) {
return function (value, message) {
var context;
if (! isEspoweredValue(value)) {
return baseAssert(value, message);
}
context = value.powerAssertContext;
return baseAssert(context.value, buildPowerAssertText(message, context, config));
};
}
function decorateTwoArgs (baseAssert, config) {
return function (arg1, arg2, message) {
var context, val1, val2;
if (!(isEspoweredValue(arg1) || isEspoweredValue(arg2))) {
return baseAssert(arg1, arg2, message);
}
if (isEspoweredValue(arg1)) {
context = extend({}, arg1.powerAssertContext);
val1 = arg1.powerAssertContext.value;
} else {
val1 = arg1;
}
if (isEspoweredValue(arg2)) {
if (isEspoweredValue(arg1)) {
context.events = context.events.concat(arg2.powerAssertContext.events);
} else {
baseAssert(context.result, message);
context = extend({}, arg2.powerAssertContext);
}
val2 = arg2.powerAssertContext.value;
} else {
baseAssert(value, message);
val2 = arg2;
}
}
return {
ok: empoweredAssert,
_capt: _capt,
_expr: _expr
return baseAssert(val1, val2, buildPowerAssertText(message, context, config));
};

@@ -141,2 +191,8 @@ }

function buildPowerAssertText (message, context, config) {
var powerAssertText = config.formatter.format(context).join(config.lineSeparator);
return message ? message + ' ' + powerAssertText : powerAssertText;
}
// borrowed from qunit.js

@@ -143,0 +199,0 @@ function extend (a, b) {

{
"name": "empower",
"description": "Power Assert feature enhancer for assert function/object",
"version": "0.1.6",
"version": "0.2.0",
"keywords": [

@@ -28,9 +28,10 @@ "test",

"devDependencies": {
"espower": "~0.1.6",
"espower": "~0.2.0",
"esprima": "~1.0.4",
"escodegen": "~0.0.27",
"escodegen": "~0.0.28",
"coffee-script-redux": "2.0.0-beta7",
"grunt": "~0.4.1",
"grunt-mocha-test": "~0.7.0",
"grunt-contrib-jshint": "~0.6.4"
"grunt": "~0.4.2",
"grunt-mocha-test": "~0.8.0",
"grunt-contrib-jshint": "~0.7.1",
"grunt-contrib-watch": "~0.5.3"
},

@@ -37,0 +38,0 @@ "licenses": [

@@ -19,3 +19,3 @@ empower

Please note that `empower` is an alpha version product. Pull-requests, issue reports and patches are always welcomed. See [power-assert](http://github.com/twada/power-assert) project for more documentation.
Please note that `empower` is a beta version product. Pull-requests, issue reports and patches are always welcomed. See [power-assert](http://github.com/twada/power-assert) project for more documentation.

@@ -22,0 +22,0 @@

var espower = require('espower'),
esprima = require('esprima'),
escodegen = require('escodegen'),
instrument;
escodegen = require('escodegen');

@@ -15,4 +14,2 @@ function extractBodyFrom (source) {

expression = node.expression;
} else if (node.type === 'ReturnStatement') {
expression = node.argument;
}

@@ -22,15 +19,15 @@ return escodegen.generate(expression.arguments[0], {format: {compact: true}});

instrument = function () {
return function (line, options) {
options = options || {destructive: false, source: line, path: '/path/to/some_test.js', powerAssertVariableName: 'assert'};
var tree = extractBodyFrom(line),
result = espower(tree, options),
instrumentedCode = extractBodyOfAssertionAsCode(result);
return instrumentedCode;
};
}();
function applyEspower (line, options) {
options = options || {destructive: false, source: line, path: '/path/to/some_test.js', powerAssertVariableName: 'assert'};
var tree = extractBodyFrom(line);
return espower(tree, options);
}
function weave (line, options) {
return escodegen.generate(applyEspower(line, options), {format: {compact: true}});
}
module.exports = {
instrument: instrument,
weave: weave,
extractBodyOfAssertionAsCode: extractBodyOfAssertionAsCode
};
var empower = require('../lib/empower'),
instrument = require('../test_helper').instrument,
weave = require('../test_helper').weave,
assert = require('assert');

@@ -16,2 +16,20 @@

});
suite('targetMethods', function () {
setup (function () {
this.targetMethods = empower.defaultOptions().targetMethods;
});
test('oneArg', function () {
assert.deepEqual(this.targetMethods.oneArg, ['ok']);
});
test('twoArgs', function () {
assert.deepEqual(this.targetMethods.twoArgs, [
'equal',
'notEqual',
'strictEqual',
'notStrictEqual',
'deepEqual',
'notDeepEqual'
]);
});
});
});

@@ -27,3 +45,3 @@

try {
assert(eval(instrument('assert(falsyNum);')));
eval(weave('assert(falsyNum);'));
} catch (e) {

@@ -82,2 +100,7 @@ baseAssert.equal(e.message, [

});
test('preserve return value if target assertion method returns something', function () {
var empoweredAssert = this.empoweredAssert,
ret = empoweredAssert.equal(1, '1');
empoweredAssert.strictEqual(ret, true);
});
}

@@ -97,2 +120,3 @@

this.ok(actual == expected, message);
return true;
},

@@ -108,3 +132,15 @@ strictEqual: function (actual, expected, message) {

setup(function () {
this.empoweredAssert = empower(this.fakeAssertObject, {destructive: false});
this.options = {
destructive: false,
targetMethods: {
oneArg: [
'ok'
],
twoArgs: [
'equal',
'strictEqual'
]
}
};
this.empoweredAssert = empower(this.fakeAssertObject, this.options);
});

@@ -124,3 +160,3 @@ suite('returned assert', function () {

test('avoid empowering multiple times', function () {
var empoweredAgain = empower(this.empoweredAssert, {destructive: false});
var empoweredAgain = empower(this.empoweredAssert, this.options);
assert.equal(empoweredAgain, this.empoweredAssert);

@@ -132,3 +168,15 @@ });

setup(function () {
this.empoweredAssert = empower(this.fakeAssertObject, {destructive: true});
this.options = {
destructive: true,
targetMethods: {
oneArg: [
'ok'
],
twoArgs: [
'equal',
'strictEqual'
]
}
};
this.empoweredAssert = empower(this.fakeAssertObject, this.options);
});

@@ -148,3 +196,3 @@ suite('returned assert', function () {

test('avoid empowering multiple times', function () {
var empoweredAgain = empower(this.fakeAssertObject, {destructive: true});
var empoweredAgain = empower(this.fakeAssertObject, this.options);
assert.equal(empoweredAgain, this.fakeAssertObject);

@@ -166,2 +214,3 @@ });

this.ok(actual == expected, message);
return true;
};

@@ -176,3 +225,15 @@ assertOk.strictEqual = function (actual, expected, message) {

setup(function () {
this.empoweredAssert = empower(this.fakeAssertFunction, {destructive: false});
this.options = {
destructive: false,
targetMethods: {
oneArg: [
'ok'
],
twoArgs: [
'equal',
'strictEqual'
]
}
};
this.empoweredAssert = empower(this.fakeAssertFunction, this.options);
});

@@ -195,3 +256,3 @@ suite('returned assert', function () {

test('avoid empowering multiple times', function () {
var empoweredAgain = empower(this.empoweredAssert, {destructive: false});
var empoweredAgain = empower(this.empoweredAssert, this.options);
assert.equal(empoweredAgain, this.empoweredAssert);

@@ -198,0 +259,0 @@ });

var empower = require('../lib/empower'),
instrument = require('../test_helper').instrument,
weave = require('../test_helper').weave,
baseAssert = require('assert'),

@@ -20,3 +20,3 @@ assert = empower(baseAssert),

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(falsyStr);')));
eval(weave('assert(falsyStr);'));
}, [

@@ -33,21 +33,6 @@ '# /path/to/some_test.js:1',

test('ReturnStatement', function () {
var falsyStr = '';
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('return assert(falsyStr);')));
}, [
'# /path/to/some_test.js:1',
'',
'return assert(falsyStr);',
' | ',
' "" ',
''
]);
});
test('Identifier with falsy number', function () {
var falsyNum = 0;
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(falsyNum);')));
eval(weave('assert(falsyNum);'));
}, [

@@ -67,3 +52,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!truth);')));
eval(weave('assert(!truth);'));
}, [

@@ -84,3 +69,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!!some);')));
eval(weave('assert(!!some);'));
}, [

@@ -101,3 +86,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(typeof foo !== "undefined");')));
eval(weave('assert(typeof foo !== "undefined");'));
}, [

@@ -117,3 +102,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert({}.hoge === "xxx");')));
eval(weave('assert({}.hoge === "xxx");'));
}, [

@@ -138,3 +123,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((delete foo.bar) === false);')));
eval(weave('assert((delete foo.bar) === false);'));
}, [

@@ -155,3 +140,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((delete nonexistent) === false);')));
eval(weave('assert((delete nonexistent) === false);'));
}, [

@@ -172,3 +157,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(fuga === piyo);')));
eval(weave('assert(fuga === piyo);'));
}, [

@@ -191,3 +176,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(fuga !== piyo);')));
eval(weave('assert(fuga !== piyo);'));
}, [

@@ -209,3 +194,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(fuga !== 4);')));
eval(weave('assert(fuga !== 4);'));
}, [

@@ -224,3 +209,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(4 !== 4);')));
eval(weave('assert(4 !== 4);'));
}, [

@@ -241,3 +226,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(ary1.length === ary2.length);')));
eval(weave('assert(ary1.length === ary2.length);'));
}, [

@@ -260,3 +245,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(5 < actual && actual < 13);')));
eval(weave('assert(5 < actual && actual < 13);'));
}, [

@@ -278,3 +263,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert.ok(actual < 5 || 13 < actual);')));
eval(weave('assert.ok(actual < 5 || 13 < actual);'));
}, [

@@ -296,3 +281,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(2 > actual && actual < 13);')));
eval(weave('assert(2 > actual && actual < 13);'));
}, [

@@ -317,3 +302,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo.bar.baz);')));
eval(weave('assert(foo.bar.baz);'));
}, [

@@ -339,3 +324,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo["bar"].baz);')));
eval(weave('assert(foo["bar"].baz);'));
}, [

@@ -362,3 +347,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo[propName].baz);')));
eval(weave('assert(foo[propName].baz);'));
}, [

@@ -388,3 +373,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo[propName]["baz"][keys()[0]]);')));
eval(weave('assert(foo[propName]["baz"][keys()[0]]);'));
}, [

@@ -409,3 +394,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(func());')));
eval(weave('assert(func());'));
}, [

@@ -429,3 +414,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(obj.age());')));
eval(weave('assert(obj.age());'));
}, [

@@ -448,3 +433,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(isFalsy(positiveInt));')));
eval(weave('assert(isFalsy(positiveInt));'));
}, [

@@ -471,3 +456,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(sum(one, two, three) === seven);')));
eval(weave('assert(sum(one, two, three) === seven);'));
}, [

@@ -495,3 +480,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(sum(sum(one, two), three) === sum(sum(two, three), seven));')));
eval(weave('assert(sum(sum(one, two), three) === sum(sum(two, three), seven));'));
}, [

@@ -523,3 +508,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(math.calc.sum(one, two, three) === seven);')));
eval(weave('assert(math.calc.sum(one, two, three) === seven);'));
}, [

@@ -541,3 +526,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((three * (seven * ten)) === three);')));
eval(weave('assert((three * (seven * ten)) === three);'));
}, [

@@ -561,5 +546,5 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert.ok(hoge === fuga, "comment");')));
eval(weave('assert.ok(hoge === fuga, "comment");'));
}, [
'# /path/to/some_test.js:1',
'comment # /path/to/some_test.js:1',
'',

@@ -580,3 +565,3 @@ 'assert.ok(hoge === fuga, "comment");',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(longString === anotherLongString);')));
eval(weave('assert(longString === anotherLongString);'));
}, [

@@ -602,3 +587,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!concat(fuga, piyo));')));
eval(weave('assert(!concat(fuga, piyo));'));
}, [

@@ -626,3 +611,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!concat(fuga, piyo));')));
eval(weave('assert(!concat(fuga, piyo));'));
}, [

@@ -648,3 +633,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert.ok(cyclic[two] === cyclic);')));
eval(weave('assert.ok(cyclic[two] === cyclic);'));
}, [

@@ -667,3 +652,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(typeof + twoStr === -twoStr);')));
eval(weave('assert(typeof + twoStr === -twoStr);'));
}, [

@@ -686,3 +671,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(minusOne += 1);')));
eval(weave('assert(minusOne += 1);'));
}, [

@@ -702,3 +687,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((dog.age += 1) === four);')));
eval(weave('assert((dog.age += 1) === four);'));
}, [

@@ -719,3 +704,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert([foo, bar].length === four);')));
eval(weave('assert([foo, bar].length === four);'));
}, [

@@ -738,3 +723,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");')));
eval(weave('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");'));
}, [

@@ -757,3 +742,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(++minusOne);')));
eval(weave('assert(++minusOne);'));
}, [

@@ -773,3 +758,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(zero--);')));
eval(weave('assert(zero--);'));
}, [

@@ -789,3 +774,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(truthy ? falsy : anotherFalsy);')));
eval(weave('assert(truthy ? falsy : anotherFalsy);'));
}, [

@@ -805,3 +790,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);')));
eval(weave('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);'));
}, [

@@ -821,3 +806,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(/^not/.exec(str));')));
eval(weave('assert(/^not/.exec(str));'));
}, [

@@ -838,3 +823,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!({foo: bar, hoge: fuga}));')));
eval(weave('assert(!({foo: bar, hoge: fuga}));'));
}, [

@@ -855,3 +840,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));')));
eval(weave('assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));'));
}, [

@@ -872,3 +857,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!(new Array(foo, bar, baz)));')));
eval(weave('assert(!(new Array(foo, bar, baz)));'));
}, [

@@ -892,3 +877,3 @@ '# /path/to/some_test.js:1',

assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(baz === new Array(foo, bar, baz)[1]);')));
eval(weave('assert(baz === new Array(foo, bar, baz)[1]);'));
}, [

@@ -911,7 +896,6 @@ '# /path/to/some_test.js:1',

test('FunctionExpression will not be instrumented: assert(baz === (function (a, b) { return a + b; })(foo, bar));', function () {
var foo = 'foo', bar = 'bar', baz = 'baz';
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(baz === (function (a, b) { return a + b; })(foo, bar));')));
eval(weave('assert(baz === (function (a, b) { return a + b; })(foo, bar));'));
}, [

@@ -930,2 +914,119 @@ '# /path/to/some_test.js:1',

test('equal with Literal and Identifier: assert.equal(1, minusOne);', function () {
var minusOne = -1;
assertPowerAssertContextFormatting(function () {
eval(weave('assert.equal(1, minusOne)'));
}, [
'# /path/to/some_test.js:1',
'',
'assert.equal(1, minusOne)',
' | ',
' -1 ',
''
]);
});
test('equal with UpdateExpression and Literal: assert.equal(++minusOne, 1);', function () {
var minusOne = -1;
assertPowerAssertContextFormatting(function () {
eval(weave('assert.equal(++minusOne, 1)'));
}, [
'# /path/to/some_test.js:1',
'',
'assert.equal(++minusOne, 1)',
' | ',
' 0 ',
''
]);
});
test('notEqual with ConditionalExpression and AssignmentExpression: assert.notEqual(truthy ? fiveInStr : tenInStr, four += 1);', function () {
var truthy = 3, fiveInStr = '5', tenInStr = '10', four = 4;
assertPowerAssertContextFormatting(function () {
eval(weave('assert.notEqual(truthy ? fiveInStr : tenInStr, four += 1)'));
}, [
'# /path/to/some_test.js:1',
'',
'assert.notEqual(truthy ? fiveInStr : tenInStr, four += 1)',
' | | | ',
' 3 "5" 5 ',
''
]);
});
test('strictEqual with CallExpression and BinaryExpression, Identifier: assert.strictEqual(obj.truthy(), three == threeInStr);', function () {
var obj = { truthy: function () { return 'true'; }}, three = 3, threeInStr = '3';
assertPowerAssertContextFormatting(function () {
eval(weave('assert.strictEqual(obj.truthy(), three == threeInStr);'));
}, [
'# /path/to/some_test.js:1',
'',
'assert.strictEqual(obj.truthy(), three == threeInStr);',
' | | | | | ',
' | | | | "3" ',
' {} "true" 3 true ',
''
]);
});
test('notStrictEqual with MemberExpression and UnaryExpression: assert.notStrictEqual(typeof undefinedVar, types.undef);', function () {
var types = { undef: 'undefined' };
assertPowerAssertContextFormatting(function () {
eval(weave('assert.notStrictEqual(typeof undefinedVar, types.undef)'));
}, [
'# /path/to/some_test.js:1',
'',
'assert.notStrictEqual(typeof undefinedVar, types.undef)',
' | | | ',
' | | "undefined"',
' "undefined" {"undef":"undefined"}',
''
]);
});
test('deepEqual with LogicalExpression and ObjectExpression: assert.deepEqual(alice || bob, {name: kenName, age: four});', function () {
var alice = {name: 'alice', age: 3}, bob = {name: 'bob', age: 5}, kenName = 'ken', four = 4;
assertPowerAssertContextFormatting(function () {
eval(weave('assert.deepEqual(alice || bob, {name: kenName, age: four});'));
}, [
'# /path/to/some_test.js:1',
'',
'assert.deepEqual(alice || bob, {name: kenName, age: four});',
' | | | | ',
' | | "ken" 4 ',
' | {"name":"alice","age":3} ',
' {"name":"alice","age":3} ',
''
]);
});
test('notDeepEqual with ArrayExpression and NewExpression: assert.notDeepEqual([foo, bar, baz], new Array(foo, bar, baz));', function () {
var foo = 'foo', bar = ['toto', 'tata'], baz = {name: 'hoge'};
assertPowerAssertContextFormatting(function () {
eval(weave('assert.notDeepEqual([foo, bar, baz], new Array(foo, bar, baz));'));
}, [
'# /path/to/some_test.js:1',
'',
'assert.notDeepEqual([foo, bar, baz], new Array(foo, bar, baz));',
' | | | | | | | ',
' | | | | | | {"name":"hoge"}',
' | | | | | ["toto","tata"]',
' | | | | "foo" ',
' | | | ["foo",["toto","tata"],{"name":"hoge"}]',
' | | {"name":"hoge"} ',
' | ["toto","tata"] ',
' "foo" ',
''
]);
});
});
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