Extra tests for html, xml, json and tail nodes

(and some consistent passing of missing payloads)
This commit is contained in:
dceejay
2015-03-24 17:43:47 +00:00
parent 72a9de058d
commit fcc6943f98
8 changed files with 140 additions and 60 deletions

View File

@@ -25,35 +25,39 @@ module.exports = function(RED) {
this.as = n.as || "single";
var node = this;
this.on("input", function(msg) {
try {
var $ = cheerio.load(msg.payload);
var pay = [];
$(node.tag).each(function() {
if (node.as === "multi") {
var pay2 = null;
if (node.ret === "html") { pay2 = $(this).html(); }
if (node.ret === "text") { pay2 = $(this).text(); }
//if (node.ret === "attr") { pay2 = $(this)[0]["attribs"]; }
//if (node.ret === "val") { pay2 = $(this).val(); }
if (pay2) {
msg.payload = pay2;
node.send(msg);
if (msg.hasOwnProperty("payload")) {
try {
var $ = cheerio.load(msg.payload);
var pay = [];
$(node.tag).each(function() {
if (node.as === "multi") {
var pay2 = null;
if (node.ret === "html") { pay2 = $(this).html(); }
if (node.ret === "text") { pay2 = $(this).text(); }
//if (node.ret === "attr") { pay2 = $(this)[0]["attribs"]; }
//if (node.ret === "val") { pay2 = $(this).val(); }
/* istanbul ignore else */
if (pay2) {
msg.payload = pay2;
node.send(msg);
}
}
if (node.as === "single") {
if (node.ret === "html") { pay.push( $(this).html() ); }
if (node.ret === "text") { pay.push( $(this).text() ); }
//if (node.ret === "attr") { pay.push( $(this)[0]["attribs"] ); }
//if (node.ret === "val") { pay.push( $(this).val() ); }
}
});
if ((node.as === "single") && (pay.length !== 0)) {
msg.payload = pay;
node.send(msg);
}
if (node.as === "single") {
if (node.ret === "html") { pay.push( $(this).html() ); }
if (node.ret === "text") { pay.push( $(this).text() ); }
//if (node.ret === "attr") { pay.push( $(this)[0]["attribs"] ); }
//if (node.ret === "val") { pay.push( $(this).val() ); }
}
});
if ((node.as === "single") && (pay.length !== 0)) {
msg.payload = pay;
node.send(msg);
} catch (error) {
node.error(error.message,msg);
}
} catch (error) {
node.error(error.message,msg);
}
else { node.send(msg); } // If no payload - just pass it on.
});
}
RED.nodes.registerType("html",CheerioNode);

View File

@@ -31,15 +31,15 @@ module.exports = function(RED) {
catch(e) { node.error(e.message,msg); }
}
else if (typeof msg.payload === "object") {
if (!Buffer.isBuffer(msg.payload) ) {
if (!util.isArray(msg.payload)) {
msg.payload = JSON.stringify(msg.payload);
node.send(msg);
}
if ((!Buffer.isBuffer(msg.payload)) && (!util.isArray(msg.payload))) {
msg.payload = JSON.stringify(msg.payload);
node.send(msg);
}
else { node.warn("Dropped: "+msg.payload); }
}
else { node.warn("dropped: "+msg.payload); }
else { node.warn("Dropped: "+msg.payload); }
}
else { node.send(msg); } // If no payload - just pass it on.
});
}
RED.nodes.registerType("json",JSONNode);

View File

@@ -42,6 +42,7 @@ module.exports = function(RED) {
}
else { node.warn("This node only handles xml strings or js objects."); }
}
else { node.send(msg); } // If no payload - just pass it on.
});
}
RED.nodes.registerType("xml",XMLNode);

View File

@@ -61,6 +61,7 @@ module.exports = function(RED) {
});
this.on("close", function() {
/* istanbul ignore else */
if (tail) { tail.kill(); }
});
}