mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Debug to status option (#1499)
* Let debug optionally target the status line (32 chars only) * Add batching of messages to debug ws comms * let Debug handle simple case of NaN would also close #1530 * Fixup debug tests for batch comms (no new tests yet) * mixup comms/api test to match new batch mode (no new tests) * Add test for NaN being sent OK. * redo original fix to padding / labels for new debug options * fix debug test (re-add fix from #1444) * Fix up merge issues in debug tests
This commit is contained in:
committed by
Nick O'Leary
parent
7bd8d8c3ae
commit
7b1787fdbb
@@ -51,10 +51,14 @@ describe('inject node', function() {
|
||||
function() {
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('topic', 't1');
|
||||
msg.should.have.property('payload');
|
||||
should(msg.payload).be.lessThan(timestamp.getTime());
|
||||
done();
|
||||
try {
|
||||
msg.should.have.property('topic', 't1');
|
||||
msg.should.have.property('payload');
|
||||
should(msg.payload).be.lessThan(timestamp.getTime());
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -25,13 +25,19 @@ describe('debug node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 55);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
||||
|
||||
it('should be loaded', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", name: "Debug", complete:"false" }];
|
||||
var flow = [{id:"n1", type:"debug", name:"Debug", complete:"false" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
n1.should.have.property('name', 'Debug');
|
||||
@@ -41,31 +47,31 @@ describe('debug node', function() {
|
||||
});
|
||||
|
||||
it('should publish on input', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", name: "Debug" }];
|
||||
var flow = [{id:"n1", type:"debug", name:"Debug" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload:"test"});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",name:"Debug",msg:"test",
|
||||
format:"string[4]",property:"payload"}
|
||||
});
|
||||
}]);
|
||||
}, 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() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var count = 0;
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload:"test"});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:"test",property:"payload",format:"string[4]"}
|
||||
});
|
||||
}]);
|
||||
count++;
|
||||
}, function() {
|
||||
try {
|
||||
@@ -86,31 +92,31 @@ describe('debug node', function() {
|
||||
});
|
||||
|
||||
it('should publish complete message', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", complete: "true" }];
|
||||
var flow = [{id:"n1", type:"debug", complete:"true" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload:"test"});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"Object"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish complete message to console', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", complete: "true", console: "true" }];
|
||||
var flow = [{id:"n1", type:"debug", complete:"true", console:"true" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload:"test"});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"Object"}
|
||||
});
|
||||
}]);
|
||||
}, function() {
|
||||
try {
|
||||
helper.log().called.should.be.true();
|
||||
@@ -129,29 +135,29 @@ describe('debug node', function() {
|
||||
});
|
||||
|
||||
it('should publish other property', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", complete: "foo" }];
|
||||
var flow = [{id:"n1", type:"debug", complete:"foo" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload:"test", foo:"bar"});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:"bar",property:"foo",format:"string[3]"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish multi-level properties', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", complete: "foo.bar" }];
|
||||
var flow = [{id:"n1", type:"debug", complete:"foo.bar" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload:"test", foo: {bar: "bar"}});
|
||||
n1.emit("input", {payload:"test", foo: {bar:"bar"}});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:"bar",property:"foo.bar",format:"string[3]"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -163,9 +169,9 @@ describe('debug node', function() {
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: new Error("oops")});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:'{"name":"Error","message":"oops"}',property:"payload",format:"error"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -177,9 +183,9 @@ describe('debug node', function() {
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: true});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg: 'true',property:"payload",format:"boolean"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -191,9 +197,23 @@ describe('debug node', function() {
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: 7});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:"7",property:"payload",format:"number"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish a NaN', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", console:"true" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: Number.NaN});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:"NaN",property:"payload",format:"number"}
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -205,9 +225,9 @@ describe('debug node', function() {
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
topic:"debug",data:{id:"n1",msg: '(undefined)',property:"payload",format:"undefined"}
|
||||
});
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:'(undefined)',property:"payload",format:"undefined"}
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -217,11 +237,11 @@ describe('debug node', function() {
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: null});
|
||||
n1.emit("input", {payload:null});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:'(undefined)',property:"payload",format:"null"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -233,10 +253,10 @@ describe('debug node', function() {
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: {type:'foo'}});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"Object"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -248,11 +268,11 @@ describe('debug node', function() {
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: [0,1,2,3]});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{id:"n1",msg: '[\n 0,\n 1,\n 2,\n 3\n]',format:"array[4]",
|
||||
property:"payload"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -266,28 +286,28 @@ describe('debug node', function() {
|
||||
o.o = o;
|
||||
n1.emit("input", {payload: o});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
msg:'{\n "name": "bar",\n "o": "[Circular ~]"\n}',
|
||||
property:"payload",format:"Object"
|
||||
}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish an object 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() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: {type:'foo'}});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"Object"}
|
||||
});
|
||||
}]);
|
||||
}, function() {
|
||||
try {
|
||||
helper.log().called.should.be.true();
|
||||
@@ -306,15 +326,15 @@ describe('debug node', function() {
|
||||
});
|
||||
|
||||
it('should publish a string after a newline to console if the string contains \\n', function(done) {
|
||||
var flow = [{id:"n1", type:"debug", console: "true"}];
|
||||
var flow = [{id:"n1", type:"debug", console:"true"}];
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: "test\ntest"});
|
||||
n1.emit("input", {payload:"test\ntest"});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:"test\ntest",property:"payload",format:"string[9]"}
|
||||
});
|
||||
}]);
|
||||
}, function() {
|
||||
try {
|
||||
helper.log().called.should.be.true();
|
||||
@@ -337,10 +357,10 @@ describe('debug node', function() {
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: Array(1002).join("X")});
|
||||
n1.emit("input", {payload:Array(1002).join("X")});
|
||||
}, function(msg) {
|
||||
var a = JSON.parse(msg);
|
||||
a.should.eql({
|
||||
a.should.eql([{
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
@@ -348,7 +368,7 @@ describe('debug node', function() {
|
||||
property:"payload",
|
||||
format:"string[1001]"
|
||||
}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -361,7 +381,7 @@ describe('debug node', function() {
|
||||
n1.emit("input", {payload: {foo: Array(1002).join("X")}});
|
||||
}, function(msg) {
|
||||
var a = JSON.parse(msg);
|
||||
a.should.eql({
|
||||
a.should.eql([{
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
@@ -369,7 +389,7 @@ describe('debug node', function() {
|
||||
property:"payload",
|
||||
format:"Object"
|
||||
}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -382,7 +402,7 @@ describe('debug node', function() {
|
||||
n1.emit("input", {payload: Array(1001).fill("X")});
|
||||
}, function(msg) {
|
||||
var a = JSON.parse(msg);
|
||||
a.should.eql({
|
||||
a.should.eql([{
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
@@ -391,11 +411,11 @@ describe('debug node', function() {
|
||||
type: "array",
|
||||
data: Array(1000).fill("X"),
|
||||
length: 1001
|
||||
},null," "),
|
||||
},null," "),
|
||||
property:"payload",
|
||||
format:"array[1001]"
|
||||
}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -408,7 +428,7 @@ describe('debug node', function() {
|
||||
n1.emit("input", {payload: {foo: Array(1001).fill("X")}});
|
||||
}, function(msg) {
|
||||
var a = JSON.parse(msg);
|
||||
a.should.eql({
|
||||
a.should.eql([{
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
@@ -423,7 +443,7 @@ describe('debug node', function() {
|
||||
property:"payload",
|
||||
format:"Object"
|
||||
}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -436,7 +456,7 @@ describe('debug node', function() {
|
||||
n1.emit("input", {payload: Buffer(501).fill("\"")});
|
||||
}, function(msg) {
|
||||
var a = JSON.parse(msg);
|
||||
a.should.eql({
|
||||
a[0].should.eql({
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
@@ -457,7 +477,7 @@ describe('debug node', function() {
|
||||
n1.emit("input", {payload: {foo: Buffer(1001).fill("X")}});
|
||||
}, function(msg) {
|
||||
var a = JSON.parse(msg);
|
||||
a.should.eql({
|
||||
a[0].should.eql({
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
@@ -482,17 +502,17 @@ describe('debug node', function() {
|
||||
helper.load(debugNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: new Buffer('HELLO', 'utf8')});
|
||||
n1.emit("input", {payload: new Buffer.from('HELLO', 'utf8')});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{
|
||||
id:"n1",
|
||||
msg: '48454c4c4f',
|
||||
msg:'48454c4c4f',
|
||||
property:"payload",
|
||||
format: "buffer[5]"
|
||||
format:"buffer[5]"
|
||||
}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -510,9 +530,9 @@ describe('debug node', function() {
|
||||
n1.emit("input", {payload:"message 2"});
|
||||
});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql({
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",data:{id:"n1",msg:"message 2",property:"payload",format:"string[9]"}
|
||||
});
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -577,8 +597,12 @@ function websocket_test(open_callback, message_callback, done_callback) {
|
||||
var close_callback = function() { ws.close(); };
|
||||
ws.on('open', function() { open_callback(close_callback); });
|
||||
ws.on('message', function(msg) {
|
||||
message_callback(msg, close_callback);
|
||||
ws.close();
|
||||
done_callback();
|
||||
try {
|
||||
message_callback(msg, close_callback);
|
||||
ws.close();
|
||||
done_callback();
|
||||
} catch(err) {
|
||||
done_callback(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -31,6 +31,13 @@ var address = '127.0.0.1';
|
||||
var listenPort = 0; // use ephemeral port
|
||||
|
||||
describe("api/comms", function() {
|
||||
|
||||
beforeEach(function (done) {
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 55);
|
||||
});
|
||||
|
||||
describe("with default keepalive", function() {
|
||||
var server;
|
||||
var url;
|
||||
@@ -72,7 +79,7 @@ describe("api/comms", function() {
|
||||
comms.publish('topic1', 'foo');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic1","data":"foo"}');
|
||||
msg.should.equal('[{"topic":"topic1","data":"foo"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -85,7 +92,8 @@ describe("api/comms", function() {
|
||||
ws.send('{"subscribe":"topic2"}');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic2","data":"bar"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic2","data":"bar"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -100,7 +108,8 @@ describe("api/comms", function() {
|
||||
comms.publish('topic3', 'new');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic3","data":"new"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic3","data":"new"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -115,7 +124,8 @@ describe("api/comms", function() {
|
||||
comms.publish('topic3', 'correct');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic3","data":"correct"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic3","data":"correct"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -133,7 +143,8 @@ describe("api/comms", function() {
|
||||
comms.publish('topic4', 'bar');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic4","data":"bar"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic4","data":"bar"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -325,7 +336,7 @@ describe("api/comms", function() {
|
||||
var ws = new WebSocket(url);
|
||||
var count = 0;
|
||||
ws.on('message', function(data) {
|
||||
var msg = JSON.parse(data);
|
||||
var msg = JSON.parse(data)[0];
|
||||
msg.should.have.property('topic','hb');
|
||||
msg.should.have.property('data').be.a.Number;
|
||||
count++;
|
||||
@@ -346,7 +357,7 @@ describe("api/comms", function() {
|
||||
}, 50);
|
||||
});
|
||||
ws.on('message', function(data) {
|
||||
var msg = JSON.parse(data);
|
||||
var msg = JSON.parse(data)[0];
|
||||
// It is possible a heartbeat message may arrive - so ignore them
|
||||
if (msg.topic != "hb") {
|
||||
msg.should.have.property('topic', 'foo');
|
||||
@@ -435,7 +446,7 @@ describe("api/comms", function() {
|
||||
ws.send('{"subscribe":"foo"}');
|
||||
comms.publish('foo', 'correct');
|
||||
} else {
|
||||
msg.should.equal('{"topic":"foo","data":"correct"}');
|
||||
msg.should.equal('[{"topic":"foo","data":"correct"}]');
|
||||
ws.close();
|
||||
}
|
||||
});
|
||||
@@ -509,7 +520,7 @@ describe("api/comms", function() {
|
||||
},200);
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"foo","data":"correct"}');
|
||||
msg.should.equal('[{"topic":"foo","data":"correct"}]');
|
||||
count++;
|
||||
ws.close();
|
||||
});
|
||||
|
Reference in New Issue
Block a user