mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
update test for file node for new output port
This commit is contained in:
parent
8226f1fa75
commit
054c7a76a4
@ -53,37 +53,38 @@ describe('file Nodes', function() {
|
||||
});
|
||||
|
||||
it('should write to a file', function(done) {
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":true}];
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":true, wires: [["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper"}];
|
||||
helper.load(fileNode, flow, function() {
|
||||
var n1 = helper.getNode("fileNode1");
|
||||
n1.emit("input", {payload:"test"});
|
||||
setTimeout(function() {
|
||||
var n2 = helper.getNode("helperNode1");
|
||||
n2.on("input", function(msg) {
|
||||
var f = fs.readFileSync(fileToTest);
|
||||
f.should.have.length(4);
|
||||
fs.unlinkSync(fileToTest);
|
||||
msg.should.have.property("payload", "test");
|
||||
done();
|
||||
},wait);
|
||||
});
|
||||
n1.receive({payload:"test"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should append to a file and add newline', function(done) {
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":false}];
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":false, wires: [["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper"}];
|
||||
try {
|
||||
fs.unlinkSync(fileToTest);
|
||||
}catch(err) {}
|
||||
} catch(err) {
|
||||
}
|
||||
helper.load(fileNode, flow, function() {
|
||||
var n1 = helper.getNode("fileNode1");
|
||||
n1.emit("input", {payload:"test2"}); // string
|
||||
setTimeout(function() {
|
||||
n1.emit("input", {payload:true}); // boolean
|
||||
},30);
|
||||
setTimeout(function() {
|
||||
n1.emit("input", {payload:999}); // number
|
||||
},60);
|
||||
setTimeout(function() {
|
||||
n1.emit("input", {payload:[2]}); // object (array)
|
||||
},90);
|
||||
setTimeout(function() {
|
||||
var n2 = helper.getNode("helperNode1");
|
||||
var count = 0;
|
||||
var data = ["test2", true, 999, [2]];
|
||||
|
||||
n2.on("input", function (msg) {
|
||||
msg.should.have.property("payload", data[count]);
|
||||
if (count === 3) {
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
if (os.type() !== "Windows_NT") {
|
||||
f.should.have.length(19);
|
||||
@ -94,63 +95,87 @@ describe('file Nodes', function() {
|
||||
f.should.equal("test2\r\ntrue\r\n999\r\n[2]\r\n");
|
||||
}
|
||||
done();
|
||||
},wait);
|
||||
}
|
||||
count++;
|
||||
});
|
||||
|
||||
n1.receive({payload:"test2"}); // string
|
||||
setTimeout(function() {
|
||||
n1.receive({payload:true}); // boolean
|
||||
},30);
|
||||
setTimeout(function() {
|
||||
n1.receive({payload:999}); // number
|
||||
},60);
|
||||
setTimeout(function() {
|
||||
n1.receive({payload:[2]}); // object (array)
|
||||
},90);
|
||||
});
|
||||
});
|
||||
|
||||
it('should append to a file after it has been deleted ', function(done) {
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":false}];
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":false, wires: [["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper"}];
|
||||
try {
|
||||
fs.unlinkSync(fileToTest);
|
||||
} catch(err) {}
|
||||
} catch(err) {
|
||||
}
|
||||
helper.load(fileNode, flow, function() {
|
||||
var n1 = helper.getNode("fileNode1");
|
||||
// Send two messages to the file
|
||||
n1.emit("input", {payload:"one"});
|
||||
n1.emit("input", {payload:"two"});
|
||||
setTimeout(function() {
|
||||
var n2 = helper.getNode("helperNode1");
|
||||
var data = ["one", "two", "three", "four"];
|
||||
var count = 0;
|
||||
|
||||
n2.on("input", function (msg) {
|
||||
msg.should.have.property("payload", data[count]);
|
||||
try {
|
||||
if (count === 1) {
|
||||
// Check they got appended as expected
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
f.should.equal("onetwo");
|
||||
|
||||
// Delete the file
|
||||
fs.unlinkSync(fileToTest);
|
||||
|
||||
// Send two more messages to the file
|
||||
n1.emit("input", {payload:"three"});
|
||||
n1.emit("input", {payload:"four"});
|
||||
|
||||
setTimeout(function() {
|
||||
// Check the file was updated
|
||||
try {
|
||||
// Send two more messages to the file
|
||||
n1.receive({payload:"three"});
|
||||
n1.receive({payload:"four"});
|
||||
}, wait);
|
||||
}
|
||||
if (count === 3) {
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
f.should.equal("threefour");
|
||||
fs.unlinkSync(fileToTest);
|
||||
done();
|
||||
}
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
},wait);
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
},wait);
|
||||
count++;
|
||||
});
|
||||
|
||||
// Send two messages to the file
|
||||
n1.receive({payload:"one"});
|
||||
n1.receive({payload:"two"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should append to a file after it has been recreated ', function(done) {
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":false}];
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":false, wires: [["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper"}];
|
||||
try {
|
||||
fs.unlinkSync(fileToTest);
|
||||
} catch(err) {}
|
||||
} catch(err) {
|
||||
}
|
||||
helper.load(fileNode, flow, function() {
|
||||
var n1 = helper.getNode("fileNode1");
|
||||
// Send two messages to the file
|
||||
n1.emit("input", {payload:"one"});
|
||||
n1.emit("input", {payload:"two"});
|
||||
setTimeout(function() {
|
||||
var n2 = helper.getNode("helperNode1");
|
||||
var data = ["one", "two", "three", "four"];
|
||||
var count = 0;
|
||||
|
||||
n2.on("input", function (msg) {
|
||||
try {
|
||||
msg.should.have.property("payload", data[count]);
|
||||
if (count == 1) {
|
||||
// Check they got appended as expected
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
f.should.equal("onetwo");
|
||||
@ -163,10 +188,27 @@ describe('file Nodes', function() {
|
||||
} else {
|
||||
recreateTest(n1, fileToTest);
|
||||
}
|
||||
}
|
||||
if (count == 3) {
|
||||
// Check the file was updated
|
||||
try {
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
f.should.equal("threefour");
|
||||
fs.unlinkSync(fileToTest);
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
},wait);
|
||||
}
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
count++;
|
||||
});
|
||||
|
||||
// Send two messages to the file
|
||||
n1.receive({payload:"one"});
|
||||
n1.receive({payload:"two"});
|
||||
});
|
||||
|
||||
function recreateTest(n1, fileToDelete) {
|
||||
@ -177,30 +219,23 @@ describe('file Nodes', function() {
|
||||
fs.writeFileSync(fileToTest,"");
|
||||
|
||||
// Send two more messages to the file
|
||||
n1.emit("input", {payload:"three"});
|
||||
n1.emit("input", {payload:"four"});
|
||||
|
||||
setTimeout(function() {
|
||||
// Check the file was updated
|
||||
try {
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
f.should.equal("threefour");
|
||||
fs.unlinkSync(fileToTest);
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
},wait);
|
||||
n1.receive({payload:"three"});
|
||||
n1.receive({payload:"four"});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
it('should use msg.filename if filename not set in node', function(done) {
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "appendNewline":true, "overwriteFile":true}];
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "appendNewline":true, "overwriteFile":true, wires: [["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper"}];
|
||||
helper.load(fileNode, flow, function() {
|
||||
var n1 = helper.getNode("fileNode1");
|
||||
n1.emit("input", {payload:"fine", filename:fileToTest});
|
||||
setTimeout(function() {
|
||||
var n2 = helper.getNode("helperNode1");
|
||||
|
||||
n2.on("input", function (msg) {
|
||||
msg.should.have.property("payload", "fine");
|
||||
msg.should.have.property("filename", fileToTest);
|
||||
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
if (os.type() !== "Windows_NT") {
|
||||
f.should.have.length(5);
|
||||
@ -211,16 +246,20 @@ describe('file Nodes', function() {
|
||||
f.should.equal("fine\r\n");
|
||||
}
|
||||
done();
|
||||
},wait);
|
||||
});
|
||||
|
||||
n1.receive({payload:"fine", filename:fileToTest});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to delete the file', function(done) {
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":"delete"}];
|
||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":"delete", wires: [["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper"}];
|
||||
helper.load(fileNode, flow, function() {
|
||||
var n1 = helper.getNode("fileNode1");
|
||||
n1.emit("input", {payload:"fine"});
|
||||
setTimeout(function() {
|
||||
var n2 = helper.getNode("helperNode1");
|
||||
|
||||
n2.on("input", function (msg) {
|
||||
try {
|
||||
var f = fs.readFileSync(fileToTest).toString();
|
||||
f.should.not.equal("fine");
|
||||
@ -230,7 +269,9 @@ describe('file Nodes', function() {
|
||||
e.code.should.equal("ENOENT");
|
||||
done();
|
||||
}
|
||||
},wait);
|
||||
});
|
||||
|
||||
n1.receive({payload:"fine"});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user