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.2.1 to 0.3.0

coverage/blanket.js

2

bower.json
{
"name": "empower",
"version": "0.2.1",
"version": "0.3.0",
"main": [

@@ -5,0 +5,0 @@ "lib/empower.js",

module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
(function () {
var taskName;
for(taskName in pkg.devDependencies) {
if(taskName.substring(0, 6) === 'grunt-') {
grunt.loadNpmTasks(taskName);
}
}
})();
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: pkg,
bump: {
options: {
files: ['package.json', 'bower.json'],
updateConfigs: ['pkg'],
commit: true,
commitMessage: '%VERSION%',
commitFiles: ['package.json', 'bower.json'], // '-a' for all files
createTag: true,
tagName: 'v%VERSION%',
tagMessage: '%VERSION%',
push: false,
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d' // options to use with '$ git describe'
}
},
jshint: {

@@ -30,2 +38,12 @@ files: [

src: ['test/**/*.js']
},
coverage: {
options: {
ui: 'tdd',
reporter: 'mocha-lcov-reporter',
require: 'coverage/blanket',
quiet: true,
captureFile: 'coverage.lcov'
},
src: ['test/**/*.js']
}

@@ -42,2 +60,3 @@ },

grunt.registerTask('test', ['jshint', 'mochaTest:unit']);
grunt.registerTask('coverage', ['mochaTest:coverage']);
};

@@ -20,9 +20,9 @@ /**

if (typeof define === 'function' && define.amd) {
define(['./power-assert-formatter'], factory);
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('./power-assert-formatter'));
module.exports = factory();
} else {
root.empower = factory(root.powerAssertFormatter);
root.empower = factory();
}
}(this, function (defaultFormatter) {
}(this, function () {
'use strict';

@@ -34,4 +34,2 @@

destructive: false,
formatter: defaultFormatter,
lineSeparator: '\n',
targetMethods: {

@@ -57,6 +55,7 @@ oneArg: [

* @param assert target assert function or object to enhance
* @param formatter power assert format function
* @param options enhancement options
* @return enhanced assert function/object
*/
function empower (assert, options) {
function empower (assert, formatter, options) {
var typeOfAssert = (typeof assert),

@@ -73,5 +72,5 @@ config;

case 'function':
return empowerAssertFunction(assert, config);
return empowerAssertFunction(assert, formatter, config);
case 'object':
return empowerAssertObject(assert, config);
return empowerAssertObject(assert, formatter, config);
default:

@@ -88,7 +87,7 @@ throw new Error('Cannot be here');

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

@@ -99,7 +98,7 @@ return extend(target, enhancement);

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

@@ -113,3 +112,3 @@ enhancement.ok(context, message);

function enhance (target, config) {
function enhance (target, formatter, config) {
var events = [],

@@ -131,3 +130,3 @@ enhancement = {};

if (typeof target[methodName] === 'function') {
enhancement[methodName] = decorateOneArg(bind(target[methodName], target), config);
enhancement[methodName] = decorateOneArg(target[methodName].bind(target), formatter);
}

@@ -137,3 +136,3 @@ });

if (typeof target[methodName] === 'function') {
enhancement[methodName] = decorateTwoArgs(bind(target[methodName], target), config);
enhancement[methodName] = decorateTwoArgs(target[methodName].bind(target), formatter);
}

@@ -153,3 +152,3 @@ });

function decorateOneArg (baseAssert, config) {
function decorateOneArg (baseAssert, formatter) {
return function (value, message) {

@@ -161,3 +160,3 @@ var context;

context = value.powerAssertContext;
return baseAssert(context.value, buildPowerAssertText(message, context, config));
return baseAssert(context.value, buildPowerAssertText(message, context, formatter));
};

@@ -167,3 +166,3 @@ }

function decorateTwoArgs (baseAssert, config) {
function decorateTwoArgs (baseAssert, formatter) {
return function (arg1, arg2, message) {

@@ -193,3 +192,3 @@ var context, val1, val2;

return baseAssert(val1, val2, buildPowerAssertText(message, context, config));
return baseAssert(val1, val2, buildPowerAssertText(message, context, formatter));
};

@@ -199,4 +198,4 @@ }

function buildPowerAssertText (message, context, config) {
var powerAssertText = config.formatter.format(context).join(config.lineSeparator);
function buildPowerAssertText (message, context, formatter) {
var powerAssertText = formatter(context);
return message ? message + ' ' + powerAssertText : powerAssertText;

@@ -222,20 +221,2 @@ }

// borrowed from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
function bind (aFunction, oThis) {
if (typeof aFunction !== 'function') {
throw new TypeError('bind - what is trying to be bound is not callable');
}
var aArgs = Array.prototype.slice.call(arguments, 2),
fToBind = aFunction,
NOP = function () {},
fBound = function () {
return fToBind.apply(((aFunction instanceof NOP) && oThis) ? aFunction : oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
NOP.prototype = aFunction.prototype;
fBound.prototype = new NOP();
return fBound;
}
// using returnExports UMD pattern with substack pattern

@@ -242,0 +223,0 @@ empower.defaultOptions = defaultOptions;

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

@@ -17,3 +17,4 @@ "test",

"scripts": {
"test": "grunt test"
"test": "grunt test",
"coveralls": "grunt coverage && cat ./coverage.lcov | ./node_modules/coveralls/bin/coveralls.js"
},

@@ -29,10 +30,14 @@ "main": "./lib/empower",

"devDependencies": {
"espower": "~0.2.1",
"espower": "~0.3.0",
"esprima": "~1.0.4",
"escodegen": "~0.0.28",
"coffee-script-redux": "2.0.0-beta7",
"escodegen": "~1.0.1",
"grunt": "~0.4.2",
"grunt-mocha-test": "~0.8.0",
"grunt-contrib-jshint": "~0.7.1",
"grunt-contrib-watch": "~0.5.3"
"grunt-mocha-test": "~0.8.1",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-bump": "~0.0.13",
"mocha-lcov-reporter": "~0.0.1",
"blanket": "~1.1.5",
"coveralls": "~2.6.0",
"load-grunt-tasks": "~0.2.1"
},

@@ -39,0 +44,0 @@ "licenses": [

@@ -7,2 +7,3 @@ empower

[![Dependency Status](https://gemnasium.com/twada/empower.png)](https://gemnasium.com/twada/empower)
[![Coverage Status](https://coveralls.io/repos/twada/empower/badge.png?branch=master)](https://coveralls.io/r/twada/empower?branch=master)

@@ -14,3 +15,3 @@ Power Assert feature enhancer for assert function/object.

---------------------------------------
`empower` is a core module of [power-assert](http://github.com/twada/power-assert) family. `empower` enhances standard `assert` function or any assert-like object to work with power-assert feature added code instrumented by [espower](http://github.com/twada/espower). `empower` module also provides a default formatter for power-assert output.
`empower` is a core module of [power-assert](http://github.com/twada/power-assert) family. `empower` enhances standard `assert` function or any assert-like object to work with power-assert feature added code instrumented by [espower](http://github.com/twada/espower).

@@ -17,0 +18,0 @@

var empower = require('../lib/empower'),
weave = require('../test_helper').weave,
assert = require('assert');
assert = require('assert'),
fakeFormatter = function (context) {
return [
context.location.path,
context.content
].join('\n');
};

@@ -13,4 +18,4 @@

});
test('formatter: power-assert-formatter module', function () {
assert.deepEqual(this.options.formatter, require('../lib/power-assert-formatter'));
test('formatter: undefined', function () {
assert.deepEqual(typeof this.options.formatter, 'undefined');
});

@@ -38,26 +43,22 @@ suite('targetMethods', function () {

suite('lineSeparator option', function () {
function lineSeparatorTest (name, option, expectedSeparator) {
var baseAssert = require('assert'),
assert = empower(baseAssert, option);
suite('empower argument preconditions', function () {
function argumentTest (name, arg, expectedMessage) {
expectedMessage = expectedMessage || 'empower argument should be a function or object.';
test(name, function () {
var falsyNum = 0;
try {
eval(weave('assert(falsyNum);'));
} catch (e) {
baseAssert.equal(e.message, [
'# /path/to/some_test.js:1',
'',
'assert(falsyNum);',
' | ',
' 0 ',
''
].join(expectedSeparator));
}
assert.throws(
function() {
empower(arg, fakeFormatter);
},
function(err) {
return ((err instanceof TypeError) && (expectedMessage === err.message));
},
"unexpected error"
);
});
}
lineSeparatorTest('default is LF', {}, '\n');
lineSeparatorTest('LF', {lineSeparator: '\n'}, '\n');
lineSeparatorTest('CR', {lineSeparator: '\r'}, '\r');
lineSeparatorTest('CRLF', {lineSeparator: '\r\n'}, '\r\n');
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.');
});

@@ -142,3 +143,3 @@

};
this.empoweredAssert = empower(this.fakeAssertObject, this.options);
this.empoweredAssert = empower(this.fakeAssertObject, fakeFormatter, this.options);
});

@@ -158,3 +159,3 @@ suite('returned assert', function () {

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

@@ -178,3 +179,3 @@ });

};
this.empoweredAssert = empower(this.fakeAssertObject, this.options);
this.empoweredAssert = empower(this.fakeAssertObject, fakeFormatter, this.options);
});

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

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

@@ -234,6 +235,12 @@ });

};
this.empoweredAssert = empower(this.fakeAssertFunction, this.options);
this.empoweredAssert = empower(this.fakeAssertFunction, fakeFormatter, this.options);
});
suite('returned assert', function () {
sharedTestsForEmpowerFunctionReturnValue();
test('works as assert function', function () {
var empoweredAssert = this.empoweredAssert;
assert.throws(function () {
empoweredAssert(false, 'empoweredAssert');
}, /FakeAssert: assertion failed. empoweredAssert/);
});
test('is also a function', function () {

@@ -253,3 +260,3 @@ assert.ok(typeof this.empoweredAssert, 'function');

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

@@ -262,28 +269,5 @@ });

assert.throws(function () {
empower(func, {destructive: true});
empower(func, fakeFormatter, {destructive: true});
}, 'cannot use destructive:true to function\.');
});
});
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.');
});

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