From 16e17954b4161061c032d166f7c3c92ccdf444c8 Mon Sep 17 00:00:00 2001 From: dceejay Date: Thu, 26 Mar 2015 15:01:55 +0000 Subject: [PATCH] add try catch to helper shutdown, tiny fixes for exec and trigger based on tests --- nodes/core/core/75-exec.js | 6 +++--- nodes/core/core/89-trigger.js | 2 +- test/nodes/helper.js | 23 +++++++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/nodes/core/core/75-exec.js b/nodes/core/core/75-exec.js index f075a67a4..853af26a2 100644 --- a/nodes/core/core/75-exec.js +++ b/nodes/core/core/75-exec.js @@ -22,9 +22,9 @@ module.exports = function(RED) { function ExecNode(n) { RED.nodes.createNode(this,n); - this.cmd = n.command.trim(); + this.cmd = (n.command || "").trim(); this.addpay = n.addpay; - this.append = n.append.trim() || ""; + this.append = (n.append || "").trim(); this.useSpawn = n.useSpawn; var node = this; @@ -33,7 +33,7 @@ module.exports = function(RED) { if (this.useSpawn === true) { // make the extra args into an array // then prepend with the msg.payload - if (typeof(msg.payload !== "string")) { msg.payload = msg.payload.toString(); } + if (typeof(msg.payload !== "string")) { msg.payload = (msg.payload || "").toString(); } var arg = []; if (node.append.length > 0) { arg = node.append.split(","); } if ((node.addpay === true) && (msg.payload.trim() !== "")) { arg.unshift(msg.payload); } diff --git a/nodes/core/core/89-trigger.js b/nodes/core/core/89-trigger.js index 94c365415..f76b3b598 100644 --- a/nodes/core/core/89-trigger.js +++ b/nodes/core/core/89-trigger.js @@ -23,7 +23,7 @@ module.exports = function(RED) { this.op2 = n.op2 || "0"; this.op1type = n.op1type || "val"; this.op2type = n.op2type || "val"; - this.extend = n.extend || false; + this.extend = n.extend || "false"; this.units = n.units || "ms"; this.duration = n.duration || 250; if (this.duration <= 0) { this.duration = 0; } diff --git a/test/nodes/helper.js b/test/nodes/helper.js index 436747336..6e0da5c32 100644 --- a/test/nodes/helper.js +++ b/test/nodes/helper.js @@ -56,12 +56,12 @@ module.exports = { logSpy = sinon.spy(log,"log"); logSpy.FATAL = log.FATAL; logSpy.ERROR = log.ERROR; - logSpy.WARN = log.WARN; - logSpy.INFO = log.INFO; - logSpy.DEBUG = log.DEBUG; - logSpy.TRACE = log.TRACE; - logSpy.METRIC = log.METRIC; - + logSpy.WARN = log.WARN; + logSpy.INFO = log.INFO; + logSpy.DEBUG = log.DEBUG; + logSpy.TRACE = log.TRACE; + logSpy.METRIC = log.METRIC; + if (typeof testCredentials === 'function') { cb = testCredentials; testCredentials = {}; @@ -94,7 +94,7 @@ module.exports = { testNode[i](RED); } } else { - testNode(RED); + testNode(RED); } flows.load().then(function() { should.deepEqual(testFlows, flows.getFlows()); @@ -138,14 +138,17 @@ module.exports = { //TODO consider saving TCP handshake/server reinit on start/stop/start sequences stopServer: function(done) { if(server) { - server.close(done); + try { + server.close(done); + } catch(e) { + done(); + } } }, url: function() { return url; }, nock: nock, - + log: function() { return logSpy;} }; -