Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
node-red-contrib-mock-node
Advanced tools
Readme
Crude way of mocking node-red nodes so you can unit test them easily (ish).
$ npm install node-red-contrib-mock-node --save-dev
Consider the following example node:
module.exports = function (RED) {
'use strict';
RED.nodes.registerType('example-node-red-node', function (config) {
RED.nodes.createNode(this, config);
var node = this;
node.context().set('test', config.testValue);
node.context().flow.set('test', config.testValue + 1);
node.context().global.set('test', config.testValue + 2);
node.on('input', function (msg) {
node.send(msg);
node.status({
fill: 'green',
shape: 'dot',
text: 'hello'
});
});
});
};
We can test it like so:
var nodeRedModule = require('./example-node-red-node.js');
var mock = require('node-red-contrib-mock-node');
it('should test properly', function () {
var node = mock(nodeRedModule, {
testValue: 3
}, {
username: 'uname',
password: 'pword'
}, function(module, node) {
// Do stuff with the module and node before the node's registerType callback is invoked.
});
assert.strictEqual(node.credentials.username, 'uname');
assert.strictEqual(node.credentials.password, 'pword');
assert.strictEqual(node.context().get('test'), 3);
assert.strictEqual(node.context().flow.get('test'), 4);
assert.strictEqual(node.context().global.get('test'), 5);
var msg = {topic: 'topic', payload: 'payload'};
node.emit('input', msg);
assert.strictEqual(node.sent(0), msg);
assert.strictEqual(node.status().fill, 'green');
assert.strictEqual(node.status().shape, 'dot');
assert.strictEqual(node.status().text, 'hello');
});
The key part is the arguments to the function mock:
FAQs
Crude facility to mock NodeRED nodes for unit testing
The npm package node-red-contrib-mock-node receives a total of 2 weekly downloads. As such, node-red-contrib-mock-node popularity was classified as not popular.
We found that node-red-contrib-mock-node 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.