From 087cd121b84618246b5b1054347c5054046257d1 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 20 Mar 2018 20:40:36 +0000 Subject: [PATCH] add debug and trace to function node (#1654) --- nodes/core/core/80-function.js | 8 +++++ test/nodes/core/core/80-function_spec.js | 44 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/nodes/core/core/80-function.js b/nodes/core/core/80-function.js index 62e905d04..69d6d0ca2 100644 --- a/nodes/core/core/80-function.js +++ b/nodes/core/core/80-function.js @@ -65,6 +65,8 @@ module.exports = function(RED) { "log:__node__.log,"+ "error:__node__.error,"+ "warn:__node__.warn,"+ + "debug:__node__.debug,"+ + "trace:__node__.trace,"+ "on:__node__.on,"+ "status:__node__.status,"+ "send:function(msgs){ __node__.send(__msgid__,msgs);}"+ @@ -91,6 +93,12 @@ module.exports = function(RED) { warn: function() { node.warn.apply(node, arguments); }, + debug: function() { + node.debug.apply(node, arguments); + }, + trace: function() { + node.trace.apply(node, arguments); + }, send: function(id, msgs) { sendResults(node, id, msgs); }, diff --git a/test/nodes/core/core/80-function_spec.js b/test/nodes/core/core/80-function_spec.js index a59be3076..847776a92 100644 --- a/test/nodes/core/core/80-function_spec.js +++ b/test/nodes/core/core/80-function_spec.js @@ -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) { var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.warn('test');"}]; helper.load(functionNode, flow, function () {