mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add tail node binary mode test
This commit is contained in:
parent
d3a98dd355
commit
0d1543ee8a
@ -28,7 +28,7 @@ module.exports = function(RED) {
|
||||
|
||||
this.filename = n.filename;
|
||||
this.filetype = n.filetype || "text";
|
||||
this.split = n.split;
|
||||
this.split = n.split || false;
|
||||
var node = this;
|
||||
|
||||
var err = "";
|
||||
@ -36,7 +36,7 @@ module.exports = function(RED) {
|
||||
var tail = spawn("tail", ["-F", "-n", "0", this.filename]);
|
||||
tail.stdout.on("data", function (data) {
|
||||
var msg = { topic:node.filename };
|
||||
if (this.filetype === "text") {
|
||||
if (node.filetype === "text") {
|
||||
if (node.split) {
|
||||
// TODO: allow customisation of the line break - as we do elsewhere
|
||||
var strings = data.toString().split("\n");
|
||||
|
@ -88,6 +88,24 @@ describe('tail Node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work in binary mode', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "filetype":"binary", "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
//console.log(msg);
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
msg.payload.toString().should.equal("Tail message line 7\nTail message line 8\n");
|
||||
done();
|
||||
});
|
||||
setTimeout( function() {
|
||||
fs.appendFileSync(fileToTail, "Tail message line 7\nTail message line 8\n");
|
||||
},wait);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle a non-existent file', function(done) {
|
||||
fs.writeFileSync(fileToTail, "Tail message line.\n");
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
|
Loading…
Reference in New Issue
Block a user