mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'master' into dev
This commit is contained in:
@@ -541,13 +541,17 @@ describe('exec node', function() {
|
||||
var n2 = helper.getNode("n2");
|
||||
var n3 = helper.getNode("n3");
|
||||
var n4 = helper.getNode("n4");
|
||||
var payload = "";
|
||||
n2.on("input", function(msg) {
|
||||
//console.log(msg);
|
||||
try {
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.should.be.a.String();
|
||||
msg.payload.should.equal(expected);
|
||||
done();
|
||||
payload += msg.payload;
|
||||
if (payload.endsWith("\n")) {
|
||||
payload.should.equal(expected);
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(err) { done(err); }
|
||||
});
|
||||
@@ -567,6 +571,7 @@ describe('exec node', function() {
|
||||
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
|
||||
expected = "12345 deg C\n";
|
||||
}
|
||||
var payload = "";
|
||||
|
||||
helper.load(execNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
@@ -578,8 +583,11 @@ describe('exec node', function() {
|
||||
try {
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.should.be.a.String();
|
||||
msg.payload.should.equal(expected);
|
||||
done();
|
||||
payload += msg.payload;
|
||||
if (payload.endsWith("\n")) {
|
||||
payload.should.equal(expected);
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(err) { done(err); }
|
||||
});
|
||||
@@ -661,8 +669,16 @@ describe('exec node', function() {
|
||||
};
|
||||
|
||||
n2.on("input", function(msg) {
|
||||
messages[0] = msg;
|
||||
completeTest();
|
||||
var payload = msg.payload;
|
||||
if (messages[0]) {
|
||||
messages[0].payload += payload;
|
||||
}
|
||||
else {
|
||||
messages[0] = msg;
|
||||
}
|
||||
if (payload.endsWith("\n")) {
|
||||
completeTest();
|
||||
}
|
||||
});
|
||||
n4.on("input", function(msg) {
|
||||
messages[1] = msg;
|
||||
@@ -869,8 +885,16 @@ describe('exec node', function() {
|
||||
};
|
||||
|
||||
n2.on("input", function(msg) {
|
||||
messages[0] = msg;
|
||||
completeTest();
|
||||
var payload = msg.payload;
|
||||
if (messages[0]) {
|
||||
messages[0].payload += payload;
|
||||
}
|
||||
else {
|
||||
messages[0] = msg;
|
||||
}
|
||||
if (payload.endsWith("\n")) {
|
||||
completeTest();
|
||||
}
|
||||
});
|
||||
n4.on("input", function(msg) {
|
||||
messages[1] = msg;
|
||||
|
@@ -87,6 +87,57 @@ describe('CSV node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a simple string to a javascript object with | separator (no template)', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", sep:"|", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(csvNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', { col1: 1, col2: 2, col3: 3, col4: 4 });
|
||||
msg.should.have.property('columns', "col1,col2,col3,col4");
|
||||
check_parts(msg, 0, 1);
|
||||
done();
|
||||
});
|
||||
var testString = "1|2|3|4"+String.fromCharCode(10);
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a simple string to a javascript object with tab separator (with template)', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", sep:"\t", temp:"A,B,,D", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(csvNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', { A: 1, B: 2, D: 4 });
|
||||
msg.should.have.property('columns', "A,B,D");
|
||||
check_parts(msg, 0, 1);
|
||||
done();
|
||||
});
|
||||
var testString = "1\t2\t3\t4"+String.fromCharCode(10);
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a simple string to a javascript object with space separator (with spaced template)', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", sep:" ", temp:"A, B, , D", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(csvNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', { A: 1, B: 2, D: 4 });
|
||||
msg.should.have.property('columns', "A,B,D");
|
||||
check_parts(msg, 0, 1);
|
||||
done();
|
||||
});
|
||||
var testString = "1 2 3 4"+String.fromCharCode(10);
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove quotes and whitespace from template', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:'"a", "b" , " c "," d " ', wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
@@ -170,6 +221,58 @@ describe('CSV node', function() {
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow passing in a template as first line of CSV (not comma)', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"", hdrin:true, sep:";", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(csvNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', { a: 1, "b b":2, "c;c":3, "d, d": 4 });
|
||||
msg.should.have.property('columns', 'a,b b,c;c,"d, d"');
|
||||
check_parts(msg, 0, 1);
|
||||
done();
|
||||
});
|
||||
var testString = 'a;b b;"c;c";" d, d "'+"\n"+"1;2;3;4"+String.fromCharCode(10);
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow passing in a template as first line of CSV (special char /)', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"", hdrin:true, sep:"/", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(csvNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', { a: 1, "b b":2, "c/c":3, "d, d": 4 });
|
||||
msg.should.have.property('columns', 'a,b b,c/c,"d, d"');
|
||||
check_parts(msg, 0, 1);
|
||||
done();
|
||||
});
|
||||
var testString = 'a/b b/"c/c"/" d, d "'+"\n"+"1/2/3/4"+String.fromCharCode(10);
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow passing in a template as first line of CSV (special char \\)', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"", hdrin:true, sep:"\\", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(csvNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', { a: 1, "b b":2, "c\\c":3, "d, d": 4 });
|
||||
msg.should.have.property('columns', 'a,b b,c\\c,"d, d"');
|
||||
check_parts(msg, 0, 1);
|
||||
done();
|
||||
});
|
||||
var testString = 'a\\b b\\"c\\c"\\" d, d "'+"\n"+"1\\2\\3\\4"+String.fromCharCode(10);
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should leave numbers starting with 0, e and + as strings (except 0.)', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e,f,g", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
@@ -609,6 +712,24 @@ describe('CSV node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a simple object back to a tsv using a tab as a separator', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"", sep:"\t", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(csvNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('payload', '1\tfoo\t"ba""r"\tdi,ng\n');
|
||||
done();
|
||||
}
|
||||
catch(e) { done(e); }
|
||||
});
|
||||
var testJson = { d:1, b:"foo", c:"ba\"r", a:"di,ng" };
|
||||
n1.emit("input", {payload:testJson});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle a template with spaces in the property names', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"a,b o,c p,,e", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
|
Reference in New Issue
Block a user