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

trigger test - add missing try/catch to all test with callback

This commit is contained in:
Dave Conway-Jones 2017-09-20 09:31:11 +01:00
parent 69946f0be0
commit 32d98a7fa3
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D

View File

@ -81,14 +81,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});
}); });
@ -307,8 +310,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.
@ -326,16 +332,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", "true"); else {
//console.log(Date.now() - ss); msg.should.have.a.property("payload", "true");
(Date.now() - ss).should.be.greaterThan(149); //console.log(Date.now() - ss);
done(); (Date.now() - ss).should.be.greaterThan(149);
done();
}
} }
catch(err) { done(err); }
}); });
var ss = Date.now(); var ss = Date.now();
n1.emit("input", {payload:"Hello"}); n1.emit("input", {payload:"Hello"});
@ -353,16 +362,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"});
@ -383,15 +395,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"});
@ -412,15 +427,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"});
@ -441,14 +459,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"});
}); });
@ -462,14 +483,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", 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"});
}); });
@ -483,8 +507,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(); }
@ -508,8 +535,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(); }