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

Renable unit tests following logging api changes

This commit is contained in:
Nick O'Leary 2015-01-29 09:57:09 +00:00
parent 109270b437
commit f983e4da9f
6 changed files with 180 additions and 145 deletions

View File

@ -54,34 +54,35 @@ describe('debug node', function() {
}); });
}); });
// HELEN - commenting out for now it('should publish to console', function(done) {
// it('should publish to console', function(done) { var flow = [{id:"n1", type:"debug", console: "true" }];
// var flow = [{id:"n1", type:"debug", console: "true" }]; helper.load(debugNode, flow, function() {
// helper.load(debugNode, flow, function() { var n1 = helper.getNode("n1");
// var n1 = helper.getNode("n1"); var count = 0;
// var count = 0; websocket_test(function() {
// n1.on('log', function(msg) { n1.emit("input", {payload:"test"});
// var tstmp = msg._timestamp; }, function(msg) {
// msg.should.eql({level:'log',id:'n1',type:'debug',msg:'test', _timestamp:tstmp}); JSON.parse(msg).should.eql({
// count++; topic:"debug",data:{id:"n1",msg:"test",property:"payload"}
// if (count == 2) { });
// done(); count++;
// } }, function() {
// }); try {
// websocket_test(function() { helper.log().called.should.be.true;
// n1.emit("input", {payload:"test"}); var logEvents = helper.log().args.filter(function(evt) {
// }, function(msg) { return evt[0].level == "log";
// JSON.parse(msg).should.eql({ });
// topic:"debug",data:{id:"n1",msg:"test",property:"payload"} logEvents.should.have.length(1);
// }); var tstmp = logEvents[0][0].timestamp;
// count++; logEvents[0][0].should.eql({level:'log',id:'n1',type:'debug',msg:'test', timestamp:tstmp});
// }, function() {
// if (count == 2) { done();
// done(); } catch(err) {
// } done(err);
// }); }
// }); });
// }); });
});
it('should publish complete message', function(done) { it('should publish complete message', function(done) {
var flow = [{id:"n1", type:"debug", complete: "true" }]; var flow = [{id:"n1", type:"debug", complete: "true" }];

View File

@ -131,23 +131,27 @@ describe('function node', function() {
}); });
}); });
// HELEN - commenting out for now it('should handle and log script error', function(done) {
// it('should handle and log script error', function(done) { var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"retunr"}];
// var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"retunr"}]; helper.load(functionNode, flow, function() {
// helper.load(functionNode, flow, function() { var n1 = helper.getNode("n1");
// var n1 = helper.getNode("n1"); n1.receive({payload:"foo",topic: "bar"});
// n1.on("log", function(msg) { try {
// if (msg.level === 'error') { helper.log().called.should.be.true;
// msg.should.have.property('level', 'error'); var logEvents = helper.log().args.filter(function(evt) {
// msg.should.have.property('id', 'n1'); return evt[0].level == "error";
// msg.should.have.property('type', 'function'); });
// msg.should.have.property('msg', 'ReferenceError: retunr is not defined'); logEvents.should.have.length(1);
// done(); var msg = logEvents[0][0];
// } msg.should.have.property('level', 'error');
// msg.should.have.property('id', 'n1');
// }); msg.should.have.property('type', 'function');
// n1.receive({payload:"foo",topic: "bar"}); msg.should.have.property('msg', 'ReferenceError: retunr is not defined');
// }); done();
// }); } catch(err) {
done(err);
}
});
});
}); });

View File

@ -122,29 +122,34 @@ describe('html node', function() {
}); });
}); });
}); });
// HELEN - commenting out for now
// it('should log on error', function(done) { it('should log on error', function(done) {
// fs.readFile(file,function(err, data) { fs.readFile(file,function(err, data) {
// var flow = [{id:"n1",type:"html",wires:[["n2"]],tag:"p"}, var flow = [{id:"n1",type:"html",wires:[["n2"]],tag:"p"},
// {id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];
//
// helper.load(htmlNode, flow, function() { helper.load(htmlNode, flow, function() {
// var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
// var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
// n1.on("log", function(msg) { try {
// if (msg.level && (msg.level === 'metric')) { helper.log().called.should.be.false;
// // do nothing as we've just hit a metric related msg n1.receive({payload:null,topic: "bar"});
// } else { helper.log().called.should.be.true;
// msg.should.have.property('msg'); var logEvents = helper.log().args.filter(function(evt) {
// msg.msg.indexOf("Error:").should.be.above(-1); return evt[0].level == "log";
// msg.msg.should.startWith("Error:"); });
// done(); logEvents.should.have.length(1);
// } // Each logEvent is the array of args passed to the function.
// }); logEvents[0][0].should.have.a.property('msg');
// n1.receive({payload:null,topic: "bar"}); logEvents[0][0].msg.should.startWith("Error:");
// });
// }); done();
// }); } catch(err) {
done(err);
}
});
});
});
describe('multiple messages', function(){ describe('multiple messages', function(){
var cnt = 0; var cnt = 0;

View File

@ -70,43 +70,49 @@ describe('JSON node', function() {
jn1.receive({payload:obj,topic: "bar"}); jn1.receive({payload:obj,topic: "bar"});
}); });
}); });
// HELEN - commenting out for now
// it('should log an error if asked to parse an invalid json string', function(done) { it('should log an error if asked to parse an invalid json string', function(done) {
// var flow = [{id:"jn1",type:"json",wires:[["jn2"]],func:"return msg;"}, var flow = [{id:"jn1",type:"json",wires:[["jn2"]],func:"return msg;"},
// {id:"jn2", type:"helper"}]; {id:"jn2", type:"helper"}];
// helper.load(jsonNode, flow, function() { helper.load(jsonNode, flow, function() {
// var jn1 = helper.getNode("jn1"); try {
// var jn2 = helper.getNode("jn2"); helper.log().called.should.be.false;
// jn1.on("log", function(msg) { var jn1 = helper.getNode("jn1");
// if (msg.level && (msg.level === 'metric')) { var jn2 = helper.getNode("jn2");
// // do nothing as we've just hit a metric related msg jn1.receive({payload:'foo',topic: "bar"});
// } else { helper.log().called.should.be.true;
// msg.should.have.property('msg'); var logEvents = helper.log().args.filter(function(evt) {
// should.deepEqual("SyntaxError: Unexpected token o"+ "\nfoo", msg.msg); return evt[0].level == "log";
// done(); });
// } logEvents.should.have.length(1);
// }); logEvents[0][0].should.have.a.property('msg',"SyntaxError: Unexpected token o"+ "\nfoo");
// jn1.receive({payload:'foo',topic: "bar"}); done();
// }); } catch(err) {
// }); done(err);
// HELEN - commenting out for now }
// it('should log an error if asked to parse something thats not json or js', function(done) { });
// var flow = [{id:"jn1",type:"json",wires:[["jn2"]],func:"return msg;"}, });
// {id:"jn2", type:"helper"}];
// helper.load(jsonNode, flow, function() { it('should log an error if asked to parse something thats not json or js', function(done) {
// var jn1 = helper.getNode("jn1"); var flow = [{id:"jn1",type:"json",wires:[["jn2"]],func:"return msg;"},
// var jn2 = helper.getNode("jn2"); {id:"jn2", type:"helper"}];
// jn1.on("log", function(msg) { helper.load(jsonNode, flow, function() {
// if (msg.level && (msg.level === 'metric')) { try {
// // do nothing as we've just hit a metric related msg helper.log().called.should.be.false;
// } else { var jn1 = helper.getNode("jn1");
// msg.should.have.property('msg'); var jn2 = helper.getNode("jn2");
// should.deepEqual("dropped: 1", msg.msg); jn1.receive({payload:1,topic: "bar"});
// done(); helper.log().called.should.be.true;
// } var logEvents = helper.log().args.filter(function(evt) {
// }); return evt[0].level == "log";
// jn1.receive({payload:1,topic: "bar"}); });
// }); logEvents.should.have.length(1);
// }); logEvents[0][0].should.have.a.property('msg',"dropped: 1");
done();
} catch(err) {
done(err);
}
});
});
}); });

View File

@ -74,41 +74,53 @@ describe('XML node', function() {
n1.receive({payload:obj,topic: "bar"}); n1.receive({payload:obj,topic: "bar"});
}); });
}); });
// HELEN - commenting out for now
// it('should log an error if asked to parse an invalid xml string', function(done) { it('should log an error if asked to parse an invalid xml string', function(done) {
// var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"}, var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
// {id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];
// helper.load(xmlNode, flow, function() { helper.load(xmlNode, flow, function() {
// var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
// var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
// n1.on("log", function(msg) { n1.receive({payload:'<not valid xml>',topic: "bar"});
// if (msg.level && (msg.level === 'metric')) { setTimeout(function() {
// // do nothing as we've just hit a metric related msg try {
// } else { helper.log().called.should.be.true;
// should.deepEqual("error", msg.level); var logEvents = helper.log().args.filter(function(evt) {
// done(); return evt[0].level == "error";
// } });
// }); logEvents.should.have.length(1);
// n1.receive({payload:'<not valid xml>',topic: "bar"}); logEvents[0][0].should.have.a.property('msg');
// }); logEvents[0][0].msg.toString().should.startWith("Error: Attribute without value");
// });
// HELEN - commenting out for now done();
// it('should log an error if asked to parse something thats not xml or js', function(done) { } catch(err) {
// var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"}, done(err);
// {id:"n2", type:"helper"}]; }
// helper.load(xmlNode, flow, function() { },200);
// var n1 = helper.getNode("n1"); });
// var n2 = helper.getNode("n2"); });
// n1.on("log", function(msg) {
// if (msg.level && (msg.level === 'metric')) { it('should log an error if asked to parse something thats not xml or js', function(done) {
// // do nothing as we've just hit a metric related msg var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
// } else {msg.should.have.property('msg'); {id:"n2", type:"helper"}];
// should.deepEqual("This node only handles xml strings or js objects.", msg.msg); helper.load(xmlNode, flow, function() {
// done(); var n1 = helper.getNode("n1");
// } var n2 = helper.getNode("n2");
// }); n1.receive({payload:1,topic: "bar"});
// n1.receive({payload:1,topic: "bar"}); setTimeout(function() {
// }); try {
// }); helper.log().called.should.be.true;
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].level == "log";
});
logEvents.should.have.length(1);
logEvents[0][0].should.have.a.property('msg',"This node only handles xml strings or js objects.");
done();
} catch(err) {
done(err);
}
},200);
});
});
}); });

View File

@ -15,6 +15,7 @@
**/ **/
var should = require("should"); var should = require("should");
var sinon = require("sinon");
var when = require("when"); var when = require("when");
var request = require('supertest'); var request = require('supertest');
var nock; var nock;
@ -32,6 +33,7 @@ var redNodes = require("../../red/nodes");
var flows = require("../../red/nodes/flows"); var flows = require("../../red/nodes/flows");
var credentials = require("../../red/nodes/credentials"); var credentials = require("../../red/nodes/credentials");
var comms = require("../../red/comms.js"); var comms = require("../../red/comms.js");
var log = require("../../red/log.js");
var http = require('http'); var http = require('http');
var express = require('express'); var express = require('express');
@ -41,7 +43,7 @@ var address = '127.0.0.1';
var listenPort = 0; // use ephemeral port var listenPort = 0; // use ephemeral port
var port; var port;
var url; var url;
var logSpy;
var server; var server;
function helperNode(n) { function helperNode(n) {
@ -50,6 +52,8 @@ function helperNode(n) {
module.exports = { module.exports = {
load: function(testNode, testFlows, testCredentials, cb) { load: function(testNode, testFlows, testCredentials, cb) {
logSpy = sinon.spy(log,"log");
if (typeof testCredentials === 'function') { if (typeof testCredentials === 'function') {
cb = testCredentials; cb = testCredentials;
testCredentials = {}; testCredentials = {};
@ -92,6 +96,7 @@ module.exports = {
unload: function() { unload: function() {
// TODO: any other state to remove between tests? // TODO: any other state to remove between tests?
redNodes.clearRegistry(); redNodes.clearRegistry();
logSpy.restore();
return flows.stopFlows(); return flows.stopFlows();
}, },
@ -131,4 +136,6 @@ module.exports = {
nock: nock, nock: nock,
log: function() { return logSpy;}
}; };