Merge pull request #2873 from node-red/function-modules

Function node external modules
This commit is contained in:
Nick O'Leary
2021-03-01 21:35:31 +00:00
committed by GitHub
28 changed files with 1323 additions and 223 deletions

View File

@@ -93,9 +93,6 @@ describe('function node', function() {
/*
it('should be loaded', function(done) {
var flow = [{id:"n1", type:"function", name: "function" }];
helper.load(functionNode, flow, function() {
@@ -1417,6 +1414,86 @@ describe('function node', function() {
});
});
describe('externalModules', function() {
it('should fail if using OS module without functionExternalModules set to true', function(done) {
var flow = [
{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"os", module:"os"}]},
{id:"n2", type:"helper"}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
should.not.exist(n1);
done();
}).catch(err => done(err));
})
it('should fail if using OS module without it listed in libs', function(done) {
var flow = [
{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;"},
{id:"n2", type:"helper"}
];
helper.settings({
functionExternalModules: true
})
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var messageReceived = false;
n2.on("input", function(msg) {
messageReceived = true;
});
n1.receive({payload:"foo",topic: "bar"});
setTimeout(function() {
try {
messageReceived.should.be.false();
done();
} catch(err) {
done(err);
}
},20);
}).catch(err => done(err));
})
it('should require the OS module', function(done) {
var flow = [
{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"os", module:"os"}]},
{id:"n2", type:"helper"}
];
helper.settings({
functionExternalModules: true
})
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', require('os').type());
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo",topic: "bar"});
}).catch(err => done(err));
})
it('should fail if module variable name clashes with sandbox builtin', function(done) {
var flow = [
{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"flow", module:"os"}]},
{id:"n2", type:"helper"}
];
helper.settings({
functionExternalModules: true
})
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
should.not.exist(n1);
done();
}).catch(err => done(err));
})
})
describe('Logger', function () {
function testLog(initCode,funcCode,expectedLevel, done) {
@@ -1603,5 +1680,4 @@ describe('function node', function() {
});
})
*/
});