mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Modify Tail node to only send new messages
Now with test that works with it. Part of Issue #326 Now need to redo with libs that support windows.
This commit is contained in:
@@ -23,14 +23,17 @@ var tailNode = require("../../../../nodes/core/storage/28-tail.js");
|
||||
var helper = require("../../helper.js");
|
||||
|
||||
describe('TailNode', function() {
|
||||
|
||||
|
||||
var resourcesDir = path.join(__dirname,"..","..","..","resources");
|
||||
var fileToTail = path.join(resourcesDir,"28-tail-test-file.txt");
|
||||
|
||||
fs.writeFile(fileToTail, "Tail message line 1\nTail message line 2\n", function (err) {
|
||||
if (err) { console.log('cannot write to '+fileToTail); }
|
||||
});
|
||||
|
||||
beforeEach(function(done) {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
|
||||
afterEach(function(done) {
|
||||
helper.unload();
|
||||
helper.stopServer(done);
|
||||
@@ -44,8 +47,8 @@ describe('TailNode', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should tail a file', function(done) {
|
||||
|
||||
it('tail should tail a file', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
@@ -53,27 +56,57 @@ describe('TailNode', function() {
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
var inputCounter = 0;
|
||||
helperNode1.on("input", function(msg) {
|
||||
console.log(msg);
|
||||
//console.log(msg);
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
msg.payload.should.equal("Tail message line" + (++inputCounter));
|
||||
if(inputCounter === 2) {
|
||||
msg.payload.should.equal("Tail message line " + (++inputCounter + 2));
|
||||
if (inputCounter === 2) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
fs.appendFileSync(fileToTail, "Tail message line 3\nTail message line 4\n");
|
||||
});
|
||||
});
|
||||
|
||||
it('work in non-split mode', function(done) {
|
||||
|
||||
it('tail should work in non-split mode', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":false, "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.should.equal("Tail message line1\nTail message line2\n");
|
||||
msg.payload.should.equal("Tail message line 5\nTail message line 6\n");
|
||||
done();
|
||||
});
|
||||
fs.appendFile(fileToTail, "Tail message line 5\nTail message line 6\n");
|
||||
});
|
||||
});
|
||||
|
||||
it('tail should handle file going away and coming back', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
var inputCounter = 0;
|
||||
var warned = false;
|
||||
tailNode1.on("log", function(msg) {
|
||||
if (msg.level == "warn") { warned = true; }
|
||||
if ((inputCounter === 3)&&(warned === true)) { done(); }
|
||||
});
|
||||
helperNode1.on("input", function(msg) {
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
msg.payload.should.equal("Tail message line A");
|
||||
inputCounter += 1;
|
||||
if ((inputCounter === 3)&&(warned === true)) { done(); }
|
||||
});
|
||||
fs.writeFileSync(fileToTail, "Tail message line A\n");
|
||||
setTimeout( function() {
|
||||
fs.appendFileSync(fileToTail, "Tail message line A\n");
|
||||
fs.appendFileSync(fileToTail, "Tail message line A\n");
|
||||
},250);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user