mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Extra tests for html, xml, json and tail nodes
(and some consistent passing of missing payloads)
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -61,6 +61,7 @@ module.exports = function(RED) {
|
||||
});
|
||||
|
||||
this.on("close", function() {
|
||||
/* istanbul ignore else */
|
||||
if (tail) { tail.kill(); }
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user