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

better tests for windows nodes

This commit is contained in:
Dave Conway-Jones 2017-03-06 17:40:09 +00:00
parent 6264104642
commit 06ffe722d4
4 changed files with 103 additions and 86 deletions

View File

@ -413,7 +413,7 @@ describe('trigger node', function() {
n1.emit("input", {payload:"foo"}); // trigger n1.emit("input", {payload:"foo"}); // trigger
setTimeout( function() { setTimeout( function() {
n1.emit("input", {reset:true}); // reset n1.emit("input", {reset:true}); // reset
},90); },95);
setTimeout( function() { setTimeout( function() {
c.should.equal(4); // should send foo 4 times. c.should.equal(4); // should send foo 4 times.
done(); done();

View File

@ -16,6 +16,7 @@
var should = require("should"); var should = require("should");
var path = require('path'); var path = require('path');
var os = require('os');
var fs = require('fs-extra'); var fs = require('fs-extra');
var sinon = require('sinon'); var sinon = require('sinon');
var tailNode = require("../../../../nodes/core/storage/28-tail.js"); var tailNode = require("../../../../nodes/core/storage/28-tail.js");
@ -39,98 +40,100 @@ describe('tail Node', function() {
}); });
}); });
it('should be loaded', function(done) { if (os.type() !== "Windows_NT") {
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail}]; it('should be loaded', function(done) {
helper.load(tailNode, flow, function() { var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail}];
var tailNode1 = helper.getNode("tailNode1"); helper.load(tailNode, flow, function() {
tailNode1.should.have.property('name', 'tailNode'); var tailNode1 = helper.getNode("tailNode1");
done(); tailNode1.should.have.property('name', 'tailNode');
done();
});
}); });
});
it('should tail a file', function(done) { it('should tail a file', function(done) {
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]}, var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(tailNode, flow, function() { helper.load(tailNode, flow, function() {
var tailNode1 = helper.getNode("tailNode1"); var tailNode1 = helper.getNode("tailNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
var inputCounter = 0; var inputCounter = 0;
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
//console.log(msg); //console.log(msg);
msg.should.have.property('topic', fileToTail); msg.should.have.property('topic', fileToTail);
msg.payload.should.equal("Tail message line " + (++inputCounter + 2)); msg.payload.should.equal("Tail message line " + (++inputCounter + 2));
if (inputCounter === 2) { if (inputCounter === 2) {
done();
}
});
setTimeout( function() {
fs.appendFileSync(fileToTail, "Tail message line 3\n");
fs.appendFileSync(fileToTail, "Tail message line 4\n");
},wait);
});
});
it('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 line 5\nTail message line 6\n");
done(); done();
} });
setTimeout( function() {
fs.appendFileSync(fileToTail, "Tail message line 5\nTail message line 6\n");
},wait);
}); });
setTimeout( function() {
fs.appendFileSync(fileToTail, "Tail message line 3\n");
fs.appendFileSync(fileToTail, "Tail message line 4\n");
},wait);
}); });
});
it('should work in non-split mode', function(done) { it('should work in binary mode', function(done) {
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":false, "filename":fileToTail, "wires":[["helperNode1"]]}, var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "filetype":"binary", "filename":fileToTail, "wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(tailNode, flow, function() { helper.load(tailNode, flow, function() {
var tailNode1 = helper.getNode("tailNode1"); var tailNode1 = helper.getNode("tailNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
//console.log(msg); //console.log(msg);
msg.should.have.property('topic', fileToTail); msg.should.have.property('topic', fileToTail);
msg.payload.should.equal("Tail message line 5\nTail message line 6\n"); msg.payload.toString().should.equal("Tail message line 7\nTail message line 8\n");
done(); done();
});
setTimeout( function() {
fs.appendFileSync(fileToTail, "Tail message line 7\nTail message line 8\n");
},wait);
}); });
setTimeout( function() {
fs.appendFileSync(fileToTail, "Tail message line 5\nTail message line 6\n");
},wait);
}); });
});
it('should work in binary mode', function(done) { it('should handle a non-existent file', function(done) {
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "filetype":"binary", "filename":fileToTail, "wires":[["helperNode1"]]}, fs.writeFileSync(fileToTail, "Tail message line.\n");
{id:"helperNode1", type:"helper", wires:[]}]; var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
helper.load(tailNode, flow, function() { {id:"helperNode1", type:"helper", wires:[]}];
var tailNode1 = helper.getNode("tailNode1"); helper.load(tailNode, flow, function() {
var helperNode1 = helper.getNode("helperNode1"); var tailNode1 = helper.getNode("tailNode1");
helperNode1.on("input", function(msg) { var helperNode1 = helper.getNode("helperNode1");
//console.log(msg); helperNode1.on("input", function(msg) {
msg.should.have.property('topic', fileToTail); msg.should.have.property('topic', fileToTail);
msg.payload.toString().should.equal("Tail message line 7\nTail message line 8\n"); msg.payload.should.equal("Tail message line");
done(); done();
});
setTimeout(function() {
fs.unlinkSync(fileToTail);
},500);
setTimeout( function() {
fs.writeFile(fileToTail, "Tail message line\n");
},1000);
}); });
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"]]},
{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) {
msg.should.have.property('topic', fileToTail);
msg.payload.should.equal("Tail message line");
done();
});
setTimeout(function(){
fs.unlinkSync(fileToTail);
},500);
setTimeout( function() {
fs.writeFile(fileToTail, "Tail message line\n");
},1000);
});
});
it('should throw an error if run on Windows', function(done) { it('should throw an error if run on Windows', function(done) {
// Stub os platform so we can make it look like windows // Stub os platform so we can make it look like windows
var os = require('os'); var os = require('os');
var spy = sinon.stub(os, 'platform', function(arg){ return("windows"); }); var spy = sinon.stub(os, 'platform', function(arg) { return("windows"); });
/*jshint immed: false */ /*jshint immed: false */
(function() { tailNode("1234"); }).should.throw(); (function() { tailNode("1234"); }).should.throw();

View File

@ -17,6 +17,7 @@
var should = require("should"); var should = require("should");
var path = require('path'); var path = require('path');
var fs = require('fs-extra'); var fs = require('fs-extra');
var os = require('os');
var sinon = require("sinon"); var sinon = require("sinon");
var fileNode = require("../../../../nodes/core/storage/50-file.js"); var fileNode = require("../../../../nodes/core/storage/50-file.js");
var helper = require("../../helper.js"); var helper = require("../../helper.js");
@ -80,8 +81,14 @@ describe('file Nodes', function() {
},90); },90);
setTimeout(function() { setTimeout(function() {
var f = fs.readFileSync(fileToTest).toString(); var f = fs.readFileSync(fileToTest).toString();
f.should.have.length(19); if (os.type() !== "Windows_NT") {
f.should.equal("test2\ntrue\n999\n[2]\n"); f.should.have.length(19);
f.should.equal("test2\ntrue\n999\n[2]\n");
}
else {
f.should.have.length(23);
f.should.equal("test2\r\ntrue\r\n999\r\n[2]\r\n");
}
done(); done();
},wait); },wait);
}); });
@ -94,8 +101,14 @@ describe('file Nodes', function() {
n1.emit("input", {payload:"fine", filename:fileToTest}); n1.emit("input", {payload:"fine", filename:fileToTest});
setTimeout(function() { setTimeout(function() {
var f = fs.readFileSync(fileToTest).toString(); var f = fs.readFileSync(fileToTest).toString();
f.should.have.length(5); if (os.type() !== "Windows_NT") {
f.should.equal("fine\n"); f.should.have.length(5);
f.should.equal("fine\n");
}
else {
f.should.have.length(6);
f.should.equal("fine\r\n");
}
done(); done();
},wait); },wait);
}); });
@ -197,7 +210,7 @@ describe('file Nodes', function() {
it('should fail to append to a ro file', function(done) { it('should fail to append to a ro file', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var spy = sinon.stub(fs, 'appendFile', function(arg,arg2,arg3,arg4){ arg4(new Error("Stub error message")); }); var spy = sinon.stub(fs, 'appendFile', function(arg,arg2,arg3,arg4) { arg4(new Error("Stub error message")); });
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}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
@ -222,7 +235,7 @@ describe('file Nodes', function() {
it('should cope with failing to delete a file', function(done) { it('should cope with failing to delete a file', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var spy = sinon.stub(fs, 'unlink', function(arg,arg2){ arg2(new Error("Stub error message")); }); var spy = sinon.stub(fs, 'unlink', function(arg,arg2) { arg2(new Error("Stub error message")); });
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":"delete"}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":"delete"}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
@ -325,7 +338,7 @@ describe('file Nodes', function() {
it('should try to create a new directory if asked to do so (overwrite)', function(done) { it('should try to create a new directory if asked to do so (overwrite)', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var fileToTest2 = path.join(resourcesDir,"a","50-file-test-file.txt"); var fileToTest2 = path.join(resourcesDir,"a","50-file-test-file.txt");
var spy = sinon.stub(fs, "ensureFile", function(arg1,arg2,arg3,arg4){ arg2(null); }); var spy = sinon.stub(fs, "ensureFile", function(arg1,arg2,arg3,arg4) { arg2(null); });
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":true, "createDir":true}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":true, "createDir":true}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {

View File

@ -133,7 +133,8 @@ describe('nodes/registry/installer', function() {
done(); done();
} }
else { else {
err.message.should.eql("Install failed"); console.log("ERRROR::"+err.toString()+"::");
err.toString().should.eql("Error: Install failed");
done(); done();
} }
}); });