Compare commits

...

8 Commits

Author SHA1 Message Date
Dave Conway-Jones
539ca8b84d keep changes in this branch in sync with other trigger changes 2017-12-29 16:57:37 +00:00
Dave Conway-Jones
813a5d2879 add some istanbul ignore to trigger 2017-11-03 19:20:03 +00:00
Dave Conway-Jones
d2b53ebba0 boost trigger node test coverage 2017-09-20 17:35:24 +01:00
Dave Conway-Jones
32d98a7fa3 trigger test - add missing try/catch to all test with callback 2017-09-20 09:31:11 +01:00
Dave Conway-Jones
69946f0be0 test trigger repeat for pass by ref error 2017-09-20 08:42:23 +01:00
Dave Conway-Jones
6e610c0435 Add some tests for trigger by topic 2017-09-19 23:21:50 +01:00
Dave Conway-Jones
cdf9e2c214 ensure trigger node clones repeating message 2017-09-19 22:40:36 +01:00
Dave Conway-Jones
6b672bd9af Let trigger node support per topic mode 2017-09-18 15:44:37 +01:00
4 changed files with 337 additions and 99 deletions

View File

@@ -56,6 +56,13 @@
</ul> </ul>
</div> </div>
<br/> <br/>
<div class="form-row">
<label data-i18n="trigger.for" for="node-input-bytopic"></label>
<select id="node-input-bytopic">
<option value="all" data-i18n="trigger.alltopics"></option>
<option value="topic" data-i18n="trigger.bytopics"></option>
</select>
</div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label> <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></input> <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></input>
@@ -85,7 +92,7 @@
<p>If set to a <i>string</i> type, the node supports the mustache template syntax.</p> <p>If set to a <i>string</i> type, the node supports the mustache template syntax.</p>
<p>If the node receives a message with a <code>reset</code> property, or a <code>payload</code> <p>If the node receives a message with a <code>reset</code> property, or a <code>payload</code>
that matches that configured in the node, any timeout or repeat currently in that matches that configured in the node, any timeout or repeat currently in
progress will be cleared and no message triggered.</o> progress will be cleared and no message triggered.</p>
<p>The node can be configured to resend a message at a regular interval until it <p>The node can be configured to resend a message at a regular interval until it
is reset by a received message.</p> is reset by a received message.</p>
</script> </script>
@@ -103,6 +110,7 @@
extend: {value:"false"}, extend: {value:"false"},
units: {value:"ms"}, units: {value:"ms"},
reset: {value:""}, reset: {value:""},
bytopic: {value: "all"},
name: {value:""} name: {value:""}
}, },
inputs:1, inputs:1,

View File

@@ -19,6 +19,7 @@ module.exports = function(RED) {
var mustache = require("mustache"); var mustache = require("mustache");
function TriggerNode(n) { function TriggerNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.bytopic = n.bytopic || "all";
this.op1 = n.op1 || "1"; this.op1 = n.op1 || "1";
this.op2 = n.op2 || "0"; this.op2 = n.op2 || "0";
this.op1type = n.op1type || "str"; this.op1type = n.op1type || "str";
@@ -47,7 +48,7 @@ module.exports = function(RED) {
this.extend = n.extend || "false"; this.extend = n.extend || "false";
this.units = n.units || "ms"; this.units = n.units || "ms";
this.reset = n.reset || ''; this.reset = n.reset || '';
this.duration = parseInt(n.duration); this.duration = parseFloat(n.duration);
if (isNaN(this.duration)) { if (isNaN(this.duration)) {
this.duration = 250; this.duration = 250;
} }
@@ -65,29 +66,32 @@ module.exports = function(RED) {
this.op2Templated = (this.op2type === 'str' && this.op2.indexOf("{{") != -1); this.op2Templated = (this.op2type === 'str' && this.op2.indexOf("{{") != -1);
if ((this.op1type === "num") && (!isNaN(this.op1))) { this.op1 = Number(this.op1); } if ((this.op1type === "num") && (!isNaN(this.op1))) { this.op1 = Number(this.op1); }
if ((this.op2type === "num") && (!isNaN(this.op2))) { this.op2 = Number(this.op2); } if ((this.op2type === "num") && (!isNaN(this.op2))) { this.op2 = Number(this.op2); }
if (this.op1 == "null") { this.op1 = null; } //if (this.op1 == "null") { this.op1 = null; }
if (this.op2 == "null") { this.op2 = null; } //if (this.op2 == "null") { this.op2 = null; }
//try { this.op1 = JSON.parse(this.op1); } //try { this.op1 = JSON.parse(this.op1); }
//catch(e) { this.op1 = this.op1; } //catch(e) { this.op1 = this.op1; }
//try { this.op2 = JSON.parse(this.op2); } //try { this.op2 = JSON.parse(this.op2); }
//catch(e) { this.op2 = this.op2; } //catch(e) { this.op2 = this.op2; }
var node = this; var node = this;
var tout = null; node.topics = {};
var m2;
this.on("input", function(msg) { this.on("input", function(msg) {
var topic = msg.topic || "_none";
if (node.bytopic === "all") { topic = "_none"; }
node.topics[topic] = node.topics[topic] || {};
if (msg.hasOwnProperty("reset") || ((node.reset !== '') && (msg.payload == node.reset)) ) { if (msg.hasOwnProperty("reset") || ((node.reset !== '') && (msg.payload == node.reset)) ) {
if (node.loop === true) { clearInterval(tout); } if (node.loop === true) { clearInterval(node.topics[topic].tout); }
else { clearTimeout(tout); } else { clearTimeout(node.topics[topic].tout); }
tout = null; delete node.topics[topic];
node.status({}); node.status({});
} }
else { else {
if (((!tout) && (tout !== 0)) || (node.loop === true)) { if (((!node.topics[topic].tout) && (node.topics[topic].tout !== 0)) || (node.loop === true)) {
if (node.op2type === "pay" || node.op2type === "payl") { m2 = msg.payload; } if (node.op2type === "pay" || node.op2type === "payl") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
else if (node.op2Templated) { m2 = mustache.render(node.op2,msg); } else if (node.op2Templated) { node.topics[topic].m2 = mustache.render(node.op2,msg); }
else if (node.op2type !== "nul") { else if (node.op2type !== "nul") {
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg); node.topics[topic].m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
} }
if (node.op1type === "pay") { } if (node.op1type === "pay") { }
@@ -96,58 +100,67 @@ module.exports = function(RED) {
msg.payload = RED.util.evaluateNodeProperty(node.op1,node.op1type,node,msg); msg.payload = RED.util.evaluateNodeProperty(node.op1,node.op1type,node,msg);
} }
if (node.op1type !== "nul") { node.send(msg); } if (node.op1type !== "nul") { node.send(RED.util.cloneMessage(msg)); }
if (node.duration === 0) { tout = 0; } if (node.duration === 0) { node.topics[topic].tout = 0; }
else if (node.loop === true) { else if (node.loop === true) {
if (tout) { clearInterval(tout); } /* istanbul ignore else */
if (node.topics[topic].tout) { clearInterval(node.topics[topic].tout); }
/* istanbul ignore else */
if (node.op1type !== "nul") { if (node.op1type !== "nul") {
var msg2 = RED.util.cloneMessage(msg); var msg2 = RED.util.cloneMessage(msg);
tout = setInterval(function() { node.send(msg2); },node.duration); node.topics[topic].tout = setInterval(function() { node.send(RED.util.cloneMessage(msg2)); }, node.duration);
} }
} }
else { else {
tout = setTimeout(function() { node.topics[topic].tout = setTimeout(function() {
if (node.op2type !== "nul") { if (node.op2type !== "nul") {
var msg2 = RED.util.cloneMessage(msg); var msg2 = RED.util.cloneMessage(msg);
if (node.op2type === "flow" || node.op2type === "global") { if (node.op2type === "flow" || node.op2type === "global") {
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg); node.topics[topic].m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
} }
msg2.payload = m2; msg2.payload = node.topics[topic].m2;
node.send(msg2); node.send(msg2);
} }
tout = null; delete node.topics[topic];
node.status({}); node.status({});
},node.duration); }, node.duration);
} }
node.status({fill:"blue",shape:"dot",text:" "}); node.status({fill:"blue",shape:"dot",text:" "});
} }
else if ((node.extend === "true" || node.extend === true) && (node.duration > 0)) { else if ((node.extend === "true" || node.extend === true) && (node.duration > 0)) {
if (tout) { clearTimeout(tout); } /* istanbul ignore else */
if (node.op2type === "payl") { m2 = msg.payload; } if (node.op2type === "payl") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
tout = setTimeout(function() { /* istanbul ignore else */
if (node.topics[topic].tout) { clearTimeout(node.topics[topic].tout); }
node.topics[topic].tout = setTimeout(function() {
if (node.op2type !== "nul") { if (node.op2type !== "nul") {
var msg2 = RED.util.cloneMessage(msg); var msg2 = RED.util.cloneMessage(msg);
if (node.op2type === "flow" || node.op2type === "global") { if (node.op2type === "flow" || node.op2type === "global") {
m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg); node.topics[topic].m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
}
if (node.topics[topic] !== undefined) {
msg2.payload = node.topics[topic].m2;
node.send(msg2);
} }
msg2.payload = m2;
node.send(msg2);
} }
tout = null; delete node.topics[topic];
node.status({}); node.status({});
},node.duration); }, node.duration);
} }
else { else {
if (node.op2type === "payl") { m2 = msg.payload; } if (node.op2type === "payl") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
} }
} }
}); });
this.on("close", function() { this.on("close", function() {
if (tout) { for (var t in node.topics) {
if (node.loop === true) { clearInterval(tout); } /* istanbul ignore else */
else { clearTimeout(tout); } if (node.topics[t]) {
tout = null; if (node.loop === true) { clearInterval(node.topics[t].tout); }
else { clearTimeout(node.topics[t].tout); }
delete node.topics[t];
}
} }
node.status({}); node.status({});
}); });

View File

@@ -270,6 +270,9 @@
"wait-reset": "wait to be reset", "wait-reset": "wait to be reset",
"wait-for": "wait for", "wait-for": "wait for",
"wait-loop": "resend it every", "wait-loop": "resend it every",
"for": "Handling",
"bytopics": "each msg.topic independently",
"alltopics": "all messages",
"duration": { "duration": {
"ms": "Milliseconds", "ms": "Milliseconds",
"s": "Seconds", "s": "Seconds",

View File

@@ -15,8 +15,10 @@
**/ **/
var should = require("should"); var should = require("should");
var sinon = require("sinon");
var helper = require("../../helper.js"); var helper = require("../../helper.js");
var triggerNode = require("../../../../nodes/core/core/89-trigger.js"); var triggerNode = require("../../../../nodes/core/core/89-trigger.js");
var RED = require("../../../../red/red.js");
describe('trigger node', function() { describe('trigger node', function() {
@@ -81,14 +83,17 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
if (c === 0) { try {
msg.should.have.a.property("payload", '1'); if (c === 0) {
c+=1; msg.should.have.a.property("payload", '1');
} c+=1;
else { }
msg.should.have.a.property("payload", '0'); else {
done(); msg.should.have.a.property("payload", '0');
done();
}
} }
catch(err) { done(err); }
}); });
n1.emit("input", {payload:null}); n1.emit("input", {payload:null});
}); });
@@ -161,6 +166,155 @@ describe('trigger node', function() {
}); });
}); });
it('should handle multiple topics as one if not asked to handle', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", bytopic:"all", op1:"1", op2:"0", op1type:"num", op2type:"num", duration:"30", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
try {
c += 1;
if (c === 1) {
msg.should.have.a.property("payload", 1);
msg.should.have.a.property("topic", "A");
}
else if (c === 2) {
msg.should.have.a.property("payload", 0);
msg.should.have.a.property("topic", "A");
done();
}
} catch(err) {
done(err);
}
});
n1.emit("input", {payload:1,topic:"A"});
n1.emit("input", {payload:2,topic:"B"});
n1.emit("input", {payload:3,topic:"C"});
});
});
it('should handle multiple topics individually if asked to do so', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", bytopic:"topic", op1:"1", op2:"0", op1type:"num", op2type:"num", duration:"30", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
try {
c += 1;
if (c === 1) {
msg.should.have.a.property("payload", 1);
msg.should.have.a.property("topic", "A");
}
else if (c === 2) {
msg.should.have.a.property("payload", 1);
msg.should.have.a.property("topic", "B");
}
else if (c === 3) {
msg.should.have.a.property("payload", 1);
msg.should.have.a.property("topic", "C");
}
else if (c === 4) {
msg.should.have.a.property("payload", 0);
msg.should.have.a.property("topic", "A");
}
else if (c === 5) {
msg.should.have.a.property("payload", 0);
msg.should.have.a.property("topic", "B");
}
else if (c === 6) {
msg.should.have.a.property("payload", 0);
msg.should.have.a.property("topic", "C");
done();
}
} catch(err) {
done(err);
}
});
n1.emit("input", {payload:1,topic:"A"});
n1.emit("input", {payload:2,topic:"B"});
n1.emit("input", {payload:3,topic:"C"});
});
});
it('should handle multiple topics individually, and extend one, if asked to do so', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", bytopic:"topic", extend:"true", op1:"1", op2:"0", op1type:"num", op2type:"num", duration:"30", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
try {
c += 1;
if (c === 1) {
msg.should.have.a.property("payload", 1);
msg.should.have.a.property("topic", "A");
}
else if (c === 2) {
msg.should.have.a.property("payload", 1);
msg.should.have.a.property("topic", "B");
}
else if (c === 3) {
msg.should.have.a.property("payload", 1);
msg.should.have.a.property("topic", "C");
}
else if (c === 4) {
msg.should.have.a.property("payload", 0);
msg.should.have.a.property("topic", "A");
}
else if (c === 5) {
msg.should.have.a.property("payload", 0);
msg.should.have.a.property("topic", "C");
}
else if (c === 6) {
msg.should.have.a.property("payload", 0);
msg.should.have.a.property("topic", "B");
done();
}
} catch(err) {
done(err);
}
});
n1.emit("input", {payload:1,topic:"A"});
n1.emit("input", {payload:2,topic:"B"});
n1.emit("input", {payload:3,topic:"C"});
setTimeout( function() { n1.emit("input", {payload:2,topic:"B"})}, 20 );
});
});
it('should be able to return things from flow and global context variables', function(done) {
var spy = sinon.stub(RED.util, 'evaluateNodeProperty',
function(arg1, arg2, arg3, arg4) { return arg1; }
);
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"foo", op1type:"flow", op2:"bar", op2type:"global", duration:"20", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
try {
if (c === 0) {
msg.should.have.a.property("payload", "foo");
c+=1;
}
else {
msg.should.have.a.property("payload", "bar");
spy.restore();
done();
}
}
catch(err) { spy.restore(); done(err); }
});
n1.emit("input", {payload:null});
});
});
it('should be able to not output anything on first trigger', function(done) { it('should be able to not output anything on first trigger', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true",op2:"false",op2type:"val",duration:"30", wires:[["n2"]] }, var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true",op2:"false",op2type:"val",duration:"30", wires:[["n2"]] },
{id:"n2", type:"helper"} ]; {id:"n2", type:"helper"} ];
@@ -187,8 +341,11 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
msg.should.have.a.property("payload", true); try {
c += 1; msg.should.have.a.property("payload", true);
c += 1;
}
catch(err) { done(err); }
}); });
setTimeout( function() { setTimeout( function() {
c.should.equal(1); // should only have had one output. c.should.equal(1); // should only have had one output.
@@ -199,23 +356,30 @@ describe('trigger node', function() {
}); });
it('should be able to extend the delay', function(done) { it('should be able to extend the delay', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op1:"false", op2:"true", duration:"100", wires:[["n2"]] }, var spy = sinon.stub(RED.util, 'evaluateNodeProperty',
function(arg1, arg2, arg3, arg4) { return arg1; }
);
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"flow", op1:"foo", op2:"bar", op2type:"global", duration:"100", wires:[["n2"]] },
{id:"n2", type:"helper"} ]; {id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() { helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
if (c === 0) { try {
msg.should.have.a.property("payload", "Hello"); if (c === 0) {
c += 1; msg.should.have.a.property("payload", "foo");
} c += 1;
else { }
msg.should.have.a.property("payload", "true"); else {
//console.log(Date.now() - ss); msg.should.have.a.property("payload", "bar");
(Date.now() - ss).should.be.greaterThan(149); //console.log(Date.now() - ss);
done(); (Date.now() - ss).should.be.greaterThan(149);
spy.restore();
done();
}
} }
catch(err) { spy.restore(); done(err); }
}); });
var ss = Date.now(); var ss = Date.now();
n1.emit("input", {payload:"Hello"}); n1.emit("input", {payload:"Hello"});
@@ -233,16 +397,19 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
if (c === 0) { try {
msg.should.have.a.property("payload", "Hello"); if (c === 0) {
c += 1; msg.should.have.a.property("payload", "Hello");
} c += 1;
else { }
msg.should.have.a.property("payload", "World"); else {
//console.log(Date.now() - ss); msg.should.have.a.property("payload", "World");
(Date.now() - ss).should.be.greaterThan(70); //console.log(Date.now() - ss);
done(); (Date.now() - ss).should.be.greaterThan(70);
done();
}
} }
catch(err) { done(err); }
}); });
var ss = Date.now(); var ss = Date.now();
n1.emit("input", {payload:"Hello"}); n1.emit("input", {payload:"Hello"});
@@ -263,15 +430,18 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
if (c === 0) { try {
msg.should.have.a.property("payload", "Goodbye"); if (c === 0) {
c += 1; msg.should.have.a.property("payload", "Goodbye");
} c += 1;
else { }
msg.should.have.a.property("payload", "World"); else {
(Date.now() - ss).should.be.greaterThan(70); msg.should.have.a.property("payload", "World");
done(); (Date.now() - ss).should.be.greaterThan(70);
done();
}
} }
catch(err) { done(err); }
}); });
var ss = Date.now(); var ss = Date.now();
n1.emit("input", {payload:"Hello"}); n1.emit("input", {payload:"Hello"});
@@ -292,15 +462,18 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
if (c === 0) { try {
msg.should.have.a.property("payload", "Goodbye"); if (c === 0) {
c += 1; msg.should.have.a.property("payload", "Goodbye");
} c += 1;
else { }
msg.should.have.a.property("payload", "World"); else {
(Date.now() - ss).should.be.greaterThan(70); msg.should.have.a.property("payload", "World");
done(); (Date.now() - ss).should.be.greaterThan(70);
done();
}
} }
catch(err) { done(err); }
}); });
var ss = Date.now(); var ss = Date.now();
n1.emit("input", {payload:"Hello"}); n1.emit("input", {payload:"Hello"});
@@ -321,14 +494,17 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
if (c === 0) { try {
msg.should.have.a.property("payload", "Hello"); if (c === 0) {
c+=1; msg.should.have.a.property("payload", "Hello");
} c+=1;
else { }
msg.should.have.a.property("payload", "World"); else {
done(); msg.should.have.a.property("payload", "World");
done();
}
} }
catch(err) { done(err); }
}); });
n1.emit("input", {payload:"Hello",topic:"World"}); n1.emit("input", {payload:"Hello",topic:"World"});
}); });
@@ -342,19 +518,46 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
if (c === 0) { try {
msg.should.have.a.property("payload", null); if (c === 0) {
c+=1; msg.should.have.a.property("payload", null);
} c+=1;
else { }
msg.should.have.a.property("payload", "World"); else {
done(); msg.should.have.a.property("payload", "World");
done();
}
} }
catch(err) { done(err); }
}); });
n1.emit("input", {payload:"World"}); n1.emit("input", {payload:"World"});
}); });
}); });
it('should handle string null as null on op2', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"val", op2type:"val", op1:"null", op2:"null", duration:"40", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
try {
if (c === 0) {
msg.should.have.a.property("payload", null);
c+=1;
}
else {
msg.should.have.a.property("payload", null);
done();
}
}
catch(err) { done(err); }
});
n1.emit("input", {payload:"null"});
});
});
it('should be able to set infinite timeout, and clear timeout', function(done) { it('should be able to set infinite timeout, and clear timeout', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:"0", extend: false, wires:[["n2"]] }, var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:"0", extend: false, wires:[["n2"]] },
{id:"n2", type:"helper"} ]; {id:"n2", type:"helper"} ];
@@ -363,8 +566,11 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
c += 1; try {
msg.should.have.a.property("payload", 1); c += 1;
msg.should.have.a.property("payload", "1");
}
catch(err) { done(err); }
}); });
setTimeout( function() { setTimeout( function() {
if (c === 2) { done(); } if (c === 2) { done(); }
@@ -388,8 +594,11 @@ describe('trigger node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
c += 1; try {
msg.should.have.a.property("payload", 1); c += 1;
msg.should.have.a.property("payload", "1");
}
catch(err) { done(err); }
}); });
setTimeout( function() { setTimeout( function() {
if (c === 2) { done(); } if (c === 2) { done(); }
@@ -406,7 +615,7 @@ describe('trigger node', function() {
}); });
it('should be able to set a repeat, and clear loop by reset', function(done) { it('should be able to set a repeat, and clear loop by reset', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", reset:"boo", duration:-25, wires:[["n2"]] }, var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", reset:"boo", op1:"", op1type:"pay", duration:-25, wires:[["n2"]] },
{id:"n2", type:"helper"} ]; {id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() { helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
@@ -414,9 +623,14 @@ describe('trigger node', function() {
var c = 0; var c = 0;
n2.on("input", function(msg) { n2.on("input", function(msg) {
c += 1; c += 1;
msg.should.have.a.property("payload", "foo"); try {
msg.should.have.property('payload','foo');
msg.payload = "bar"; // try to provoke pass by reference error
}
catch(err) { done(err); }
}); });
n1.emit("input", {payload:"foo"}); // trigger n1.emit("input", {payload:"foo"}); // trigger
n1.emit("input", {payload:"foo"}); // trigger
setTimeout( function() { setTimeout( function() {
n1.emit("input", {reset:true}); // reset n1.emit("input", {reset:true}); // reset
},90); },90);