Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
empower-core
Advanced tools
The empower-core npm package is a core library for power-assert, which provides a way to enhance assertion libraries by adding descriptive assertion messages. It is designed to work with various assertion libraries to provide more informative error messages, making it easier to debug test failures.
Enhanced Assertion Messages
This feature allows you to enhance the standard assertion messages with more descriptive information. In the example, the assertion `enhancedAssert(result === 5, 'Expected result to be 5')` will provide a more detailed error message if the assertion fails.
const assert = require('assert');
const empower = require('empower-core');
const enhancedAssert = empower(assert);
function add(a, b) {
return a + b;
}
const result = add(2, 2);
enhancedAssert(result === 5, 'Expected result to be 5');
Customizable Assertion Formatting
This feature allows you to customize the formatting of assertion messages. By providing patterns, you can control how the assertion messages are displayed. In the example, the pattern `['assert(value, [message])']` is used to format the assertion message.
const assert = require('assert');
const empower = require('empower-core');
const enhancedAssert = empower(assert, { patterns: ['assert(value, [message])'] });
function multiply(a, b) {
return a * b;
}
const result = multiply(3, 3);
enhancedAssert(result === 10, 'Expected result to be 10');
Power-assert is a similar package that provides descriptive assertion messages. It is designed to work with various assertion libraries and offers a more user-friendly way to debug test failures. Compared to empower-core, power-assert is a more comprehensive solution that includes additional features and integrations.
Chai is a popular assertion library for Node.js and the browser that provides a variety of assertion styles (BDD, TDD, and assert). While it does not specifically focus on enhancing assertion messages like empower-core, it offers a rich set of features for writing tests and assertions.
Should is another assertion library for Node.js that provides a fluent interface for writing assertions. It focuses on readability and expressiveness, making it easier to write and understand tests. While it does not offer the same level of enhanced assertion messages as empower-core, it provides a user-friendly way to write assertions.
Power Assert feature enhancer for assert function/object.
empower-core
is a core module of power-assert family. empower-core
enhances standard assert
function or any assert-like object to work with power-assert feature added code instrumented by espower.
empower-core
works with standard assert
function (best fit with Mocha), and also supports assert-like objects/functions provided by various testing frameworks such as QUnit, buster.js, and nodeunit.
Pull-requests, issue reports and patches are always welcomed. See power-assert project for more documentation.
See CHANGELOG
return type |
---|
function or object |
empower-core
function takes function or object(originalAssert
) then returns PowerAssert feature added function/object based on originalAssert
.
If destructive
option is falsy, originalAssert
will be unchanged. If destructive
option is truthy, originalAssert
will be manipulated directly and returned enhancedAssert
will be the same instance of originalAssert
.
type | default value |
---|---|
function or object | N/A |
originalAssert
is an instance of standard assert
function or any assert-like object. see SUPPORTED ASSERTION LIBRARIES and ASSERTION LIBRARIES KNOWN TO WORK section. Be careful that originalAssert
will be manipulated directly if destructive
option is truthy.
type | default value |
---|---|
object | (return value of empowerCore.defaultOptions() ) |
Configuration options. If not passed, default options will be used.
type | default value |
---|---|
boolean | false |
If truthy, modify originalAssert
destructively.
If false
, empower-core mimics originalAssert as new object/function, so originalAssert
will not be changed. If true
, originalAssert
will be manipulated directly and returned enhancedAssert
will be the same instance of originalAssert
.
type | default value |
---|---|
boolean | true |
bindReceiver
defaults to true
, meaning assertion methods have their this
value bound to the original assertion. Setting bindReceiver
to false causes the this
reference to be passed through from the actual invocation.
type | default value |
---|---|
function | (function defined in empowerCore.defaultOptions() ) |
Both methods are called with a single event
argument, it will have the following properties:
event.enhanced
- true
for methods matching patterns
. false
for methods matching wrapOnlyPatterns
.
event.originalMessage
- The actual value the user provided for optional message
parameter. This will be undefined
if the user did not provide a value, even if the underlying assertion provides a default message.
event.defaultMessage
- If you use objects instead of strings to specify patterns (see below), the defaultMessage
metadata will be copied directly on the event object.
event.matcherSpec
- This contains the complete parsed matcher spec as supplied, as well as any additional metadata you may have supplied (see patterns section below for details on how to supply additional metadata).
event.args
- An array of the actual arguments passed to the assertion.
event.assertionThrew
- Whether or not the underlying assertion threw an error. This will always be true
in an onError
callback, and always false
in an onSuccess
callback.
event.error
- Only present if event.assertionThrew === true
. Contains the error thrown by the underlying assertion method.
event.returnValue
- Only present if event.assertionThrew === false
. Contains the value return value returned by the underlying assertion method.
event.powerAssertContext
- Only present for methods that match patterns
, and only in code that has been enhanced with the power-assert transform. It contains the information necessary for power-assert renderers to generate their output. Implementors of onError
should usually attach it to the error object
function onError (errorEvent) {
var e = errorEvent.error;
if (errorEvent.powerAssertContext && e.name === 'AssertionError') {
e.powerAssertContext = errorEvent.powerAssertContext;
}
throw e;
}
type | default value |
---|---|
function | N/A |
TBD
type | default value |
---|---|
Array of string or objects | objects shown below |
[
'assert(value, [message])',
'assert.ok(value, [message])',
'assert.equal(actual, expected, [message])',
'assert.notEqual(actual, expected, [message])',
'assert.strictEqual(actual, expected, [message])',
'assert.notStrictEqual(actual, expected, [message])',
'assert.deepEqual(actual, expected, [message])',
'assert.notDeepEqual(actual, expected, [message])',
'assert.deepStrictEqual(actual, expected, [message])',
'assert.notDeepStrictEqual(actual, expected, [message])'
]
Target patterns for power assert feature instrumentation.
Pattern detection is done by call-signature. Any arguments enclosed in bracket (for example, [message]
) means optional parameters. Without bracket means mandatory parameters.
Instead of a string, you may alternatively specify an object with a pattern
property, and any other arbitrary data.
Currently only defaultMessage
is formally recommended, but you can attach any data here and it will be passed to the onSuccess
and onError
handlers.
[
{
pattern: 'assert.fail([message])',
defaultMessage:'assert.fail() was called!!'
},
...
]
type | default value |
---|---|
Array of string | empty array |
Methods matching these patterns will not be instrumented by the code transform, but they will be wrapped at runtime and trigger events in the onSuccess
and onError
callbacks. Note that "wrap only" events will never have a powerAssertContext
property.
Similar to the options.patterns
, you may supply objects with a pattern
member, and the additional metadata will be passed to the assertion listeners.
Returns default options object for empowerCore
function. In other words, returns
{
destructive: false,
onError: onError,
onSuccess: onSuccess,
patterns: [
'assert(value, [message])',
'assert.ok(value, [message])',
'assert.equal(actual, expected, [message])',
'assert.notEqual(actual, expected, [message])',
'assert.strictEqual(actual, expected, [message])',
'assert.notStrictEqual(actual, expected, [message])',
'assert.deepEqual(actual, expected, [message])',
'assert.notDeepEqual(actual, expected, [message])',
'assert.deepStrictEqual(actual, expected, [message])',
'assert.notDeepStrictEqual(actual, expected, [message])'
]
}
with sensible default for onError
and onSuccess
function onError (errorEvent) {
var e = errorEvent.error;
if (errorEvent.powerAssertContext && e.name === 'AssertionError') {
e.powerAssertContext = errorEvent.powerAssertContext;
}
throw e;
}
function onSuccess(successEvent) {
return successEvent.returnValue;
}
Install
$ npm install --save-dev empower-core
empowerCore
function is exported
<script type="text/javascript" src="./path/to/node_modules/empower-core/build/empower-core.js"></script>
Install
$ bower install --save-dev empower-core
Then load (empowerCore
function is exported)
<script type="text/javascript" src="./path/to/bower_components/empower-core/build/empower-core.js"></script>
Licensed under the MIT license.
FAQs
Power Assert feature enhancer for assert function/object
The npm package empower-core receives a total of 219,095 weekly downloads. As such, empower-core popularity was classified as popular.
We found that empower-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.