From 0d1543ee8a817290a35143146f38838c37dedc28 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 25 Feb 2016 08:52:43 +0000 Subject: [PATCH] Add tail node binary mode test --- nodes/core/storage/28-tail.js | 4 ++-- test/nodes/core/storage/28-tail_spec.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nodes/core/storage/28-tail.js b/nodes/core/storage/28-tail.js index 824824885..017a9a89d 100644 --- a/nodes/core/storage/28-tail.js +++ b/nodes/core/storage/28-tail.js @@ -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"); diff --git a/test/nodes/core/storage/28-tail_spec.js b/test/nodes/core/storage/28-tail_spec.js index fcd185295..c291773c9 100644 --- a/test/nodes/core/storage/28-tail_spec.js +++ b/test/nodes/core/storage/28-tail_spec.js @@ -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"]]},