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.5 to 0.1.6

28

lib/empower.js

@@ -46,3 +46,7 @@ /**

function empower (assert, options) {
var config;
var typeOfAssert = (typeof assert),
config;
if ((typeOfAssert !== 'object' && typeOfAssert !== 'function') || assert === null) {
throw new TypeError('empower argument should be a function or object.');
}
if (isEmpowered(assert)) {

@@ -52,3 +56,3 @@ return assert;

config = extend(defaultOptions(), (options || {}));
switch (typeof assert) {
switch (typeOfAssert) {
case 'function':

@@ -65,2 +69,5 @@ return empowerAssertFunction(assert, config);

function empowerAssertObject (assertObject, config) {
if (typeof assertObject.ok !== 'function') {
throw new TypeError('empower target object should be respond to \'ok\' method.');
}
var baseAssert = config.destructive ? assertObject.ok : bind(assertObject.ok, assertObject),

@@ -74,2 +81,5 @@ enhancement = enhance(baseAssert, config),

function empowerAssertFunction (assertFunction, config) {
if (config.destructive) {
throw new Error('cannot use destructive:true to function.');
}
var enhancement = enhance(assertFunction, config),

@@ -108,14 +118,8 @@ powerAssert = function powerAssert (context, message) {

function empoweredAssert (value, message) {
var context, powerAssertText;
if (value instanceof PowerAssertContext) {
var context = value.context,
callback,
powerAssertText;
context = value.context;
if (!context.result) {
if (typeof config.callback === 'function') {
callback = config.callback;
callback(context, message);
} else {
powerAssertText = config.formatter.format(context).join(config.lineSeparator);
baseAssert(context.result, message ? message + ' ' + powerAssertText : powerAssertText);
}
powerAssertText = config.formatter.format(context).join(config.lineSeparator);
baseAssert(context.result, message ? message + ' ' + powerAssertText : powerAssertText);
} else {

@@ -122,0 +126,0 @@ baseAssert(context.result, message);

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

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

"devDependencies": {
"espower": "~0.1.5",
"espower": "~0.1.6",
"esprima": "~1.0.4",
"escodegen": "~0.0.27",
"coffee-script-redux": "2.0.0-beta7",
"mocha": "1.12.1",
"grunt": "~0.4.1",
"grunt-mocha-test": "~0.6.3",
"grunt-mocha-test": "~0.7.0",
"grunt-contrib-jshint": "~0.6.4"

@@ -37,0 +36,0 @@ },

@@ -6,4 +6,3 @@ var empower = require('../lib/empower'),

baseAssert = require('assert'),
config = empower.defaultOptions(),
powerAssertTextLines = [],
assert = empower(baseAssert),
CoffeeScript = require('coffee-script-redux'),

@@ -24,12 +23,13 @@ extractBodyOfAssertionAsCode = require('../test_helper').extractBodyOfAssertionAsCode,

config.callback = function (context, message) {
powerAssertTextLines = config.formatter.format(context);
var expectPowerAssertMessage = function (body, expectedLines) {
try {
body();
baseAssert.fail('AssertionError should be thrown');
} catch (e) {
baseAssert.equal(e.message, expectedLines.join('\n'));
}
};
var assert = empower(baseAssert, config);
suite('CoffeeScriptRedux integration', function () {
setup(function () {
powerAssertTextLines.length = 0;
});

@@ -39,4 +39,5 @@ test('assert.ok dog.speak() == says', function () {

says = 'meow';
assert.ok(eval(espowerCoffee('assert.ok dog.speak() == says')));
baseAssert.deepEqual(powerAssertTextLines, [
expectPowerAssertMessage(function () {
assert.ok(eval(espowerCoffee('assert.ok dog.speak() == says')));
}, [
'# /path/to/bar_test.coffee:1',

@@ -55,4 +56,5 @@ '',

four = 4;
assert.ok(eval(espowerCoffee('assert.ok dog.age is four')));
baseAssert.deepEqual(powerAssertTextLines, [
expectPowerAssertMessage(function () {
assert.ok(eval(espowerCoffee('assert.ok dog.age is four')));
}, [
'# /path/to/bar_test.coffee:1',

@@ -73,4 +75,5 @@ '',

prop = 'birthday';
assert.ok(eval(espowerCoffee('assert.ok dog[prop].year is lastYear')));
baseAssert.deepEqual(powerAssertTextLines, [
expectPowerAssertMessage(function () {
assert.ok(eval(espowerCoffee('assert.ok dog[prop].year is lastYear')));
}, [
'# /path/to/bar_test.coffee:1',

@@ -77,0 +80,0 @@ '',

@@ -21,5 +21,5 @@ var empower = require('../lib/empower'),

function lineSeparatorTest (name, option, expectedSeparator) {
var baseAssert = require('assert'),
assert = empower(baseAssert, option);
test(name, function () {
var baseAssert = require('assert');
var assert = empower(baseAssert, option);
var falsyNum = 0;

@@ -47,52 +47,41 @@ try {

suite('assert object empowerment', function () {
test('destructive: false', function () {
var assertOk = function (actual, message) {
if (!actual) {
throw new Error('FakeAssert: assertion failed. ' + message);
}
};
var fakeAssertObject = {
ok: assertOk,
equal: function (actual, expected, message) {
this.ok(actual == expected, message);
},
strictEqual: function (actual, expected, message) {
this.ok(actual === expected, message);
}
};
var empoweredAssert = empower(fakeAssertObject, {destructive: false});
assert.ok(typeof empoweredAssert === 'object');
assert.ok(typeof empoweredAssert.ok === 'function');
assert.ok(typeof empoweredAssert._capt === 'function');
assert.ok(typeof empoweredAssert._expr === 'function');
assert.ok(typeof empoweredAssert.equal === 'function');
assert.ok(typeof empoweredAssert.strictEqual === 'function');
assert.notEqual(empoweredAssert, fakeAssertObject);
assert.notEqual(empoweredAssert.ok, fakeAssertObject.ok);
assert.equal(fakeAssertObject.ok, assertOk);
try {
function sharedTestsForEmpowerFunctionReturnValue () {
test('has ok method', function () {
assert.equal(typeof this.empoweredAssert.ok, 'function');
});
test('has _capt method', function () {
assert.equal(typeof this.empoweredAssert._capt, 'function');
});
test('has _expr method', function () {
assert.equal(typeof this.empoweredAssert._expr, 'function');
});
test('has equal method', function () {
assert.equal(typeof this.empoweredAssert.equal, 'function');
});
test('has strictEqual method', function () {
assert.equal(typeof this.empoweredAssert.strictEqual, 'function');
});
test('ok method works as assert.ok', function () {
var empoweredAssert = this.empoweredAssert;
assert.throws(function () {
empoweredAssert.ok(false, 'empoweredAssert.ok');
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.ok');
}
try {
}, /FakeAssert: assertion failed. empoweredAssert.ok/);
});
test('equal method works', function () {
var empoweredAssert = this.empoweredAssert;
assert.throws(function () {
empoweredAssert.equal(1, 'hoge', 'empoweredAssert.equal');
}, /FakeAssert: assertion failed. empoweredAssert.equal/);
});
test('strictEqual method works', function () {
var empoweredAssert = this.empoweredAssert;
assert.throws(function () {
empoweredAssert.strictEqual(1, '1', 'empoweredAssert.strictEqual');
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.strictEqual');
}
var empoweredAgain = empower(empoweredAssert, {destructive: false});
assert.equal(empoweredAgain, empoweredAssert, 'avoid empowering multiple times');
}, /FakeAssert: assertion failed. empoweredAssert.strictEqual/);
});
}
test('destructive: true', function () {
suite('assert object empowerment', function () {
setup(function () {
var assertOk = function (actual, message) {

@@ -112,29 +101,47 @@ if (!actual) {

};
this.fakeAssertObject = fakeAssertObject;
});
empower(fakeAssertObject, {destructive: true});
assert.ok(typeof fakeAssertObject === 'object');
assert.ok(typeof fakeAssertObject.ok === 'function');
assert.ok(typeof fakeAssertObject._capt === 'function');
assert.ok(typeof fakeAssertObject._expr === 'function');
assert.ok(typeof fakeAssertObject.equal === 'function');
assert.ok(typeof fakeAssertObject.strictEqual === 'function');
suite('destructive: false', function () {
setup(function () {
this.empoweredAssert = empower(this.fakeAssertObject, {destructive: false});
});
suite('returned assert', function () {
sharedTestsForEmpowerFunctionReturnValue();
test('is also an object', function () {
assert.ok(typeof this.empoweredAssert, 'object');
});
test('is not the same instance as target assert object', function () {
assert.notEqual(this.empoweredAssert, this.fakeAssertObject);
});
test('ok method is not refered to target.ok', function () {
assert.notEqual(this.empoweredAssert.ok, this.fakeAssertObject.ok);
});
});
test('avoid empowering multiple times', function () {
var empoweredAgain = empower(this.empoweredAssert, {destructive: false});
assert.equal(empoweredAgain, this.empoweredAssert);
});
});
assert.notEqual(fakeAssertObject.ok, assertOk);
try {
fakeAssertObject.ok(false, 'fakeAssertObject.ok');
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, 'FakeAssert: assertion failed. fakeAssertObject.ok');
}
try {
fakeAssertObject.strictEqual(1, '1', 'fakeAssertObject.strictEqual');
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, 'FakeAssert: assertion failed. fakeAssertObject.strictEqual');
}
var empoweredAgain = empower(fakeAssertObject, {destructive: true});
assert.equal(empoweredAgain, fakeAssertObject, 'avoid empowering multiple times');
suite('destructive: true', function () {
setup(function () {
this.empoweredAssert = empower(this.fakeAssertObject, {destructive: true});
});
suite('returned assert', function () {
sharedTestsForEmpowerFunctionReturnValue();
test('is also an object', function () {
assert.ok(typeof this.empoweredAssert, 'object');
});
test('is the same instance as target assert object', function () {
assert.equal(this.empoweredAssert, this.fakeAssertObject);
});
test('ok method is refered to target.ok', function () {
assert.equal(this.empoweredAssert.ok, this.fakeAssertObject.ok);
});
});
test('avoid empowering multiple times', function () {
var empoweredAgain = empower(this.fakeAssertObject, {destructive: true});
assert.equal(empoweredAgain, this.fakeAssertObject);
});
});

@@ -144,5 +151,4 @@ });

suite('assert function empowerment', function () {
test('destructive: false', function () {
setup(function () {
var assertOk = function (actual, message) {

@@ -160,31 +166,59 @@ if (!actual) {

};
this.fakeAssertFunction = assertOk;
});
var empoweredAssert = empower(assertOk, {destructive: false});
assert.ok(typeof empoweredAssert === 'function');
assert.ok(typeof empoweredAssert.ok === 'function');
assert.ok(typeof empoweredAssert._capt === 'function');
assert.ok(typeof empoweredAssert._expr === 'function');
assert.ok(typeof empoweredAssert.equal === 'function');
assert.ok(typeof empoweredAssert.strictEqual === 'function');
suite('destructive: false', function () {
setup(function () {
this.empoweredAssert = empower(this.fakeAssertFunction, {destructive: false});
});
suite('returned assert', function () {
sharedTestsForEmpowerFunctionReturnValue();
test('is also a function', function () {
assert.ok(typeof this.empoweredAssert, 'function');
});
test('is not the same instance as target assert function', function () {
assert.notEqual(this.empoweredAssert, this.fakeAssertFunction);
});
test('ok method is not refered to target.ok', function () {
assert.notEqual(this.empoweredAssert.ok, this.fakeAssertFunction.ok);
});
test('ok method is not refered to target assert function', function () {
assert.notEqual(this.empoweredAssert.ok, this.fakeAssertFunction.ok);
});
});
test('avoid empowering multiple times', function () {
var empoweredAgain = empower(this.empoweredAssert, {destructive: false});
assert.equal(empoweredAgain, this.empoweredAssert);
});
});
assert.notEqual(empoweredAssert, assertOk);
assert.notEqual(empoweredAssert.ok, assertOk);
test('does not support destructive:true', function () {
var func = this.fakeAssertFunction;
assert.throws(function () {
empower(func, {destructive: true});
}, 'cannot use destructive:true to function\.');
});
});
try {
empoweredAssert.ok(false, 'empoweredAssert.ok');
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.ok');
}
try {
empoweredAssert.strictEqual(1, '1', 'empoweredAssert.strictEqual');
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.strictEqual');
}
var empoweredAgain = empower(empoweredAssert, {destructive: false});
assert.equal(empoweredAgain, empoweredAssert, 'avoid empowering multiple times');
});
suite('empower argument preconditions', function () {
function argumentTest (name, arg, expectedMessage) {
expectedMessage = expectedMessage || 'empower argument should be a function or object.';
test(name, function () {
assert.throws(
function() {
empower(arg);
},
function(err) {
return ((err instanceof TypeError) && (expectedMessage === err.message));
},
"unexpected error"
);
});
}
argumentTest('cannot pass null', null);
argumentTest('cannot pass undefined', undefined);
argumentTest('cannot pass number', 3);
argumentTest('cannot pass string', 'hoge');
argumentTest('should respond to "ok"', {equal: function () { return false; }}, 'empower target object should be respond to \'ok\' method.');
});
var empower = require('../lib/empower'),
instrument = require('../test_helper').instrument,
baseAssert = require('assert'),
config = empower.defaultOptions(),
powerAssertTextLines = [];
config.callback = function (context, message) {
powerAssertTextLines = config.formatter.format(context);
};
var assert = empower(baseAssert, config);
assert = empower(baseAssert),
assertPowerAssertContextFormatting = function (body, expectedLines) {
try {
body();
baseAssert.fail('AssertionError should be thrown');
} catch (e) {
baseAssert.equal(e.message, expectedLines.join('\n'));
}
};
suite('power-assert-formatter', function () {
setup(function () {
powerAssertTextLines.length = 0;
});
test('Identifier with empty string', function () {
var falsyStr = '';
assert(eval(instrument('assert(falsyStr);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(falsyStr);')));
}, [
'# /path/to/some_test.js:1',

@@ -34,4 +34,5 @@ '',

var falsyStr = '';
assert(eval(instrument('return assert(falsyStr);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('return assert(falsyStr);')));
}, [
'# /path/to/some_test.js:1',

@@ -49,4 +50,5 @@ '',

var falsyNum = 0;
assert(eval(instrument('assert(falsyNum);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(falsyNum);')));
}, [
'# /path/to/some_test.js:1',

@@ -64,4 +66,5 @@ '',

var truth = true;
assert(eval(instrument('assert(!truth);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!truth);')));
}, [
'# /path/to/some_test.js:1',

@@ -80,4 +83,5 @@ '',

var some = '';
assert(eval(instrument('assert(!!some);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!!some);')));
}, [
'# /path/to/some_test.js:1',

@@ -96,4 +100,5 @@ '',

test('typeof operator: assert(typeof foo !== "undefined");', function () {
assert(eval(instrument('assert(typeof foo !== "undefined");')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(typeof foo !== "undefined");')));
}, [
'# /path/to/some_test.js:1',

@@ -111,4 +116,5 @@ '',

test('undefined property: assert({}.hoge === "xxx");', function () {
assert(eval(instrument('assert({}.hoge === "xxx");')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert({}.hoge === "xxx");')));
}, [
'# /path/to/some_test.js:1',

@@ -131,4 +137,5 @@ '',

};
assert(eval(instrument('assert((delete foo.bar) === false);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((delete foo.bar) === false);')));
}, [
'# /path/to/some_test.js:1',

@@ -147,4 +154,5 @@ '',

test('assert((delete nonexistent) === false);', function () {
assert(eval(instrument('assert((delete nonexistent) === false);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((delete nonexistent) === false);')));
}, [
'# /path/to/some_test.js:1',

@@ -163,4 +171,5 @@ '',

piyo = 8;
assert(eval(instrument('assert(fuga === piyo);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(fuga === piyo);')));
}, [
'# /path/to/some_test.js:1',

@@ -181,4 +190,5 @@ '',

piyo = 'foo';
assert(eval(instrument('assert(fuga !== piyo);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(fuga !== piyo);')));
}, [
'# /path/to/some_test.js:1',

@@ -198,4 +208,5 @@ '',

var fuga = 4;
assert(eval(instrument('assert(fuga !== 4);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(fuga !== 4);')));
}, [
'# /path/to/some_test.js:1',

@@ -212,4 +223,5 @@ '',

test('assert(4 !== 4);', function () {
assert(eval(instrument('assert(4 !== 4);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(4 !== 4);')));
}, [
'# /path/to/some_test.js:1',

@@ -228,4 +240,5 @@ '',

var ary2 = ['aaa', 'bbb', 'ccc'];
assert(eval(instrument('assert(ary1.length === ary2.length);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(ary1.length === ary2.length);')));
}, [
'# /path/to/some_test.js:1',

@@ -246,4 +259,5 @@ '',

var actual = 16;
assert(eval(instrument('assert(5 < actual && actual < 13);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(5 < actual && actual < 13);')));
}, [
'# /path/to/some_test.js:1',

@@ -263,4 +277,5 @@ '',

var actual = 10;
assert(eval(instrument('assert.ok(actual < 5 || 13 < actual);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert.ok(actual < 5 || 13 < actual);')));
}, [
'# /path/to/some_test.js:1',

@@ -280,4 +295,5 @@ '',

var actual = 5;
assert(eval(instrument('assert(2 > actual && actual < 13);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(2 > actual && actual < 13);')));
}, [
'# /path/to/some_test.js:1',

@@ -300,4 +316,5 @@ '',

};
assert(eval(instrument('assert(foo.bar.baz);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo.bar.baz);')));
}, [
'# /path/to/some_test.js:1',

@@ -321,4 +338,5 @@ '',

};
assert(eval(instrument('assert(foo["bar"].baz);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo["bar"].baz);')));
}, [
'# /path/to/some_test.js:1',

@@ -343,4 +361,5 @@ '',

};
assert(eval(instrument('assert(foo[propName].baz);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo[propName].baz);')));
}, [
'# /path/to/some_test.js:1',

@@ -368,4 +387,5 @@ '',

};
assert(eval(instrument('assert(foo[propName]["baz"][keys()[0]]);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(foo[propName]["baz"][keys()[0]]);')));
}, [
'# /path/to/some_test.js:1',

@@ -388,4 +408,5 @@ '',

var func = function () { return false; };
assert(eval(instrument('assert(func());')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(func());')));
}, [
'# /path/to/some_test.js:1',

@@ -407,4 +428,5 @@ '',

};
assert(eval(instrument('assert(obj.age());')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(obj.age());')));
}, [
'# /path/to/some_test.js:1',

@@ -425,4 +447,5 @@ '',

var positiveInt = 50;
assert(eval(instrument('assert(isFalsy(positiveInt));')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(isFalsy(positiveInt));')));
}, [
'# /path/to/some_test.js:1',

@@ -447,4 +470,5 @@ '',

var one = 1, two = 2, three = 3, seven = 7, ten = 10;
assert(eval(instrument('assert(sum(one, two, three) === seven);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(sum(one, two, three) === seven);')));
}, [
'# /path/to/some_test.js:1',

@@ -461,3 +485,3 @@ '',

test('CallExpression with CallExpressions as arguments: assert(sum(sum(one, two), three) === sum(sum(two, three), seven));', function () {
test('nexted CallExpression: assert(sum(sum(one, two), three) === sum(sum(two, three), seven));', function () {
var sum = function () {

@@ -471,4 +495,5 @@ var result = 0;

var one = 1, two = 2, three = 3, seven = 7, ten = 10;
assert(eval(instrument('assert(sum(sum(one, two), three) === sum(sum(two, three), seven));')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(sum(sum(one, two), three) === sum(sum(two, three), seven));')));
}, [
'# /path/to/some_test.js:1',

@@ -498,4 +523,5 @@ '',

var one = 1, two = 2, three = 3, seven = 7, ten = 10;
assert(eval(instrument('assert(math.calc.sum(one, two, three) === seven);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(math.calc.sum(one, two, three) === seven);')));
}, [
'# /path/to/some_test.js:1',

@@ -515,4 +541,5 @@ '',

var one = 1, two = 2, three = 3, seven = 7, ten = 10;
assert(eval(instrument('assert((three * (seven * ten)) === three);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((three * (seven * ten)) === three);')));
}, [
'# /path/to/some_test.js:1',

@@ -534,4 +561,5 @@ '',

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

@@ -552,4 +580,5 @@ '',

var anotherLongString = 'yet another loooooooooooooooooooooooooooooooooooooooooooooooooooong message';
assert(eval(instrument('assert(longString === anotherLongString);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(longString === anotherLongString);')));
}, [
'# /path/to/some_test.js:1',

@@ -573,4 +602,5 @@ '',

};
assert(eval(instrument('assert(!concat(fuga, piyo));')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!concat(fuga, piyo));')));
}, [
'# /path/to/some_test.js:1',

@@ -596,4 +626,5 @@ '',

};
assert(eval(instrument('assert(!concat(fuga, piyo));')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!concat(fuga, piyo));')));
}, [
'# /path/to/some_test.js:1',

@@ -617,4 +648,5 @@ '',

cyclic.push('baz');
assert(eval(instrument('assert.ok(cyclic[two] === cyclic);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert.ok(cyclic[two] === cyclic);')));
}, [
'# /path/to/some_test.js:1',

@@ -635,4 +667,5 @@ '',

var twoStr = '2';
assert(eval(instrument('assert(typeof + twoStr === -twoStr);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(typeof + twoStr === -twoStr);')));
}, [
'# /path/to/some_test.js:1',

@@ -653,4 +686,5 @@ '',

var minusOne = -1;
assert(eval(instrument('assert(minusOne += 1);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(minusOne += 1);')));
}, [
'# /path/to/some_test.js:1',

@@ -668,4 +702,5 @@ '',

var dog = { age: 2 }, four = 4;
assert(eval(instrument('assert((dog.age += 1) === four);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert((dog.age += 1) === four);')));
}, [
'# /path/to/some_test.js:1',

@@ -684,4 +719,5 @@ '',

var foo = 'hoge', bar = 'fuga', four = 4;
assert(eval(instrument('assert([foo, bar].length === four);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert([foo, bar].length === four);')));
}, [
'# /path/to/some_test.js:1',

@@ -702,4 +738,5 @@ '',

var foo = {bar: 'fuga'}, baz = function (arg) { return null; }, moo = 'boo', fourStr = '4';
assert(eval(instrument('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");')));
}, [
'# /path/to/some_test.js:1',

@@ -720,4 +757,5 @@ '',

var minusOne = -1;
assert(eval(instrument('assert(++minusOne);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(++minusOne);')));
}, [
'# /path/to/some_test.js:1',

@@ -735,4 +773,5 @@ '',

var zero = 0;
assert(eval(instrument('assert(zero--);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(zero--);')));
}, [
'# /path/to/some_test.js:1',

@@ -750,4 +789,5 @@ '',

var truthy = 'truthy', falsy = 0, anotherFalsy = null;
assert(eval(instrument('assert(truthy ? falsy : anotherFalsy);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(truthy ? falsy : anotherFalsy);')));
}, [
'# /path/to/some_test.js:1',

@@ -765,4 +805,5 @@ '',

var truthy = 'truthy', falsy = 0, anotherFalsy = null;
assert(eval(instrument('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);')));
}, [
'# /path/to/some_test.js:1',

@@ -780,4 +821,5 @@ '',

var str = 'ok';
assert(eval(instrument('assert(/^not/.exec(str));')));
baseAssert.deepEqual(powerAssertTextLines, [
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(/^not/.exec(str));')));
}, [
'# /path/to/some_test.js:1',

@@ -792,2 +834,94 @@ '',

test('ObjectExpression: assert(!({foo: bar, hoge: fuga}));', function () {
var bar = 'toto', fuga = 100;
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!({foo: bar, hoge: fuga}));')));
}, [
'# /path/to/some_test.js:1',
'',
'assert(!({foo: bar, hoge: fuga}));',
' | | | ',
' false "toto" 100 ',
''
]);
});
test('complex ObjectExpression: assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));', function () {
var bar = { baz: 'BAZ' }, first = 'Brendan', last = 'Eich',
nameOf = function (person) { return person.firstName + ' ' + person.lastName; };
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));')));
}, [
'# /path/to/some_test.js:1',
'',
'assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));',
' | | | | | | ',
' | | "BAZ" "Brendan Eich" "Brendan" "Eich" ',
' false {"baz":"BAZ"} ',
''
]);
});
test('NewExpression: assert(!(new Array(foo, bar, baz)));', function () {
var foo = 'foo', bar = 'bar', baz = 'baz';
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(!(new Array(foo, bar, baz)));')));
}, [
'# /path/to/some_test.js:1',
'',
'assert(!(new Array(foo, bar, baz)));',
' | | | | | ',
' | | | | "baz" ',
' | | | "bar" ',
' | | "foo" ',
' | ["foo","bar","baz"] ',
' false ',
''
]);
});
test('NewExpression: assert(baz === new Array(foo, bar, baz)[1]);', function () {
var foo = 'foo', bar = 'bar', baz = 'baz';
assertPowerAssertContextFormatting(function () {
assert(eval(instrument('assert(baz === new Array(foo, bar, baz)[1]);')));
}, [
'# /path/to/some_test.js:1',
'',
'assert(baz === new Array(foo, bar, baz)[1]);',
' | | | | | | | ',
' | | | | | | "bar"',
' | | | | | "baz" ',
' | | | | "bar" ',
' | | | "foo" ',
' | | ["foo","bar","baz"] ',
' | false ',
' "baz" ',
''
]);
});
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));')));
}, [
'# /path/to/some_test.js:1',
'',
'assert(baz === (function (a, b) { return a + b; })(foo, bar));',
' | | | | | ',
' | | | | "bar" ',
' | | "foobar" "foo" ',
' | false ',
' "baz" ',
''
]);
});
});
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