Comparing version 0.1.3 to 0.1.4
@@ -30,6 +30,8 @@ /** | ||
var DEFAULT_OPTIONS = { | ||
destructive: false, | ||
formatter: defaultFormatter | ||
}; | ||
function defaultOptions () { | ||
return { | ||
destructive: false, | ||
formatter: defaultFormatter | ||
}; | ||
} | ||
@@ -48,3 +50,3 @@ | ||
} | ||
config = extend(extend({}, DEFAULT_OPTIONS), (options || {})); | ||
config = extend(defaultOptions(), (options || {})); | ||
switch (typeof assert) { | ||
@@ -63,3 +65,3 @@ case 'function': | ||
var baseAssert = config.destructive ? assertObject.ok : bind(assertObject.ok, assertObject), | ||
enhancement = enhance(baseAssert, config.formatter), | ||
enhancement = enhance(baseAssert, config), | ||
target = config.destructive ? assertObject : Object.create(assertObject); | ||
@@ -71,3 +73,3 @@ return extend(target, enhancement); | ||
function empowerAssertFunction (assertFunction, config) { | ||
var enhancement = enhance(assertFunction, config.formatter), | ||
var enhancement = enhance(assertFunction, config), | ||
powerAssert = function powerAssert (context, message) { | ||
@@ -86,3 +88,3 @@ enhancement.ok(context, message); | ||
function enhance (baseAssert, formatter, callback) { | ||
function enhance (baseAssert, config) { | ||
var events = []; | ||
@@ -108,8 +110,10 @@ | ||
var context = value.context, | ||
callback, | ||
powerAssertText; | ||
if (!context.result) { | ||
if (typeof callback === 'function') { | ||
if (typeof config.callback === 'function') { | ||
callback = config.callback; | ||
callback(context, message); | ||
} else { | ||
powerAssertText = formatter.format(context).join('\n'); | ||
powerAssertText = config.formatter.format(context).join('\n'); | ||
baseAssert(context.result, message ? message + ' ' + powerAssertText : powerAssertText); | ||
@@ -168,5 +172,4 @@ } | ||
// using returnExports UMD pattern with substack pattern | ||
empower.enhance = enhance; | ||
empower.DEFAULT_OPTIONS = DEFAULT_OPTIONS; | ||
empower.defaultOptions = defaultOptions; | ||
return empower; | ||
})); |
{ | ||
"name": "empower", | ||
"description": "Power Assert feature enhancer for assert function/object", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"keywords": [ | ||
@@ -28,6 +28,6 @@ "test", | ||
"devDependencies": { | ||
"espower": "~0.1.2", | ||
"esprima": "1.0.3", | ||
"espower": "~0.1.4", | ||
"esprima": "1.0.4", | ||
"escodegen": "0.0.26", | ||
"coffee-script-redux": "2.0.0-beta6", | ||
"coffee-script-redux": "2.0.0-beta7", | ||
"qunitjs": "1.10.0", | ||
@@ -34,0 +34,0 @@ "qunit-tap": "1.4.0", |
@@ -6,2 +6,3 @@ empower | ||
[![NPM version](https://badge.fury.io/js/empower.png)](http://badge.fury.io/js/empower) | ||
[![Dependency Status](https://gemnasium.com/twada/empower.png)](https://gemnasium.com/twada/empower) | ||
@@ -8,0 +9,0 @@ Power Assert feature enhancer for assert function/object. |
var q = require('../test_helper').QUnit, | ||
formatter = require('../lib/power-assert-formatter'), | ||
enhance = require('../lib/empower').enhance, | ||
empower = require('../lib/empower'), | ||
config = empower.defaultOptions(), | ||
powerAssertTextLines = [], | ||
assert = enhance(q.assert.ok, formatter, function (context, message) { | ||
powerAssertTextLines = formatter.format(context); | ||
}), | ||
espower = require('espower'), | ||
@@ -13,2 +10,6 @@ esprima = require('esprima'), | ||
config.callback = function (context, message) { | ||
powerAssertTextLines = config.formatter.format(context); | ||
}; | ||
var assert = empower(q.assert, config); | ||
@@ -15,0 +16,0 @@ q.module('CoffeeScriptRedux integration', { |
@@ -5,11 +5,12 @@ var q = require('../test_helper').QUnit, | ||
q.module('empower.DEFAULT_OPTIONS'); | ||
q.module('empower.defaultOptions()', { | ||
setup: function () { | ||
this.options = empower.defaultOptions(); | ||
} | ||
}); | ||
q.test('destructive: false', function () { | ||
var options = empower.DEFAULT_OPTIONS; | ||
q.equal(options.destructive, false); | ||
q.equal(this.options.destructive, false); | ||
}); | ||
q.test('formatter: power-assert-formatter module', function () { | ||
var options = empower.DEFAULT_OPTIONS; | ||
q.deepEqual(options.formatter, require('../lib/power-assert-formatter')); | ||
q.deepEqual(this.options.formatter, require('../lib/power-assert-formatter')); | ||
}); | ||
@@ -16,0 +17,0 @@ |
var q = require('../test_helper').QUnit, | ||
instrument = require('../test_helper').instrument, | ||
formatter = require('../lib/power-assert-formatter'), | ||
enhance = require('../lib/empower').enhance, | ||
powerAssertTextLines = [], | ||
assert = enhance(q.assert.ok, formatter, function (context, message) { | ||
powerAssertTextLines = formatter.format(context); | ||
}); | ||
empower = require('../lib/empower'), | ||
config = empower.defaultOptions(), | ||
powerAssertTextLines = []; | ||
config.callback = function (context, message) { | ||
powerAssertTextLines = config.formatter.format(context); | ||
}; | ||
var assert = empower(q.assert, config); | ||
q.module('power-assert-formatter', { | ||
@@ -136,10 +138,11 @@ setup: function () { | ||
q.test('assert((delete foo) === false);', function () { | ||
var foo = { | ||
bar: { | ||
baz: false | ||
} | ||
}; | ||
assert.ok(eval(instrument('assert((delete foo) === false);'))); | ||
q.test('assert((delete nonexistent) === false);', function () { | ||
assert.ok(eval(instrument('assert((delete nonexistent) === false);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((delete nonexistent) === false);', | ||
' | | ', | ||
' true false ', | ||
'' | ||
]); | ||
@@ -711,1 +714,30 @@ }); | ||
}); | ||
q.test('ConditionalExpression: assert(truthy ? falsy : anotherFalsy);', function () { | ||
var truthy = 'truthy', falsy = 0, anotherFalsy = null; | ||
assert.ok(eval(instrument('assert(truthy ? falsy : anotherFalsy);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(truthy ? falsy : anotherFalsy);', | ||
' | | ', | ||
' "truthy" 0 ', | ||
'' | ||
]); | ||
}); | ||
q.test('ConditionalExpression of ConditionalExpression: assert(falsy ? truthy : truthy ? anotherFalsy : truthy);', function () { | ||
var truthy = 'truthy', falsy = 0, anotherFalsy = null; | ||
assert.ok(eval(instrument('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsy ? truthy : truthy ? anotherFalsy : truthy);', | ||
' | | | ', | ||
' 0 "truthy" null ', | ||
'' | ||
]); | ||
}); |
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
50400
1281
30
45