Add unit tests for function node init code

This commit is contained in:
Nick O'Leary
2020-09-25 17:11:10 +01:00
parent 0601833387
commit 2db3a4f1ef
2 changed files with 94 additions and 105 deletions

View File

@@ -121,7 +121,7 @@ module.exports = function(RED) {
"done:__done__"+
"};\n"+
node.func+"\n"+
"})(msg,send,done);";
"})(msg,__send__,__done__);";
var finScript = null;
var finOpt = null;
node.topic = n.topic;
@@ -279,12 +279,12 @@ module.exports = function(RED) {
debug:__node__.debug,
trace:__node__.trace,
status:__node__.status,
send: function(msgs, cloneMsg) {
__node__.send(__send__, RED.util.generateId(), msgs, cloneMsg);
send: function(msgs, cloneMsg) {
__node__.send(__send__, RED.util.generateId(), msgs, cloneMsg);
}
};
`+ node.ini +`
})(send);`;
})(__initSend__);`;
iniOpt = createVMOpt(node, " setup");
iniScript = new vm.Script(iniText, iniOpt);
}
@@ -296,16 +296,15 @@ module.exports = function(RED) {
}
var promise = Promise.resolve();
if (iniScript) {
context.send = function(m) { node.send(m); };
context.__initSend__ = function(msgs) { node.send(msgs); };
promise = iniScript.runInContext(context, iniOpt);
delete context.send;
}
function processMessage(msg, send, done) {
var start = process.hrtime();
context.msg = msg;
context.send = send;
context.done = done;
context.__send__ = send;
context.__done__ = done;
node.script.runInContext(context);
context.results.then(function(results) {