1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

update file node test to cope with occasional failure

This commit is contained in:
Hiroyasu Nishiyama 2018-07-27 08:30:03 +09:00
parent 4e549dd426
commit 81efce03ba

View File

@ -46,9 +46,14 @@ describe('file Nodes', function() {
it('should be loaded', function(done) {
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":true}];
helper.load(fileNode, flow, function() {
try {
var fileNode1 = helper.getNode("fileNode1");
fileNode1.should.have.property('name', 'fileNode');
done();
}
catch (e) {
done(e);
}
});
});
@ -59,11 +64,16 @@ describe('file Nodes', function() {
var n1 = helper.getNode("fileNode1");
var n2 = helper.getNode("helperNode1");
n2.on("input", function(msg) {
try {
var f = fs.readFileSync(fileToTest);
f.should.have.length(4);
fs.unlinkSync(fileToTest);
msg.should.have.property("payload", "test");
done();
}
catch (e) {
done(e);
}
});
n1.receive({payload:"test"});
});
@ -83,7 +93,9 @@ describe('file Nodes', function() {
var data = ["test2", true, 999, [2]];
n2.on("input", function (msg) {
msg.should.have.property("payload", data[count]);
try {
msg.should.have.property("payload");
data.should.containDeep([msg.payload]);
if (count === 3) {
var f = fs.readFileSync(fileToTest).toString();
if (os.type() !== "Windows_NT") {
@ -97,6 +109,10 @@ describe('file Nodes', function() {
done();
}
count++;
}
catch (e) {
done(e);
}
});
n1.receive({payload:"test2"}); // string
@ -126,7 +142,9 @@ describe('file Nodes', function() {
var count = 0;
n2.on("input", function (msg) {
msg.should.have.property("payload", data[count]);
try {
msg.should.have.property("payload");
data.should.containDeep([msg.payload]);
try {
if (count === 1) {
// Check they got appended as expected
@ -151,6 +169,10 @@ describe('file Nodes', function() {
done(err);
}
count++;
}
catch (e) {
done(e);
}
});
// Send two messages to the file
@ -174,7 +196,8 @@ describe('file Nodes', function() {
n2.on("input", function (msg) {
try {
msg.should.have.property("payload", data[count]);
msg.should.have.property("payload");
data.should.containDeep([msg.payload]);
if (count == 1) {
// Check they got appended as expected
var f = fs.readFileSync(fileToTest).toString();
@ -233,6 +256,7 @@ describe('file Nodes', function() {
var n2 = helper.getNode("helperNode1");
n2.on("input", function (msg) {
try {
msg.should.have.property("payload", "fine");
msg.should.have.property("filename", fileToTest);
@ -246,6 +270,10 @@ describe('file Nodes', function() {
f.should.equal("fine\r\n");
}
done();
}
catch (e) {
done(e);
}
});
n1.receive({payload:"fine", filename:fileToTest});