1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

add debug and trace to function node (#1654)

This commit is contained in:
Dave Conway-Jones 2018-03-20 20:40:36 +00:00 committed by Nick O'Leary
parent 2d52527fb4
commit 087cd121b8
2 changed files with 52 additions and 0 deletions

View File

@ -65,6 +65,8 @@ module.exports = function(RED) {
"log:__node__.log,"+ "log:__node__.log,"+
"error:__node__.error,"+ "error:__node__.error,"+
"warn:__node__.warn,"+ "warn:__node__.warn,"+
"debug:__node__.debug,"+
"trace:__node__.trace,"+
"on:__node__.on,"+ "on:__node__.on,"+
"status:__node__.status,"+ "status:__node__.status,"+
"send:function(msgs){ __node__.send(__msgid__,msgs);}"+ "send:function(msgs){ __node__.send(__msgid__,msgs);}"+
@ -91,6 +93,12 @@ module.exports = function(RED) {
warn: function() { warn: function() {
node.warn.apply(node, arguments); node.warn.apply(node, arguments);
}, },
debug: function() {
node.debug.apply(node, arguments);
},
trace: function() {
node.trace.apply(node, arguments);
},
send: function(id, msgs) { send: function(id, msgs) {
sendResults(node, id, msgs); sendResults(node, id, msgs);
}, },

View File

@ -527,6 +527,50 @@ describe('function node', function() {
} }
}); });
}); });
it('should log a Debug Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.debug('test');"}];
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().DEBUG);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'function');
msg.should.have.property('msg', 'test');
done();
} catch (err) {
done(err);
}
});
});
it('should log a Trace Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.trace('test');"}];
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().TRACE);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'function');
msg.should.have.property('msg', 'test');
done();
} catch (err) {
done(err);
}
});
});
it('should log a Warning Message', function (done) { it('should log a Warning Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.warn('test');"}]; var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.warn('test');"}];
helper.load(functionNode, flow, function () { helper.load(functionNode, flow, function () {