2014-07-29 13:10:20 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2014-07-29 13:10:20 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
var should = require("should");
|
2019-07-10 00:32:22 +02:00
|
|
|
var debugNode = require("nr-test-utils").require("@node-red/nodes/core/common/21-debug.js");
|
2018-03-02 05:41:16 +01:00
|
|
|
var helper = require("node-red-node-test-helper");
|
2014-07-29 13:10:20 +02:00
|
|
|
var WebSocket = require('ws');
|
|
|
|
|
|
|
|
describe('debug node', function() {
|
|
|
|
|
|
|
|
before(function(done) {
|
|
|
|
helper.startServer(done);
|
|
|
|
});
|
2014-10-01 10:50:47 +02:00
|
|
|
|
2018-04-23 13:37:26 +02:00
|
|
|
after(function(done) {
|
|
|
|
helper.stopServer(done);
|
|
|
|
});
|
|
|
|
|
2018-01-13 17:14:03 +01:00
|
|
|
beforeEach(function (done) {
|
|
|
|
setTimeout(function() {
|
|
|
|
done();
|
|
|
|
}, 55);
|
|
|
|
});
|
|
|
|
|
2014-08-01 23:05:49 +02:00
|
|
|
afterEach(function() {
|
|
|
|
helper.unload();
|
|
|
|
});
|
|
|
|
|
2014-07-29 13:10:20 +02:00
|
|
|
|
|
|
|
it('should be loaded', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", name:"Debug", complete:"false" }];
|
2014-07-29 13:10:20 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
n1.should.have.property('name', 'Debug');
|
2015-03-22 10:38:42 +01:00
|
|
|
n1.should.have.property('complete', "payload");
|
2014-07-29 13:10:20 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should publish on input', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", name:"Debug" }];
|
2014-07-29 13:10:20 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload:"test"});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2015-03-20 23:09:58 +01:00
|
|
|
topic:"debug",data:{id:"n1",name:"Debug",msg:"test",
|
2016-11-02 16:12:30 +01:00
|
|
|
format:"string[4]",property:"payload"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-29 10:57:09 +01:00
|
|
|
it('should publish to console', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", console:"true"}];
|
2015-01-29 10:57:09 +01:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
var count = 0;
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload:"test"});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2016-11-02 16:12:30 +01:00
|
|
|
topic:"debug",data:{id:"n1",msg:"test",property:"payload",format:"string[4]"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2015-01-29 10:57:09 +01:00
|
|
|
count++;
|
|
|
|
}, function() {
|
|
|
|
try {
|
2016-10-10 14:27:43 +02:00
|
|
|
helper.log().called.should.be.true();
|
2015-01-29 10:57:09 +01:00
|
|
|
var logEvents = helper.log().args.filter(function(evt) {
|
2015-02-03 23:02:26 +01:00
|
|
|
return evt[0].type == "debug";
|
2015-01-29 10:57:09 +01:00
|
|
|
});
|
|
|
|
logEvents.should.have.length(1);
|
|
|
|
var tstmp = logEvents[0][0].timestamp;
|
2015-02-03 23:02:26 +01:00
|
|
|
logEvents[0][0].should.eql({level:helper.log().INFO, id:'n1',type:'debug',msg:'test', timestamp:tstmp});
|
2015-01-29 10:57:09 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
} catch(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-07-29 13:10:20 +02:00
|
|
|
|
|
|
|
it('should publish complete message', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", complete:"true" }];
|
2014-07-29 13:10:20 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload:"test"});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2014-07-29 13:10:20 +02:00
|
|
|
topic:"debug",
|
2015-10-10 23:41:07 +02:00
|
|
|
data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"Object"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-12 21:47:13 +02:00
|
|
|
it('should publish complete message to console', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", complete:"true", console:"true" }];
|
2017-10-12 21:47:13 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload:"test"});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"Object"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, function() {
|
|
|
|
try {
|
|
|
|
helper.log().called.should.be.true();
|
|
|
|
var logEvents = helper.log().args.filter(function(evt) {
|
|
|
|
return evt[0].type == "debug";
|
|
|
|
});
|
|
|
|
logEvents.should.have.length(1);
|
|
|
|
var tstmp = logEvents[0][0].timestamp;
|
|
|
|
logEvents[0][0].should.eql({level:helper.log().INFO, id:"n1",type:"debug",msg:'\n{ payload: \'test\' }',timestamp:tstmp});
|
|
|
|
done();
|
|
|
|
} catch(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-01 10:50:47 +02:00
|
|
|
it('should publish other property', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", complete:"foo" }];
|
2014-10-01 10:50:47 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload:"test", foo:"bar"});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2016-11-02 16:12:30 +01:00
|
|
|
topic:"debug",data:{id:"n1",msg:"bar",property:"foo",format:"string[3]"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-10-01 10:50:47 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should publish multi-level properties', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", complete:"foo.bar" }];
|
2014-10-01 10:50:47 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
2018-01-13 17:14:03 +01:00
|
|
|
n1.emit("input", {payload:"test", foo: {bar:"bar"}});
|
2014-10-01 10:50:47 +02:00
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2016-11-02 16:12:30 +01:00
|
|
|
topic:"debug",data:{id:"n1",msg:"bar",property:"foo.bar",format:"string[3]"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-10-01 10:50:47 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-29 13:10:20 +02:00
|
|
|
it('should publish an Error', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: new Error("oops")});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2017-01-14 22:47:18 +01:00
|
|
|
topic:"debug",data:{id:"n1",msg:'{"name":"Error","message":"oops"}',property:"payload",format:"error"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should publish a boolean', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: true});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2015-03-20 23:09:58 +01:00
|
|
|
topic:"debug",data:{id:"n1",msg: 'true',property:"payload",format:"boolean"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-12 21:47:13 +02:00
|
|
|
it('should publish a number', 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: 7});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",data:{id:"n1",msg:"7",property:"payload",format:"number"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
|
|
|
}, 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"}
|
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-29 13:10:20 +02:00
|
|
|
it('should publish with no payload', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
|
|
|
topic:"debug",data:{id:"n1",msg:'(undefined)',property:"payload",format:"undefined"}
|
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-12 21:47:13 +02:00
|
|
|
it('should publish a null', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
2018-01-13 17:14:03 +01:00
|
|
|
n1.emit("input", {payload:null});
|
2017-10-12 21:47:13 +02:00
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",data:{id:"n1",msg:'(undefined)',property:"payload",format:"null"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-29 13:10:20 +02:00
|
|
|
it('should publish an object', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: {type:'foo'}});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2014-07-29 13:10:20 +02:00
|
|
|
topic:"debug",
|
2015-10-10 23:41:07 +02:00
|
|
|
data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"Object"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should publish an array', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: [0,1,2,3]});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2014-07-29 13:10:20 +02:00
|
|
|
topic:"debug",
|
2016-10-27 17:59:16 +02:00
|
|
|
data:{id:"n1",msg: '[\n 0,\n 1,\n 2,\n 3\n]',format:"array[4]",
|
2014-10-01 10:50:47 +02:00
|
|
|
property:"payload"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should publish an object with circular references', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
var o = { name: 'bar' };
|
|
|
|
o.o = o;
|
|
|
|
n1.emit("input", {payload: o});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2014-07-29 13:10:20 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
2016-12-21 00:21:25 +01:00
|
|
|
msg:'{\n "name": "bar",\n "o": "[Circular ~]"\n}',
|
2015-10-10 23:41:07 +02:00
|
|
|
property:"payload",format:"Object"
|
2014-07-29 13:10:20 +02:00
|
|
|
}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-12 21:47:13 +02:00
|
|
|
it('should publish an object to console', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", console:"true"}];
|
2017-10-12 21:47:13 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: {type:'foo'}});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"Object"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, function() {
|
|
|
|
try {
|
|
|
|
helper.log().called.should.be.true();
|
|
|
|
var logEvents = helper.log().args.filter(function(evt) {
|
|
|
|
return evt[0].type == "debug";
|
|
|
|
});
|
|
|
|
logEvents.should.have.length(1);
|
|
|
|
var tstmp = logEvents[0][0].timestamp;
|
|
|
|
logEvents[0][0].should.eql({level:helper.log().INFO,id:"n1",type:"debug",msg:'\n{ type: \'foo\' }',timestamp:tstmp});
|
|
|
|
done();
|
|
|
|
} catch(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should publish a string after a newline to console if the string contains \\n', function(done) {
|
2018-01-13 17:14:03 +01:00
|
|
|
var flow = [{id:"n1", type:"debug", console:"true"}];
|
2017-10-12 21:47:13 +02:00
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
2018-01-13 17:14:03 +01:00
|
|
|
n1.emit("input", {payload:"test\ntest"});
|
2017-10-12 21:47:13 +02:00
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",data:{id:"n1",msg:"test\ntest",property:"payload",format:"string[9]"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, function() {
|
|
|
|
try {
|
|
|
|
helper.log().called.should.be.true();
|
|
|
|
var logEvents = helper.log().args.filter(function(evt) {
|
|
|
|
return evt[0].type == "debug";
|
|
|
|
});
|
|
|
|
logEvents.should.have.length(1);
|
|
|
|
var tstmp = logEvents[0][0].timestamp;
|
|
|
|
logEvents[0][0].should.eql({level:helper.log().INFO,id:"n1",type:"debug",msg:"\ntest\ntest",timestamp:tstmp});
|
|
|
|
done();
|
|
|
|
} catch(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-01 18:03:04 +01:00
|
|
|
it('should publish complete message with edit', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug", name:"Debug", complete: "true",
|
2018-12-09 12:30:35 +01:00
|
|
|
targetType: "jsonata", complete: '"<" & payload & ">"'}];
|
2018-12-01 18:03:04 +01:00
|
|
|
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([{
|
|
|
|
topic:"debug",data:{id:"n1",name:"Debug",msg:"<test>",
|
|
|
|
format:"string[6]"}
|
|
|
|
}]);
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-10-27 17:59:16 +02:00
|
|
|
it('should truncate a long message', function(done) {
|
2014-07-29 13:10:20 +02:00
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
2018-01-13 17:14:03 +01:00
|
|
|
n1.emit("input", {payload:Array(1002).join("X")});
|
2014-07-29 13:10:20 +02:00
|
|
|
}, function(msg) {
|
2015-03-20 23:09:58 +01:00
|
|
|
var a = JSON.parse(msg);
|
2018-01-13 17:14:03 +01:00
|
|
|
a.should.eql([{
|
2014-07-29 13:10:20 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
2016-10-27 17:59:16 +02:00
|
|
|
msg: Array(1001).join("X")+'...',
|
2015-03-20 23:09:58 +01:00
|
|
|
property:"payload",
|
2016-11-02 16:12:30 +01:00
|
|
|
format:"string[1001]"
|
2014-07-29 13:10:20 +02:00
|
|
|
}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-12 21:47:13 +02:00
|
|
|
it('should truncate a long string in the object', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug"}];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: {foo: Array(1002).join("X")}});
|
|
|
|
}, function(msg) {
|
|
|
|
var a = JSON.parse(msg);
|
2018-01-13 17:14:03 +01:00
|
|
|
a.should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
|
|
|
msg:'{\n "foo": "'+Array(1001).join("X")+'..."\n}',
|
|
|
|
property:"payload",
|
|
|
|
format:"Object"
|
|
|
|
}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should truncate a large array', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: Array(1001).fill("X")});
|
|
|
|
}, function(msg) {
|
|
|
|
var a = JSON.parse(msg);
|
2018-01-13 17:14:03 +01:00
|
|
|
a.should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
|
|
|
msg:JSON.stringify({
|
2018-07-15 00:18:55 +02:00
|
|
|
__enc__: true,
|
2017-10-12 21:47:13 +02:00
|
|
|
type: "array",
|
|
|
|
data: Array(1000).fill("X"),
|
|
|
|
length: 1001
|
2018-01-13 17:14:03 +01:00
|
|
|
},null," "),
|
2017-10-12 21:47:13 +02:00
|
|
|
property:"payload",
|
|
|
|
format:"array[1001]"
|
|
|
|
}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should truncate a large array in the object', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug"}];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: {foo: Array(1001).fill("X")}});
|
|
|
|
}, function(msg) {
|
|
|
|
var a = JSON.parse(msg);
|
2018-01-13 17:14:03 +01:00
|
|
|
a.should.eql([{
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
|
|
|
msg:JSON.stringify({
|
|
|
|
foo:{
|
2018-07-15 00:18:55 +02:00
|
|
|
__enc__: true,
|
2017-10-12 21:47:13 +02:00
|
|
|
type: "array",
|
|
|
|
data: Array(1000).fill("X"),
|
|
|
|
length: 1001
|
|
|
|
}
|
|
|
|
},null," "),
|
|
|
|
property:"payload",
|
|
|
|
format:"Object"
|
|
|
|
}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2017-10-12 21:47:13 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should truncate a large buffer', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: Buffer(501).fill("\"")});
|
|
|
|
}, function(msg) {
|
|
|
|
var a = JSON.parse(msg);
|
2018-01-13 17:14:03 +01:00
|
|
|
a[0].should.eql({
|
2017-10-12 21:47:13 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
|
|
|
msg: Array(1001).join("2"),
|
|
|
|
property:"payload",
|
|
|
|
format:"buffer[501]"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-23 12:13:28 +02:00
|
|
|
it('should truncate a large buffer in the object', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug"}];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload: {foo: Buffer(1001).fill("X")}});
|
|
|
|
}, function(msg) {
|
|
|
|
var a = JSON.parse(msg);
|
2018-01-13 17:14:03 +01:00
|
|
|
a[0].should.eql({
|
2017-10-23 12:13:28 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
|
|
|
msg:JSON.stringify({
|
|
|
|
foo:{
|
|
|
|
type: "Buffer",
|
|
|
|
data: Array(1000).fill(88),
|
2018-07-15 00:18:55 +02:00
|
|
|
__enc__: true,
|
2017-10-23 12:13:28 +02:00
|
|
|
length: 1001
|
|
|
|
}
|
|
|
|
},null," "),
|
|
|
|
property:"payload",
|
|
|
|
format:"Object"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-29 13:10:20 +02:00
|
|
|
it('should convert Buffer to hex', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug" }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
2018-10-24 14:45:34 +02:00
|
|
|
n1.emit("input", {payload: Buffer.from('HELLO', 'utf8')});
|
2014-07-29 13:10:20 +02:00
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2014-07-29 13:10:20 +02:00
|
|
|
topic:"debug",
|
|
|
|
data:{
|
|
|
|
id:"n1",
|
2018-01-13 17:14:03 +01:00
|
|
|
msg:'48454c4c4f',
|
2015-03-20 23:09:58 +01:00
|
|
|
property:"payload",
|
2018-01-13 17:14:03 +01:00
|
|
|
format:"buffer[5]"
|
2014-07-29 13:10:20 +02:00
|
|
|
}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should publish when active', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug", active: false }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function() {
|
|
|
|
n1.emit("input", {payload:"message 1"});
|
|
|
|
helper.request()
|
|
|
|
.post('/debug/n1/enable')
|
2014-09-30 15:59:37 +02:00
|
|
|
.expect(200).end(function(err) {
|
|
|
|
if (err) { return done(err); }
|
2014-07-29 13:10:20 +02:00
|
|
|
n1.emit("input", {payload:"message 2"});
|
|
|
|
});
|
|
|
|
}, function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
JSON.parse(msg).should.eql([{
|
2016-11-02 16:12:30 +01:00
|
|
|
topic:"debug",data:{id:"n1",msg:"message 2",property:"payload",format:"string[9]"}
|
2018-01-13 17:14:03 +01:00
|
|
|
}]);
|
2014-07-29 13:10:20 +02:00
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not publish when inactive', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug", active: true }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
websocket_test(function(close) {
|
|
|
|
helper.request()
|
|
|
|
.post('/debug/n1/disable')
|
2014-09-30 15:59:37 +02:00
|
|
|
.expect(201).end(function(err) {
|
|
|
|
if (err) {
|
|
|
|
close();
|
|
|
|
return done(err);
|
|
|
|
}
|
2014-07-29 13:10:20 +02:00
|
|
|
n1.emit("input", {payload:"message"});
|
|
|
|
setTimeout(function() {
|
|
|
|
close();
|
|
|
|
done();
|
|
|
|
}, 200);
|
|
|
|
});
|
|
|
|
}, function(msg) {
|
|
|
|
should.fail(null,null,"unexpected message");
|
|
|
|
}, function() {});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('post', function() {
|
|
|
|
it('should return 404 on invalid state', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug", active: true }];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
helper.request()
|
|
|
|
.post('/debug/n1/foobar')
|
|
|
|
.expect(404).end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return 404 on invalid node', function(done) {
|
|
|
|
helper.request()
|
|
|
|
.post('/debug/n99/enable')
|
|
|
|
.expect(404).end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-12 21:47:13 +02:00
|
|
|
describe('get', function() {
|
|
|
|
it('should return the view.html', function(done) {
|
|
|
|
var flow = [{id:"n1", type:"debug"}];
|
|
|
|
helper.load(debugNode, flow, function() {
|
|
|
|
helper.request()
|
|
|
|
.get('/debug/view/view.html')
|
|
|
|
.expect(200)
|
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-29 13:10:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function websocket_test(open_callback, message_callback, done_callback) {
|
|
|
|
var ws = new WebSocket(helper.url() + "/comms");
|
|
|
|
var close_callback = function() { ws.close(); };
|
|
|
|
ws.on('open', function() { open_callback(close_callback); });
|
|
|
|
ws.on('message', function(msg) {
|
2018-01-13 17:14:03 +01:00
|
|
|
try {
|
|
|
|
message_callback(msg, close_callback);
|
|
|
|
ws.close();
|
|
|
|
done_callback();
|
|
|
|
} catch(err) {
|
|
|
|
done_callback(err);
|
|
|
|
}
|
2014-07-29 13:10:20 +02:00
|
|
|
});
|
|
|
|
}
|