mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Update Function catch tests to handle async receive
This commit is contained in:
		| @@ -282,13 +282,13 @@ module.exports = function(RED) { | ||||
|                         if (!errorMessage) { | ||||
|                             errorMessage = err.toString(); | ||||
|                         } | ||||
|                         this.error(errorMessage, msg); | ||||
|                         done(errorMessage); | ||||
|                     } | ||||
|                     else if (typeof err === "string") { | ||||
|                         this.error(err, msg); | ||||
|                         done(err); | ||||
|                     } | ||||
|                     else { | ||||
|                         this.error(JSON.stringify(err), msg); | ||||
|                         done(JSON.stringify(err)); | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|   | ||||
| @@ -1412,21 +1412,23 @@ describe('function node', function() { | ||||
|             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().ERROR); | ||||
|                     msg.should.have.property('id', 'n1'); | ||||
|                     msg.should.have.property('type', 'function'); | ||||
|                     msg.should.have.property('msg', 'small mistake'); | ||||
|                     done(); | ||||
|                 } catch (err) { | ||||
|                     done(err); | ||||
|                 } | ||||
|                 setTimeout(function() { | ||||
|                     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().ERROR); | ||||
|                         msg.should.have.property('id', 'n1'); | ||||
|                         msg.should.have.property('type', 'function'); | ||||
|                         msg.should.have.property('msg', 'small mistake'); | ||||
|                         done(); | ||||
|                     } catch (err) { | ||||
|                         done(err); | ||||
|                     } | ||||
|                 },50); | ||||
|             }); | ||||
|         }); | ||||
|         it('should catch thrown number', function (done) { | ||||
| @@ -1434,43 +1436,47 @@ describe('function node', function() { | ||||
|             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().ERROR); | ||||
|                     msg.should.have.property('id', 'n1'); | ||||
|                     msg.should.have.property('type', 'function'); | ||||
|                     msg.should.have.property('msg', '99'); | ||||
|                     done(); | ||||
|                 } catch (err) { | ||||
|                     done(err); | ||||
|                 } | ||||
|                 setTimeout(function() { | ||||
|                     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().ERROR); | ||||
|                         msg.should.have.property('id', 'n1'); | ||||
|                         msg.should.have.property('type', 'function'); | ||||
|                         msg.should.have.property('msg', '99'); | ||||
|                         done(); | ||||
|                     } catch (err) { | ||||
|                         done(err); | ||||
|                     } | ||||
|                 },50); | ||||
|             }); | ||||
|         }); | ||||
|         it('should catch thrown object (bad practise)', function (done) { | ||||
|         it('should catch thrown object (bad practice)', function (done) { | ||||
|             var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "throw {a:1};"}]; | ||||
|             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().ERROR); | ||||
|                     msg.should.have.property('id', 'n1'); | ||||
|                     msg.should.have.property('type', 'function'); | ||||
|                     msg.should.have.property('msg', '{"a":1}'); | ||||
|                     done(); | ||||
|                 } catch (err) { | ||||
|                     done(err); | ||||
|                 } | ||||
|                 setTimeout(function() { | ||||
|                     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().ERROR); | ||||
|                         msg.should.have.property('id', 'n1'); | ||||
|                         msg.should.have.property('type', 'function'); | ||||
|                         msg.should.have.property('msg', '{"a":1}'); | ||||
|                         done(); | ||||
|                     } catch (err) { | ||||
|                         done(err); | ||||
|                     } | ||||
|                 },50); | ||||
|             }); | ||||
|         }); | ||||
|     }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user