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

Fix type checking in unit tests

This commit is contained in:
Nick O'Leary 2016-10-10 13:27:43 +01:00
parent eb1a597456
commit 42f7dc1947
28 changed files with 281 additions and 252 deletions

View File

@ -60,11 +60,15 @@ describe('sentiment Node', function() {
var jn1 = helper.getNode("jn1"); var jn1 = helper.getNode("jn1");
var jn2 = helper.getNode("jn2"); var jn2 = helper.getNode("jn2");
jn2.on("input", function(msg) { jn2.on("input", function(msg) {
msg.should.have.property('sentiment'); try {
msg.sentiment.should.have.property('score'); msg.should.have.property('sentiment');
msg.sentiment.score.should.be.a.number; msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.above(10); msg.sentiment.score.should.be.a.Number();
done(); msg.sentiment.score.should.be.above(10);
done();
} catch(err) {
done(err);
}
}); });
var testString = 'good, great, best, brilliant'; var testString = 'good, great, best, brilliant';
jn1.receive({payload:testString}); jn1.receive({payload:testString});
@ -80,7 +84,7 @@ describe('sentiment Node', function() {
jn2.on("input", function(msg) { jn2.on("input", function(msg) {
msg.should.have.property('sentiment'); msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score'); msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.number; msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.be.below(-10); msg.sentiment.score.should.be.below(-10);
done(); done();
}); });
@ -98,7 +102,7 @@ describe('sentiment Node', function() {
jn2.on("input", function(msg) { jn2.on("input", function(msg) {
msg.should.have.property('sentiment'); msg.should.have.property('sentiment');
msg.sentiment.should.have.property('score'); msg.sentiment.should.have.property('score');
msg.sentiment.score.should.be.a.number; msg.sentiment.score.should.be.a.Number();
msg.sentiment.score.should.equal(20); msg.sentiment.score.should.equal(20);
done(); done();
}); });

View File

@ -32,7 +32,7 @@ describe('catch Node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
n1.should.have.property('name', 'catch'); n1.should.have.property('name', 'catch');
n2.on("input", function(msg) { n2.on("input", function(msg) {
msg.should.be.a.Error; msg.should.be.a.Error();
msg.toString().should.equal("Error: big error"); msg.toString().should.equal("Error: big error");
done(); done();
}); });

View File

@ -69,7 +69,7 @@ describe('debug node', function() {
count++; count++;
}, function() { }, function() {
try { try {
helper.log().called.should.be.true; helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) { var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "debug"; return evt[0].type == "debug";
}); });

View File

@ -66,7 +66,7 @@ describe('exec node', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
//console.log(msg); //console.log(msg);
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.String; msg.payload.should.be.a.String();
msg.payload.should.equal("echo"); msg.payload.should.equal("echo");
}); });
n3.on("input", function(msg) { n3.on("input", function(msg) {
@ -99,13 +99,13 @@ describe('exec node', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
//console.log(msg); //console.log(msg);
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.String; msg.payload.should.be.a.String();
msg.payload.should.equal("echo and more"); msg.payload.should.equal("echo and more");
}); });
n3.on("input", function(msg) { n3.on("input", function(msg) {
//console.log(msg); //console.log(msg);
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.String; msg.payload.should.be.a.String();
msg.payload.should.equal("ECHO AND MORE"); msg.payload.should.equal("ECHO AND MORE");
done(); done();
child_process.exec.restore(); child_process.exec.restore();
@ -130,11 +130,15 @@ describe('exec node', function() {
var n4 = helper.getNode("n4"); var n4 = helper.getNode("n4");
n2.on("input", function(msg) { n2.on("input", function(msg) {
//console.log("n2",msg); //console.log("n2",msg);
msg.should.have.property("payload"); try {
msg.payload.should.be.a.Buffer; msg.should.have.property("payload");
msg.payload.length.should.equal(4); Buffer.isBuffer(msg.payload).should.be.true();
done(); msg.payload.length.should.equal(4);
child_process.exec.restore(); child_process.exec.restore();
done();
} catch(err) {
done(err);
}
}); });
n1.receive({}); n1.receive({});
}); });
@ -183,10 +187,14 @@ describe('exec node', function() {
var n4 = helper.getNode("n4"); var n4 = helper.getNode("n4");
n2.on("input", function(msg) { n2.on("input", function(msg) {
//console.log(msg); //console.log(msg);
msg.should.have.property("payload"); try {
msg.payload.should.be.a.String; msg.should.have.property("payload");
msg.payload.should.equal("hello world\n"); msg.payload.should.be.a.String();
done(); msg.payload.should.equal("hello world\n");
done();
} catch(err) {
done(err);
}
}); });
n1.receive({payload:"hello world"}); n1.receive({payload:"hello world"});
}); });
@ -204,7 +212,7 @@ describe('exec node', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
//console.log(msg); //console.log(msg);
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.String; msg.payload.should.be.a.String();
msg.payload.should.equal("12345 deg C\n"); msg.payload.should.equal("12345 deg C\n");
done(); done();
}); });
@ -222,16 +230,20 @@ describe('exec node', function() {
var n3 = helper.getNode("n3"); var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4"); var n4 = helper.getNode("n4");
n2.on("input", function(msg) { n2.on("input", function(msg) {
msg.should.have.property("payload"); try {
msg.payload.should.be.a.Buffer; msg.should.have.property("payload");
msg.payload.length.should.equal(7); Buffer.isBuffer(msg.payload).should.be.true();
done(); msg.payload.length.should.equal(7);
done();
} catch(err) {
done(err);
}
}); });
n1.receive({payload:new Buffer([0x01,0x02,0x03,0x88])}); n1.receive({payload:new Buffer([0x01,0x02,0x03,0x88])});
}); });
}); });
it('should now work if passed multiple words to spawn command', function(done) { it('should work if passed multiple words to spawn command', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo this now works", addpay:false, append:"", useSpawn:true}, var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo this now works", addpay:false, append:"", useSpawn:true},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}]; {id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
helper.load(execNode, flow, function() { helper.load(execNode, flow, function() {
@ -241,14 +253,18 @@ describe('exec node', function() {
var n4 = helper.getNode("n4"); var n4 = helper.getNode("n4");
n2.on("input", function(msg) { n2.on("input", function(msg) {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.String; msg.payload.should.be.a.String();
msg.payload.should.equal("this now works\n"); msg.payload.should.equal("this now works\n");
}); });
n4.on("input", function(msg) { n4.on("input", function(msg) {
msg.should.have.property("payload"); try {
msg.payload.should.be.a.String; msg.should.have.property("payload");
msg.payload.should.equal(0); msg.payload.should.be.a.Number();
done(); msg.payload.should.equal(0);
done();
} catch(err) {
done(err);
}
}); });
n1.receive({payload:null}); n1.receive({payload:null});
}); });
@ -264,7 +280,7 @@ describe('exec node', function() {
var n4 = helper.getNode("n4"); var n4 = helper.getNode("n4");
n4.on("input", function(msg) { n4.on("input", function(msg) {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.Number; msg.payload.should.be.a.Number();
msg.payload.should.be.below(0); msg.payload.should.be.below(0);
done(); done();
}); });
@ -282,12 +298,12 @@ describe('exec node', function() {
var n4 = helper.getNode("n4"); var n4 = helper.getNode("n4");
n3.on("input", function(msg) { n3.on("input", function(msg) {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.String; msg.payload.should.be.a.String();
msg.payload.should.equal("mkdir: /foo/bar/doo: No such file or directory\n"); msg.payload.should.equal("mkdir: /foo/bar/doo: No such file or directory\n");
}); });
n4.on("input", function(msg) { n4.on("input", function(msg) {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.a.String; msg.payload.should.be.a.Number();
msg.payload.should.equal(1); msg.payload.should.equal(1);
done(); done();
}); });

View File

@ -165,7 +165,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
n1.receive({payload:"foo",topic: "bar"}); n1.receive({payload:"foo",topic: "bar"});
try { try {
helper.log().called.should.be.true; helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) { var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "function"; return evt[0].type == "function";
}); });
@ -188,7 +188,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"}); n1.receive({payload: "foo", topic: "bar"});
try { try {
helper.log().called.should.be.true; helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) { var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function"; return evt[0].type == "function";
}); });
@ -210,7 +210,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"}); n1.receive({payload: "foo", topic: "bar"});
try { try {
helper.log().called.should.be.true; helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) { var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function"; return evt[0].type == "function";
}); });
@ -232,7 +232,7 @@ describe('function node', function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"}); n1.receive({payload: "foo", topic: "bar"});
try { try {
helper.log().called.should.be.true; helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) { var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function"; return evt[0].type == "function";
}); });

View File

@ -294,7 +294,7 @@ describe('delay Node', function() {
} }
} }
} }
foundAtLeastOneDrop.should.be.true; foundAtLeastOneDrop.should.be.true();
done(); done();
} catch (err) { } catch (err) {
done(err); done(err);

View File

@ -217,7 +217,7 @@ describe('change Node', function() {
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
(msg.payload === null).should.be.true; (msg.payload === null).should.be.true();
done(); done();
} catch(err) { } catch(err) {
done(err); done(err);

View File

@ -154,7 +154,7 @@ describe('JOIN node', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.an.Array; msg.payload.should.be.an.Array();
msg.payload[0].should.equal(1); msg.payload[0].should.equal(1);
msg.payload[1].should.equal(true); msg.payload[1].should.equal(true);
//msg.payload[2].a.should.equal(1); //msg.payload[2].a.should.equal(1);
@ -274,7 +274,7 @@ describe('JOIN node', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.an.Array; msg.payload.should.be.an.Array();
msg.payload[0].should.equal(1); msg.payload[0].should.equal(1);
msg.payload[1].should.equal(2); msg.payload[1].should.equal(2);
msg.payload[2].should.equal(3); msg.payload[2].should.equal(3);
@ -323,8 +323,8 @@ describe('JOIN node', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.an.Array; msg.payload.should.be.an.Array();
(msg.payload[0] === undefined).should.be.true; (msg.payload[0] === undefined).should.be.true();
msg.payload[1].should.equal(2); msg.payload[1].should.equal(2);
msg.payload[2].should.equal(3); msg.payload[2].should.equal(3);
msg.payload[3].should.equal(4); msg.payload[3].should.equal(4);
@ -347,7 +347,7 @@ describe('JOIN node', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property("payload"); msg.should.have.property("payload");
msg.payload.should.be.an.Array; msg.payload.should.be.an.String();
msg.payload.should.equal("abcd"); msg.payload.should.equal("abcd");
done(); done();
} }

View File

@ -32,7 +32,7 @@ describe('html node', function() {
}); });
beforeEach(function() { beforeEach(function() {
fs.existsSync(file).should.be.true; fs.existsSync(file).should.be.true();
}); });
afterEach(function() { afterEach(function() {
@ -170,7 +170,7 @@ describe('html node', function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
n1.receive({payload:null,topic: "bar"}); n1.receive({payload:null,topic: "bar"});
helper.log().called.should.be.true; helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) { var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "html"; return evt[0].type == "html";
}); });

View File

@ -156,7 +156,7 @@ describe('tail Node', function() {
msg.should.have.property('topic', fileToTail); msg.should.have.property('topic', fileToTail);
inputCounter++; inputCounter++;
if (inputCounter === 1) { if (inputCounter === 1) {
warned.should.be.false; warned.should.be.false();
msg.payload.should.equal("Tail message line append"); msg.payload.should.equal("Tail message line append");
} else if (inputCounter === 2) { } else if (inputCounter === 2) {
msg.payload.should.equal("Tail message line truncate"); msg.payload.should.equal("Tail message line truncate");
@ -166,7 +166,7 @@ describe('tail Node', function() {
if (inputCounter === 5) { if (inputCounter === 5) {
setTimeout(function() { setTimeout(function() {
warned.should.be.true; warned.should.be.true();
done(); done();
},100); },100);
} }

View File

@ -20,37 +20,37 @@ var permissions = require("../../../../red/api/auth/permissions");
describe("Auth permissions", function() { describe("Auth permissions", function() {
describe("hasPermission", function() { describe("hasPermission", function() {
it('a user with no permissions',function() { it('a user with no permissions',function() {
permissions.hasPermission([],"*").should.be.false; permissions.hasPermission([],"*").should.be.false();
}); });
it('a user with global permissions',function() { it('a user with global permissions',function() {
permissions.hasPermission("*","read").should.be.true; permissions.hasPermission("*","read").should.be.true();
permissions.hasPermission(["*"],"write").should.be.true; permissions.hasPermission(["*"],"write").should.be.true();
}); });
it('a user with read permissions',function() { it('a user with read permissions',function() {
permissions.hasPermission(["read"],"read").should.be.true; permissions.hasPermission(["read"],"read").should.be.true();
permissions.hasPermission(["read"],"node.read").should.be.true; permissions.hasPermission(["read"],"node.read").should.be.true();
permissions.hasPermission(["read"],"write").should.be.false; permissions.hasPermission(["read"],"write").should.be.false();
permissions.hasPermission(["read"],"node.write").should.be.false; permissions.hasPermission(["read"],"node.write").should.be.false();
permissions.hasPermission(["*.read"],"read").should.be.true; permissions.hasPermission(["*.read"],"read").should.be.true();
permissions.hasPermission(["*.read"],"node.read").should.be.true; permissions.hasPermission(["*.read"],"node.read").should.be.true();
permissions.hasPermission(["*.read"],"write").should.be.false; permissions.hasPermission(["*.read"],"write").should.be.false();
permissions.hasPermission(["*.read"],"node.write").should.be.false; permissions.hasPermission(["*.read"],"node.write").should.be.false();
}); });
it('a user with foo permissions',function() { it('a user with foo permissions',function() {
permissions.hasPermission("foo","foo").should.be.true; permissions.hasPermission("foo","foo").should.be.true();
}); });
it('an array of permissions', function() { it('an array of permissions', function() {
permissions.hasPermission(["*"],["foo.read","foo.write"]).should.be.true; permissions.hasPermission(["*"],["foo.read","foo.write"]).should.be.true();
permissions.hasPermission("read",["foo.read","foo.write"]).should.be.false; permissions.hasPermission("read",["foo.read","foo.write"]).should.be.false();
permissions.hasPermission("read",["foo.read","bar.read"]).should.be.true; permissions.hasPermission("read",["foo.read","bar.read"]).should.be.true();
permissions.hasPermission(["flows.read"],["flows.read"]).should.be.true; permissions.hasPermission(["flows.read"],["flows.read"]).should.be.true();
permissions.hasPermission(["flows.read"],["flows.write"]).should.be.false; permissions.hasPermission(["flows.read"],["flows.write"]).should.be.false();
permissions.hasPermission(["flows.read","nodes.write"],["flows.write"]).should.be.false; permissions.hasPermission(["flows.read","nodes.write"],["flows.write"]).should.be.false();
permissions.hasPermission(["flows.read","nodes.write"],["nodes.write"]).should.be.true; permissions.hasPermission(["flows.read","nodes.write"],["nodes.write"]).should.be.true();
}); });
it('permits an empty permission', function() { it('permits an empty permission', function() {
permissions.hasPermission("*","").should.be.true; permissions.hasPermission("*","").should.be.true();
permissions.hasPermission("read",[""]).should.be.true; permissions.hasPermission("read",[""]).should.be.true();
}); });
}); });
}); });

View File

@ -44,7 +44,7 @@ describe("Auth strategies", function() {
strategies.passwordTokenExchange({},"user","password","scope",function(err,token) { strategies.passwordTokenExchange({},"user","password","scope",function(err,token) {
try { try {
should.not.exist(err); should.not.exist(err);
token.should.be.false; token.should.be.false();
done(); done();
} catch(e) { } catch(e) {
done(e); done(e);
@ -60,7 +60,7 @@ describe("Auth strategies", function() {
strategies.passwordTokenExchange({},"user","password","*",function(err,token) { strategies.passwordTokenExchange({},"user","password","*",function(err,token) {
try { try {
should.not.exist(err); should.not.exist(err);
token.should.be.false; token.should.be.false();
done(); done();
} catch(e) { } catch(e) {
done(e); done(e);
@ -138,7 +138,7 @@ describe("Auth strategies", function() {
strategies.bearerStrategy("1234",function(err,user) { strategies.bearerStrategy("1234",function(err,user) {
try { try {
should.not.exist(err); should.not.exist(err);
user.should.be.false; user.should.be.false();
done(); done();
} catch(e) { } catch(e) {
done(e); done(e);
@ -221,7 +221,7 @@ describe("Auth strategies", function() {
strategies.clientPasswordStrategy(testClient.id,"invalid_secret",function(err,client) { strategies.clientPasswordStrategy(testClient.id,"invalid_secret",function(err,client) {
try { try {
should.not.exist(err); should.not.exist(err);
client.should.be.false; client.should.be.false();
done(); done();
} catch(e) { } catch(e) {
done(e); done(e);
@ -237,7 +237,7 @@ describe("Auth strategies", function() {
strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) { strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) {
try { try {
should.not.exist(err); should.not.exist(err);
client.should.be.false; client.should.be.false();
done(); done();
} catch(e) { } catch(e) {
done(e); done(e);
@ -259,7 +259,7 @@ describe("Auth strategies", function() {
strategies.passwordTokenExchange({},"user","badpassword","scope",function(err,token) { strategies.passwordTokenExchange({},"user","badpassword","scope",function(err,token) {
try { try {
err.toString().should.equal("Error: Too many login attempts. Wait 10 minutes and try again"); err.toString().should.equal("Error: Too many login attempts. Wait 10 minutes and try again");
token.should.be.false; token.should.be.false();
done(); done();
} catch(e) { } catch(e) {
done(e); done(e);

View File

@ -79,7 +79,7 @@ describe("Tokens", function() {
Tokens.get("1234").then(function(token) { Tokens.get("1234").then(function(token) {
try { try {
should.not.exist(token); should.not.exist(token);
saveSessions.calledOnce.should.be.true; saveSessions.calledOnce.should.be.true();
done(); done();
} catch(err) { } catch(err) {
done(err); done(err);

View File

@ -162,7 +162,7 @@ describe("flow api", function() {
return done(err); return done(err);
} }
res.body.should.has.a.property('id','123'); res.body.should.has.a.property('id','123');
nodes.updateFlow.calledOnce.should.be.true; nodes.updateFlow.calledOnce.should.be.true();
nodes.updateFlow.lastCall.args[0].should.eql('123'); nodes.updateFlow.lastCall.args[0].should.eql('123');
nodes.updateFlow.lastCall.args[1].should.eql({id:'123'}); nodes.updateFlow.lastCall.args[1].should.eql({id:'123'});
nodes.updateFlow.restore(); nodes.updateFlow.restore();
@ -247,7 +247,7 @@ describe("flow api", function() {
if (err) { if (err) {
return done(err); return done(err);
} }
nodes.removeFlow.calledOnce.should.be.true; nodes.removeFlow.calledOnce.should.be.true();
nodes.removeFlow.lastCall.args[0].should.eql('123'); nodes.removeFlow.lastCall.args[0].should.eql('123');
nodes.removeFlow.restore(); nodes.removeFlow.restore();
done(); done();

View File

@ -119,7 +119,7 @@ describe("flows api", function() {
if (err) { if (err) {
return done(err); return done(err);
} }
setFlows.calledOnce.should.be.true; setFlows.calledOnce.should.be.true();
setFlows.lastCall.args[1].should.eql('full'); setFlows.lastCall.args[1].should.eql('full');
done(); done();
}); });
@ -141,7 +141,7 @@ describe("flows api", function() {
if (err) { if (err) {
return done(err); return done(err);
} }
setFlows.calledOnce.should.be.true; setFlows.calledOnce.should.be.true();
setFlows.lastCall.args[1].should.eql('nodes'); setFlows.lastCall.args[1].should.eql('nodes');
done(); done();
}); });
@ -254,7 +254,7 @@ describe("flows api", function() {
if (err) { if (err) {
return done(err); return done(err);
} }
loadFlows.called.should.be.true; loadFlows.called.should.be.true();
done(); done();
}); });
}); });

View File

@ -119,7 +119,7 @@ describe("api index", function() {
return done(err); return done(err);
} }
res.text.should.eql("Not started"); res.text.should.eql("Not started");
errorLog.calledOnce.should.be.true; errorLog.calledOnce.should.be.true();
done(); done();
}); });
}); });

View File

@ -76,7 +76,7 @@ describe("nodes api", function() {
if (err) { if (err) {
throw err; throw err;
} }
res.body.should.be.an.Array; res.body.should.be.an.Array();
res.body.should.have.lengthOf(3); res.body.should.have.lengthOf(3);
done(); done();
}); });
@ -583,8 +583,8 @@ describe("nodes api", function() {
if (err) { if (err) {
throw err; throw err;
} }
enableNodeCalled.should.be.false; enableNodeCalled.should.be.false();
disableNodeCalled.should.be.false; disableNodeCalled.should.be.false();
res.body.should.have.property("id","123"); res.body.should.have.property("id","123");
res.body.should.have.property("enabled",state); res.body.should.have.property("enabled",state);
@ -744,8 +744,8 @@ describe("nodes api", function() {
if (err) { if (err) {
throw err; throw err;
} }
enableNodeCalled.should.be.false; enableNodeCalled.should.be.false();
disableNodeCalled.should.be.false; disableNodeCalled.should.be.false();
res.body.should.have.property("name","node-red"); res.body.should.have.property("name","node-red");
res.body.should.have.property("nodes"); res.body.should.have.property("nodes");
res.body.nodes[0].should.have.property("enabled",state); res.body.nodes[0].should.have.property("enabled",state);

View File

@ -95,7 +95,7 @@ describe("ui api", function() {
if (err){ if (err){
return done(err); return done(err);
} }
Buffer.isBuffer(res.body).should.be.true; Buffer.isBuffer(res.body).should.be.true();
compareBuffers(res.body,defaultIcon); compareBuffers(res.body,defaultIcon);
done(); done();
}); });
@ -112,7 +112,7 @@ describe("ui api", function() {
if (err){ if (err){
return done(err); return done(err);
} }
Buffer.isBuffer(res.body).should.be.true; Buffer.isBuffer(res.body).should.be.true();
compareBuffers(res.body,injectIcon); compareBuffers(res.body,injectIcon);
done(); done();
}); });
@ -130,7 +130,7 @@ describe("ui api", function() {
if (err){ if (err){
return done(err); return done(err);
} }
Buffer.isBuffer(res.body).should.be.true; Buffer.isBuffer(res.body).should.be.true();
compareBuffers(res.body,testIcon); compareBuffers(res.body,testIcon);
done(); done();
}); });

View File

@ -54,14 +54,14 @@ describe("runtime", function() {
it("initialises components", function() { it("initialises components", function() {
runtime.init({testSettings: true, httpAdminRoot:"/"}); runtime.init({testSettings: true, httpAdminRoot:"/"});
log.init.called.should.be.true; log.init.called.should.be.true();
settings.init.called.should.be.true; settings.init.called.should.be.true();
redNodes.init.called.should.be.true; redNodes.init.called.should.be.true();
}); });
it("returns version", function() { it("returns version", function() {
runtime.init({testSettings: true, httpAdminRoot:"/"}); runtime.init({testSettings: true, httpAdminRoot:"/"});
/^\d+\.\d+\.\d+(-git)?$/.test(runtime.version()).should.be.true; /^\d+\.\d+\.\d+(-git)?$/.test(runtime.version()).should.be.true();
}) })
}); });
@ -117,15 +117,15 @@ describe("runtime", function() {
runtime.start().then(function() { runtime.start().then(function() {
console.log.restore(); console.log.restore();
try { try {
storageInit.calledOnce.should.be.true; storageInit.calledOnce.should.be.true();
redNodesInit.calledOnce.should.be.true; redNodesInit.calledOnce.should.be.true();
redNodesLoad.calledOnce.should.be.true; redNodesLoad.calledOnce.should.be.true();
redNodesLoadFlows.calledOnce.should.be.true; redNodesLoadFlows.calledOnce.should.be.true();
logWarn.calledWithMatch("Failed to register 1 node type"); logWarn.calledWithMatch("Failed to register 1 node type");
logWarn.calledWithMatch("Missing node modules"); logWarn.calledWithMatch("Missing node modules");
logWarn.calledWithMatch(" - module: typeA, typeB"); logWarn.calledWithMatch(" - module: typeA, typeB");
redNodesCleanModuleList.calledOnce.should.be.true; redNodesCleanModuleList.calledOnce.should.be.true();
done(); done();
} catch(err) { } catch(err) {
done(err); done(err);
@ -151,8 +151,8 @@ describe("runtime", function() {
logWarn.calledWithMatch("Missing node modules"); logWarn.calledWithMatch("Missing node modules");
logWarn.calledWithMatch(" - module: typeA, typeB"); logWarn.calledWithMatch(" - module: typeA, typeB");
logWarn.calledWithMatch(" - node-red: typeC, typeD"); logWarn.calledWithMatch(" - node-red: typeC, typeD");
redNodesCleanModuleList.calledOnce.should.be.false; redNodesCleanModuleList.calledOnce.should.be.false();
serverInstallModule.calledOnce.should.be.true; serverInstallModule.calledOnce.should.be.true();
serverInstallModule.calledWithMatch("module"); serverInstallModule.calledWithMatch("module");
done(); done();
} catch(err) { } catch(err) {
@ -217,7 +217,7 @@ describe("runtime", function() {
it("stops components", function() { it("stops components", function() {
var stopFlows = sinon.stub(redNodes,"stopFlows",function() {} ); var stopFlows = sinon.stub(redNodes,"stopFlows",function() {} );
runtime.stop(); runtime.stop();
stopFlows.called.should.be.true; stopFlows.called.should.be.true();
stopFlows.restore(); stopFlows.restore();
}); });
}); });

View File

@ -63,7 +63,7 @@ describe("runtime/log", function() {
metrics.msgid = "12345"; metrics.msgid = "12345";
metrics.value = "the metric payload"; metrics.value = "the metric payload";
var ret = log.log(metrics); var ret = log.log(metrics);
util.log.calledOnce.should.be.true; util.log.calledOnce.should.be.true();
util.log.firstCall.args[0].indexOf("[metric] ").should.equal(0); util.log.firstCall.args[0].indexOf("[metric] ").should.equal(0);
var body = JSON.parse(util.log.firstCall.args[0].substring(9)); var body = JSON.parse(util.log.firstCall.args[0].substring(9));
body.should.have.a.property("nodeid","testid"); body.should.have.a.property("nodeid","testid");
@ -83,12 +83,12 @@ describe("runtime/log", function() {
it('it logs node type and name if provided',function() { it('it logs node type and name if provided',function() {
log.log({level:log.INFO,type:"nodeType",msg:"test",name:"nodeName",id:"nodeId"}); log.log({level:log.INFO,type:"nodeType",msg:"test",name:"nodeName",id:"nodeId"});
util.log.calledOnce.should.be.true; util.log.calledOnce.should.be.true();
util.log.firstCall.args[0].indexOf("[nodeType:nodeName]").should.not.equal(-1); util.log.firstCall.args[0].indexOf("[nodeType:nodeName]").should.not.equal(-1);
}); });
it('it logs node type and id if no name provided',function() { it('it logs node type and id if no name provided',function() {
log.log({level:log.INFO,type:"nodeType",msg:"test",id:"nodeId"}); log.log({level:log.INFO,type:"nodeType",msg:"test",id:"nodeId"});
util.log.calledOnce.should.be.true; util.log.calledOnce.should.be.true();
util.log.firstCall.args[0].indexOf("[nodeType:nodeId]").should.not.equal(-1); util.log.firstCall.args[0].indexOf("[nodeType:nodeId]").should.not.equal(-1);
}); });

View File

@ -27,7 +27,7 @@ describe('Node', function() {
n.should.have.property('id','123'); n.should.have.property('id','123');
n.should.have.property('type','abc'); n.should.have.property('type','abc');
n.should.not.have.property('name'); n.should.not.have.property('name');
n.wires.should.be.empty; n.wires.should.be.empty();
}); });
it('is called with an id, a type and a name',function() { it('is called with an id, a type and a name',function() {
@ -35,7 +35,7 @@ describe('Node', function() {
n.should.have.property('id','123'); n.should.have.property('id','123');
n.should.have.property('type','abc'); n.should.have.property('type','abc');
n.should.have.property('name','barney'); n.should.have.property('name','barney');
n.wires.should.be.empty; n.wires.should.be.empty();
}); });
it('is called with an id, a type and some wires',function() { it('is called with an id, a type and some wires',function() {
@ -141,7 +141,7 @@ describe('Node', function() {
throw new Error("test error"); throw new Error("test error");
}); });
n.receive(message); n.receive(message);
n.error.called.should.be.true; n.error.called.should.be.true();
n.error.firstCall.args[1].should.equal(message); n.error.firstCall.args[1].should.equal(message);
done(); done();
@ -431,7 +431,7 @@ describe('Node', function() {
n.error(null,message); n.error(null,message);
should.deepEqual({level:Log.ERROR, id:n.id, type:n.type, msg:""}, loginfo); should.deepEqual({level:Log.ERROR, id:n.id, type:n.type, msg:""}, loginfo);
flows.handleError.called.should.be.true; flows.handleError.called.should.be.true();
flows.handleError.args[0][0].should.eql(n); flows.handleError.args[0][0].should.eql(n);
flows.handleError.args[0][1].should.eql(""); flows.handleError.args[0][1].should.eql("");
flows.handleError.args[0][2].should.eql(message); flows.handleError.args[0][2].should.eql(message);
@ -455,7 +455,7 @@ describe('Node', function() {
n.error("This is an error",message); n.error("This is an error",message);
should.deepEqual({level:Log.ERROR, id:n.id, type:n.type, msg:"This is an error"}, loginfo); should.deepEqual({level:Log.ERROR, id:n.id, type:n.type, msg:"This is an error"}, loginfo);
flows.handleError.called.should.be.true; flows.handleError.called.should.be.true();
flows.handleError.args[0][0].should.eql(n); flows.handleError.args[0][0].should.eql(n);
flows.handleError.args[0][1].should.eql("This is an error"); flows.handleError.args[0][1].should.eql("This is an error");
flows.handleError.args[0][2].should.eql(message); flows.handleError.args[0][2].should.eql(message);
@ -492,7 +492,7 @@ describe('Node', function() {
}); });
var msg = {payload:"foo", _msgid:"987654321"}; var msg = {payload:"foo", _msgid:"987654321"};
var m = n.metric(undefined,msg,"15mb"); var m = n.metric(undefined,msg,"15mb");
m.should.be.a.boolean; m.should.be.a.Boolean();
Log.log.restore(); Log.log.restore();
done(); done();
}); });
@ -521,7 +521,7 @@ describe('Node', function() {
n.status(status); n.status(status);
flows.handleStatus.called.should.be.true; flows.handleStatus.called.should.be.true();
flows.handleStatus.args[0][0].should.eql(n); flows.handleStatus.args[0][0].should.eql(n);
flows.handleStatus.args[0][1].should.eql(status); flows.handleStatus.args[0][1].should.eql(status);
flows.handleStatus.restore(); flows.handleStatus.restore();

View File

@ -102,7 +102,7 @@ describe('flows/index', function() {
// describe('#init',function() { // describe('#init',function() {
// it('registers the type-registered handler', function() { // it('registers the type-registered handler', function() {
// flows.init({},{}); // flows.init({},{});
// eventsOn.calledOnce.should.be.true; // eventsOn.calledOnce.should.be.true();
// }); // });
// }); // });
@ -114,8 +114,8 @@ describe('flows/index', function() {
]; ];
flows.init({settings:{},storage:storage}); flows.init({settings:{},storage:storage});
flows.setFlows(originalConfig).then(function() { flows.setFlows(originalConfig).then(function() {
credentialsClean.called.should.be.true; credentialsClean.called.should.be.true();
storage.hasOwnProperty('conf').should.be.true; storage.hasOwnProperty('conf').should.be.true();
flows.getFlows().flows.should.eql(originalConfig); flows.getFlows().flows.should.eql(originalConfig);
done(); done();
}); });
@ -137,9 +137,9 @@ describe('flows/index', function() {
} }
flows.init({settings:{},storage:loadStorage}); flows.init({settings:{},storage:loadStorage});
flows.setFlows(originalConfig,"load").then(function() { flows.setFlows(originalConfig,"load").then(function() {
credentialsClean.called.should.be.false; credentialsClean.called.should.be.false();
// 'load' type does not trigger a save // 'load' type does not trigger a save
loadStorage.hasOwnProperty('conf').should.be.false; loadStorage.hasOwnProperty('conf').should.be.false();
flows.getFlows().flows.should.eql(originalConfig); flows.getFlows().flows.should.eql(originalConfig);
done(); done();
}); });
@ -153,8 +153,8 @@ describe('flows/index', function() {
]; ];
flows.init({settings:{},storage:storage}); flows.init({settings:{},storage:storage});
flows.setFlows(originalConfig).then(function() { flows.setFlows(originalConfig).then(function() {
credentialsClean.called.should.be.true; credentialsClean.called.should.be.true();
storage.hasOwnProperty('conf').should.be.true; storage.hasOwnProperty('conf').should.be.true();
var cleanedFlows = flows.getFlows(); var cleanedFlows = flows.getFlows();
storage.conf.flows.should.eql(cleanedFlows.flows); storage.conf.flows.should.eql(cleanedFlows.flows);
cleanedFlows.flows.should.not.eql(originalConfig); cleanedFlows.flows.should.not.eql(originalConfig);
@ -180,9 +180,9 @@ describe('flows/index', function() {
events.once('nodes-started',function() { events.once('nodes-started',function() {
flows.setFlows(newConfig,"nodes").then(function() { flows.setFlows(newConfig,"nodes").then(function() {
flows.getFlows().flows.should.eql(newConfig); flows.getFlows().flows.should.eql(newConfig);
flowCreate.flows['t1'].update.called.should.be.true; flowCreate.flows['t1'].update.called.should.be.true();
flowCreate.flows['t2'].start.called.should.be.true; flowCreate.flows['t2'].start.called.should.be.true();
flowCreate.flows['_GLOBAL_'].update.called.should.be.true; flowCreate.flows['_GLOBAL_'].update.called.should.be.true();
done(); done();
}) })
}); });
@ -209,9 +209,9 @@ describe('flows/index', function() {
events.once('nodes-started',function() { events.once('nodes-started',function() {
flows.setFlows(newConfig,"nodes").then(function() { flows.setFlows(newConfig,"nodes").then(function() {
flows.getFlows().flows.should.eql(newConfig); flows.getFlows().flows.should.eql(newConfig);
flowCreate.flows['t1'].update.called.should.be.true; flowCreate.flows['t1'].update.called.should.be.true();
flowCreate.flows['t2'].start.called.should.be.true; flowCreate.flows['t2'].start.called.should.be.true();
flowCreate.flows['_GLOBAL_'].update.called.should.be.true; flowCreate.flows['_GLOBAL_'].update.called.should.be.true();
flows.stopFlows().then(done); flows.stopFlows().then(done);
}) })
}); });
@ -235,9 +235,9 @@ describe('flows/index', function() {
} }
flows.init({settings:{},storage:storage}); flows.init({settings:{},storage:storage});
flows.load().then(function() { flows.load().then(function() {
credentialsLoad.called.should.be.true; credentialsLoad.called.should.be.true();
// 'load' type does not trigger a save // 'load' type does not trigger a save
storage.hasOwnProperty('conf').should.be.false; storage.hasOwnProperty('conf').should.be.false();
flows.getFlows().flows.should.eql(originalConfig); flows.getFlows().flows.should.eql(originalConfig);
done(); done();
}); });
@ -277,7 +277,7 @@ describe('flows/index', function() {
flows.init({settings:{},storage:storage}); flows.init({settings:{},storage:storage});
flows.load().then(function() { flows.load().then(function() {
flows.startFlows(); flows.startFlows();
flowCreate.called.should.be.false; flowCreate.called.should.be.false();
done(); done();
}); });
}); });
@ -295,14 +295,14 @@ describe('flows/index', function() {
flows.init({settings:{},storage:storage}); flows.init({settings:{},storage:storage});
flows.load().then(function() { flows.load().then(function() {
flows.startFlows(); flows.startFlows();
flowCreate.called.should.be.false; flowCreate.called.should.be.false();
events.emit("type-registered","missing"); events.emit("type-registered","missing");
setTimeout(function() { setTimeout(function() {
flowCreate.called.should.be.false; flowCreate.called.should.be.false();
events.emit("type-registered","missing2"); events.emit("type-registered","missing2");
setTimeout(function() { setTimeout(function() {
flowCreate.called.should.be.true; flowCreate.called.should.be.true();
done(); done();
},10); },10);
},10); },10);
@ -353,7 +353,7 @@ describe('flows/index', function() {
events.once('nodes-started',function() { events.once('nodes-started',function() {
flows.handleError(originalConfig[0],"message",{}); flows.handleError(originalConfig[0],"message",{});
flowCreate.flows['t1'].handleError.called.should.be.true; flowCreate.flows['t1'].handleError.called.should.be.true();
done(); done();
}); });
@ -379,9 +379,9 @@ describe('flows/index', function() {
events.once('nodes-started',function() { events.once('nodes-started',function() {
flows.handleError(originalConfig[0],"message",{}); flows.handleError(originalConfig[0],"message",{});
try { try {
flowCreate.flows['t1'].handleError.called.should.be.true; flowCreate.flows['t1'].handleError.called.should.be.true();
flowCreate.flows['t2'].handleError.called.should.be.false; flowCreate.flows['t2'].handleError.called.should.be.false();
flowCreate.flows['t3'].handleError.called.should.be.true; flowCreate.flows['t3'].handleError.called.should.be.true();
done(); done();
} catch(err) { } catch(err) {
done(err); done(err);
@ -406,7 +406,7 @@ describe('flows/index', function() {
events.once('nodes-started',function() { events.once('nodes-started',function() {
flows.handleStatus(originalConfig[0],"message"); flows.handleStatus(originalConfig[0],"message");
flowCreate.flows['t1'].handleStatus.called.should.be.true; flowCreate.flows['t1'].handleStatus.called.should.be.true();
done(); done();
}); });
@ -433,9 +433,9 @@ describe('flows/index', function() {
events.once('nodes-started',function() { events.once('nodes-started',function() {
flows.handleStatus(originalConfig[0],"message"); flows.handleStatus(originalConfig[0],"message");
try { try {
flowCreate.flows['t1'].handleStatus.called.should.be.true; flowCreate.flows['t1'].handleStatus.called.should.be.true();
flowCreate.flows['t2'].handleStatus.called.should.be.false; flowCreate.flows['t2'].handleStatus.called.should.be.false();
flowCreate.flows['t3'].handleStatus.called.should.be.true; flowCreate.flows['t3'].handleStatus.called.should.be.true();
done(); done();
} catch(err) { } catch(err) {
done(err); done(err);

View File

@ -43,9 +43,9 @@ describe('red/nodes/registry/index', function() {
stubs.push(sinon.stub(typeRegistry,"init")); stubs.push(sinon.stub(typeRegistry,"init"));
registry.init({}); registry.init({});
installer.init.called.should.be.true; installer.init.called.should.be.true();
loader.init.called.should.be.true; loader.init.called.should.be.true();
typeRegistry.init.called.should.be.true; typeRegistry.init.called.should.be.true();
}) })
}); });
@ -87,7 +87,7 @@ describe('red/nodes/registry/index', function() {
return {id:"node-set",loaded:true}; return {id:"node-set",loaded:true};
})); }));
registry.enableNode("node-set").then(function(ns) { registry.enableNode("node-set").then(function(ns) {
typeRegistry.enableNodeSet.called.should.be.true; typeRegistry.enableNodeSet.called.should.be.true();
ns.should.have.a.property('id','node-set'); ns.should.have.a.property('id','node-set');
done(); done();
}).otherwise(function(err) { done(err); }); }).otherwise(function(err) { done(err); });
@ -116,8 +116,8 @@ describe('red/nodes/registry/index', function() {
stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo")); stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo"));
registry.enableNode("node-set").then(function(ns) { registry.enableNode("node-set").then(function(ns) {
typeRegistry.enableNodeSet.called.should.be.true; typeRegistry.enableNodeSet.called.should.be.true();
loader.loadNodeSet.called.should.be.true; loader.loadNodeSet.called.should.be.true();
ns.should.have.a.property('id','node-set'); ns.should.have.a.property('id','node-set');
ns.should.have.a.property('loaded',true); ns.should.have.a.property('loaded',true);
done(); done();

View File

@ -45,7 +45,7 @@ describe("red/nodes/registry/loader",function() {
describe("#init",function() { describe("#init",function() {
it("init",function() { it("init",function() {
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}}});
localfilesystem.init.called.should.be.true; localfilesystem.init.called.should.be.true();
}); });
}); });
@ -55,10 +55,10 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};})); stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
loader.load("foo",true).then(function() { loader.load("foo",true).then(function() {
localfilesystem.getNodeFiles.called.should.be.true; localfilesystem.getNodeFiles.called.should.be.true();
localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo'); localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo');
localfilesystem.getNodeFiles.lastCall.args[1].should.be.true; localfilesystem.getNodeFiles.lastCall.args[1].should.be.true();
registry.saveNodeList.called.should.be.false; registry.saveNodeList.called.should.be.false();
done(); done();
}) })
}); });
@ -67,7 +67,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};})); stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load("foo",true).then(function() { loader.load("foo",true).then(function() {
registry.saveNodeList.called.should.be.true; registry.saveNodeList.called.should.be.true();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
done(err); done(err);
@ -98,7 +98,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) { loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true; registry.addNodeSet.called.should.be.true();
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1"); registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode1"); registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode1");
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red"); registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
@ -113,7 +113,7 @@ describe("red/nodes/registry/loader",function() {
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red'); registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err'); registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
nodes.registerType.calledOnce.should.be.true; nodes.registerType.calledOnce.should.be.true();
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode1'); nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode1');
nodes.registerType.lastCall.args[1].should.eql('test-node-1'); nodes.registerType.lastCall.args[1].should.eql('test-node-1');
@ -146,7 +146,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) { loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true; registry.addNodeSet.called.should.be.true();
registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1"); registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/MultipleNodes1"); registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/MultipleNodes1");
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red"); registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
@ -162,7 +162,7 @@ describe("red/nodes/registry/loader",function() {
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red'); registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err'); registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
nodes.registerType.calledTwice.should.be.true; nodes.registerType.calledTwice.should.be.true();
nodes.registerType.firstCall.args[0].should.eql('node-red/MultipleNodes1'); nodes.registerType.firstCall.args[0].should.eql('node-red/MultipleNodes1');
nodes.registerType.firstCall.args[1].should.eql('test-node-multiple-1a'); nodes.registerType.firstCall.args[1].should.eql('test-node-multiple-1a');
nodes.registerType.secondCall.args[0].should.eql('node-red/MultipleNodes1'); nodes.registerType.secondCall.args[0].should.eql('node-red/MultipleNodes1');
@ -199,7 +199,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) { loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true; registry.addNodeSet.called.should.be.true();
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2"); registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode2"); registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode2");
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red"); registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
@ -214,7 +214,7 @@ describe("red/nodes/registry/loader",function() {
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red'); registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err'); registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
nodes.registerType.calledOnce.should.be.true; nodes.registerType.calledOnce.should.be.true();
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode2'); nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode2');
nodes.registerType.lastCall.args[1].should.eql('test-node-2'); nodes.registerType.lastCall.args[1].should.eql('test-node-2');
@ -249,7 +249,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) { loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true; registry.addNodeSet.called.should.be.true();
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3"); registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode3"); registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode3");
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red"); registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
@ -264,7 +264,7 @@ describe("red/nodes/registry/loader",function() {
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red'); registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
registry.addNodeSet.lastCall.args[1].should.have.a.property('err','fail'); registry.addNodeSet.lastCall.args[1].should.have.a.property('err','fail');
nodes.registerType.calledOnce.should.be.false; nodes.registerType.calledOnce.should.be.false();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
@ -296,7 +296,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) { loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true; registry.addNodeSet.called.should.be.true();
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist"); registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DoesNotExist"); registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DoesNotExist");
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red"); registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
@ -310,7 +310,7 @@ describe("red/nodes/registry/loader",function() {
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red'); registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red');
registry.addNodeSet.lastCall.args[1].should.have.a.property('err'); registry.addNodeSet.lastCall.args[1].should.have.a.property('err');
nodes.registerType.calledOnce.should.be.false; nodes.registerType.calledOnce.should.be.false();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
@ -377,7 +377,7 @@ describe("red/nodes/registry/loader",function() {
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.addModule("TestNodeModule").then(function(result) { loader.addModule("TestNodeModule").then(function(result) {
result.should.eql("a node list"); result.should.eql("a node list");
registry.addNodeSet.calledOnce.should.be.true; registry.addNodeSet.calledOnce.should.be.true();
registry.addNodeSet.lastCall.args[0].should.eql("TestNodeModule/TestNode1"); registry.addNodeSet.lastCall.args[0].should.eql("TestNodeModule/TestNode1");
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"TestNodeModule/TestNode1"); registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"TestNodeModule/TestNode1");
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"TestNodeModule"); registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"TestNodeModule");
@ -392,7 +392,7 @@ describe("red/nodes/registry/loader",function() {
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','TestNodeModule'); registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','TestNodeModule');
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err'); registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
nodes.registerType.calledOnce.should.be.true; nodes.registerType.calledOnce.should.be.true();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
done(err); done(err);
@ -427,8 +427,8 @@ describe("red/nodes/registry/loader",function() {
loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}}); loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
loader.addModule("TestNodeModule").then(function(result) { loader.addModule("TestNodeModule").then(function(result) {
result.should.eql("a node list"); result.should.eql("a node list");
registry.addNodeSet.called.should.be.false; registry.addNodeSet.called.should.be.false();
nodes.registerType.called.should.be.false; nodes.registerType.called.should.be.false();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
done(err); done(err);
@ -448,8 +448,8 @@ describe("red/nodes/registry/loader",function() {
"name": "TestNode1", "name": "TestNode1",
"enabled": false "enabled": false
}).then(function(node) { }).then(function(node) {
node.enabled.should.be.false; node.enabled.should.be.false();
nodes.registerType.called.should.be.false; nodes.registerType.called.should.be.false();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
done(err); done(err);
@ -464,8 +464,8 @@ describe("red/nodes/registry/loader",function() {
"name": "TestNode4", "name": "TestNode4",
"enabled": true "enabled": true
}).then(function(node) { }).then(function(node) {
node.enabled.should.be.true; node.enabled.should.be.true();
nodes.registerType.called.should.be.false; nodes.registerType.called.should.be.false();
node.should.have.property('err'); node.should.have.property('err');
node.err.message.should.eql("fail to require"); node.err.message.should.eql("fail to require");
@ -495,10 +495,10 @@ describe("red/nodes/registry/loader",function() {
}; };
loader.getNodeHelp(node,"fr").should.eql("bar"); loader.getNodeHelp(node,"fr").should.eql("bar");
node.help['fr'].should.eql("bar"); node.help['fr'].should.eql("bar");
fs.readFileSync.calledOnce.should.be.true; fs.readFileSync.calledOnce.should.be.true();
fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html")); fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html"));
loader.getNodeHelp(node,"fr").should.eql("bar"); loader.getNodeHelp(node,"fr").should.eql("bar");
fs.readFileSync.calledOnce.should.be.true; fs.readFileSync.calledOnce.should.be.true();
}); });
it("loads help, defaulting to en-US content", function() { it("loads help, defaulting to en-US content", function() {
stubs.push(sinon.stub(fs,"readFileSync", function(path) { stubs.push(sinon.stub(fs,"readFileSync", function(path) {
@ -512,10 +512,10 @@ describe("red/nodes/registry/loader",function() {
loader.getNodeHelp(node,"fr").should.eql("foo"); loader.getNodeHelp(node,"fr").should.eql("foo");
node.help['fr'].should.eql("foo"); node.help['fr'].should.eql("foo");
fs.readFileSync.calledOnce.should.be.true; fs.readFileSync.calledOnce.should.be.true();
fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html")); fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html"));
loader.getNodeHelp(node,"fr").should.eql("foo"); loader.getNodeHelp(node,"fr").should.eql("foo");
fs.readFileSync.calledOnce.should.be.true; fs.readFileSync.calledOnce.should.be.true();
}); });
}); });

View File

@ -116,7 +116,7 @@ describe("red/nodes/registry/registry",function() {
var expected = JSON.parse('{"node-red":{"name":"node-red","nodes":{"sentiment":{"name":"sentiment","types":["sentiment"],"enabled":true,"module":"node-red"},"inject":{"name":"inject","types":["inject"],"enabled":true,"module":"node-red"}}},"testModule":{"name":"testModule","nodes":{"a-module.js":{"name":"a-module.js","types":["example"],"enabled":true,"module":"testModule"}}}}'); var expected = JSON.parse('{"node-red":{"name":"node-red","nodes":{"sentiment":{"name":"sentiment","types":["sentiment"],"enabled":true,"module":"node-red"},"inject":{"name":"inject","types":["inject"],"enabled":true,"module":"node-red"}}},"testModule":{"name":"testModule","nodes":{"a-module.js":{"name":"a-module.js","types":["example"],"enabled":true,"module":"testModule"}}}}');
typeRegistry.init(legacySettings); typeRegistry.init(legacySettings);
typeRegistry.load(); typeRegistry.load();
legacySettings.set.calledOnce.should.be.true; legacySettings.set.calledOnce.should.be.true();
legacySettings.set.args[0][1].should.eql(expected); legacySettings.set.args[0][1].should.eql(expected);
done(); done();
}); });
@ -242,7 +242,7 @@ describe("red/nodes/registry/registry",function() {
it('returns nothing for an unregistered type config', function(done) { it('returns nothing for an unregistered type config', function(done) {
typeRegistry.init(settings); typeRegistry.init(settings);
var config = typeRegistry.getNodeConfig("imaginary-shark"); var config = typeRegistry.getNodeConfig("imaginary-shark");
(config === null).should.be.true; (config === null).should.be.true();
done(); done();
}); });
}); });
@ -261,7 +261,7 @@ describe("red/nodes/registry/registry",function() {
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1"); typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1"); typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
typeRegistry.saveNodeList().then(function() { typeRegistry.saveNodeList().then(function() {
s.set.called.should.be.true; s.set.called.should.be.true();
s.set.lastCall.args[0].should.eql('nodes'); s.set.lastCall.args[0].should.eql('nodes');
var nodes = s.set.lastCall.args[1]; var nodes = s.set.lastCall.args[1];
nodes.should.have.property('test-module'); nodes.should.have.property('test-module');
@ -446,20 +446,20 @@ describe("red/nodes/registry/registry",function() {
}); });
it('registers a node constructor', function() { it('registers a node constructor', function() {
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor); typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
events.emit.calledOnce.should.be.true; events.emit.calledOnce.should.be.true();
events.emit.lastCall.args[0].should.eql('type-registered'); events.emit.lastCall.args[0].should.eql('type-registered');
events.emit.lastCall.args[1].should.eql('node-type'); events.emit.lastCall.args[1].should.eql('node-type');
}) })
it('throws error on duplicate node registration', function() { it('throws error on duplicate node registration', function() {
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor); typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
events.emit.calledOnce.should.be.true; events.emit.calledOnce.should.be.true();
events.emit.lastCall.args[0].should.eql('type-registered'); events.emit.lastCall.args[0].should.eql('type-registered');
events.emit.lastCall.args[1].should.eql('node-type'); events.emit.lastCall.args[1].should.eql('node-type');
/*jshint immed: false */ /*jshint immed: false */
(function(){ (function(){
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor); typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
}).should.throw("node-type already registered"); }).should.throw("node-type already registered");
events.emit.calledOnce.should.be.true; events.emit.calledOnce.should.be.true();
}); });
it('extends a constructor with the Node constructor', function() { it('extends a constructor with the Node constructor', function() {
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node); TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);

View File

@ -33,16 +33,16 @@ describe("red/settings", function() {
} }
settings.init(userSettings); settings.init(userSettings);
settings.available().should.be.false; settings.available().should.be.false();
settings.a.should.equal(123); settings.a.should.equal(123);
settings.b.should.equal("test"); settings.b.should.equal("test");
settings.c.should.be.an.Array; settings.c.should.be.an.Array();
settings.c.should.have.lengthOf(3); settings.c.should.have.lengthOf(3);
settings.get("a").should.equal(123); settings.get("a").should.equal(123);
settings.get("b").should.equal("test"); settings.get("b").should.equal("test");
settings.get("c").should.be.an.Array; settings.get("c").should.be.an.Array();
settings.get("c").should.have.lengthOf(3); settings.get("c").should.have.lengthOf(3);
/*jshint immed: false */ /*jshint immed: false */
@ -51,7 +51,7 @@ describe("red/settings", function() {
}).should.throw(); }).should.throw();
settings.c.push(5); settings.c.push(5);
settings.c.should.be.an.Array; settings.c.should.be.an.Array();
settings.c.should.have.lengthOf(4); settings.c.should.have.lengthOf(4);
/*jshint immed: false */ /*jshint immed: false */
@ -96,14 +96,14 @@ describe("red/settings", function() {
} }
settings.init(userSettings); settings.init(userSettings);
settings.available().should.be.false; settings.available().should.be.false();
/*jshint immed: false */ /*jshint immed: false */
(function() { (function() {
settings.get("unknown"); settings.get("unknown");
}).should.throw(); }).should.throw();
settings.load(storage).then(function() { settings.load(storage).then(function() {
settings.available().should.be.true; settings.available().should.be.true();
settings.get("globalA").should.equal(789); settings.get("globalA").should.equal(789);
settings.set("globalA","abc").then(function() { settings.set("globalA","abc").then(function() {
savedSettings.globalA.should.equal("abc"); savedSettings.globalA.should.equal("abc");
@ -128,11 +128,11 @@ describe("red/settings", function() {
} }
settings.init(userSettings); settings.init(userSettings);
settings.available().should.be.false; settings.available().should.be.false();
settings.should.have.property("a",123); settings.should.have.property("a",123);
settings.should.have.property("b","test"); settings.should.have.property("b","test");
settings.c.should.be.an.Array; settings.c.should.be.an.Array();
settings.c.should.have.lengthOf(3); settings.c.should.have.lengthOf(3);
settings.reset(); settings.reset();

View File

@ -56,11 +56,11 @@ describe("red/storage/index", function() {
}; };
storage.init(setsBooleanModule); storage.init(setsBooleanModule);
initSetsMeToTrue.should.be.true; initSetsMeToTrue.should.be.true();
done(); done();
}); });
it('respects storage interface', function() { it('respects storage interface', function(done) {
var calledFlagGetFlows = false; var calledFlagGetFlows = false;
var calledFlagGetCredentials = false; var calledFlagGetCredentials = false;
var calledFlagGetAllFlows = false; var calledFlagGetAllFlows = false;
@ -70,7 +70,7 @@ describe("red/storage/index", function() {
var interfaceCheckerModule = { var interfaceCheckerModule = {
init : function (settings) { init : function (settings) {
settings.should.be.an.Object; settings.should.be.an.Object();
calledInit = true; calledInit = true;
}, },
getFlows : function() { getFlows : function() {
@ -78,7 +78,8 @@ describe("red/storage/index", function() {
return when.resolve([]); return when.resolve([]);
}, },
saveFlows : function (flows) { saveFlows : function (flows) {
flows.should.be.true; flows.should.be.an.Array();
flows.should.have.lengthOf(0);
return when.resolve(""); return when.resolve("");
}, },
getCredentials : function() { getCredentials : function() {
@ -86,19 +87,19 @@ describe("red/storage/index", function() {
return when.resolve({}); return when.resolve({});
}, },
saveCredentials : function(credentials) { saveCredentials : function(credentials) {
credentials.should.be.true; credentials.should.be.true();
}, },
getSettings : function() { getSettings : function() {
calledFlagGetSettings = true; calledFlagGetSettings = true;
}, },
saveSettings : function(settings) { saveSettings : function(settings) {
settings.should.be.true; settings.should.be.true();
}, },
getSessions : function() { getSessions : function() {
calledFlagGetSessions = true; calledFlagGetSessions = true;
}, },
saveSessions : function(sessions) { saveSessions : function(sessions) {
sessions.should.be.true; sessions.should.be.true();
}, },
getAllFlows : function() { getAllFlows : function() {
calledFlagGetAllFlows = true; calledFlagGetAllFlows = true;
@ -108,17 +109,17 @@ describe("red/storage/index", function() {
}, },
saveFlow : function(fn, data) { saveFlow : function(fn, data) {
fn.should.equal("name"); fn.should.equal("name");
data.should.be.true; data.should.be.true();
}, },
getLibraryEntry : function(type, path) { getLibraryEntry : function(type, path) {
type.should.be.true; type.should.be.true();
path.should.equal("name"); path.should.equal("name");
}, },
saveLibraryEntry : function(type, path, meta, body) { saveLibraryEntry : function(type, path, meta, body) {
type.should.be.true; type.should.be.true();
path.should.equal("name"); path.should.equal("name");
meta.should.be.true; meta.should.be.true();
body.should.be.true; body.should.be.true();
} }
}; };
@ -128,9 +129,10 @@ describe("red/storage/index", function() {
} }
}; };
var promises = [];
storage.init(moduleToLoad); storage.init(moduleToLoad);
storage.getFlows(); promises.push(storage.getFlows());
storage.saveFlows({flows:[],credentials:{}}); promises.push(storage.saveFlows({flows:[],credentials:{}}));
storage.getSettings(); storage.getSettings();
storage.saveSettings(true); storage.saveSettings(true);
storage.getSessions(); storage.getSessions();
@ -141,10 +143,17 @@ describe("red/storage/index", function() {
storage.getLibraryEntry(true, "name"); storage.getLibraryEntry(true, "name");
storage.saveLibraryEntry(true, "name", true, true); storage.saveLibraryEntry(true, "name", true, true);
calledInit.should.be.true; when.settle(promises).then(function() {
calledFlagGetFlows.should.be.true; try {
calledFlagGetCredentials.should.be.true; calledInit.should.be.true();
calledFlagGetAllFlows.should.be.true; calledFlagGetFlows.should.be.true();
calledFlagGetCredentials.should.be.true();
calledFlagGetAllFlows.should.be.true();
done();
} catch(err) {
done(err);
}
});
}); });
describe('respects deprecated flow library functions', function() { describe('respects deprecated flow library functions', function() {
@ -156,7 +165,7 @@ describe("red/storage/index", function() {
var interfaceCheckerModule = { var interfaceCheckerModule = {
init : function (settings) { init : function (settings) {
settings.should.be.an.Object; settings.should.be.an.Object();
}, },
getLibraryEntry : function(type, path) { getLibraryEntry : function(type, path) {
if (type === "flows") { if (type === "flows") {

View File

@ -34,8 +34,8 @@ describe('LocalFileSystem', function() {
it('should initialise the user directory',function(done) { it('should initialise the user directory',function(done) {
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
fs.existsSync(path.join(userDir,"lib")).should.be.true; fs.existsSync(path.join(userDir,"lib")).should.be.true();
fs.existsSync(path.join(userDir,"lib",'flows')).should.be.true; fs.existsSync(path.join(userDir,"lib",'flows')).should.be.true();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
done(err); done(err);
@ -51,8 +51,8 @@ describe('LocalFileSystem', function() {
var settings = {}; var settings = {};
localfilesystem.init(settings).then(function() { localfilesystem.init(settings).then(function() {
try { try {
fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib")).should.be.true; fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib")).should.be.true();
fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib",'flows')).should.be.true; fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib",'flows')).should.be.true();
settings.userDir.should.equal(process.env.NODE_RED_HOME); settings.userDir.should.equal(process.env.NODE_RED_HOME);
done(); done();
} catch(err) { } catch(err) {
@ -75,8 +75,8 @@ describe('LocalFileSystem', function() {
var settings = {}; var settings = {};
localfilesystem.init(settings).then(function() { localfilesystem.init(settings).then(function() {
try { try {
fs.existsSync(path.join(process.env.HOME,".node-red","lib")).should.be.true; fs.existsSync(path.join(process.env.HOME,".node-red","lib")).should.be.true();
fs.existsSync(path.join(process.env.HOME,".node-red","lib",'flows')).should.be.true; fs.existsSync(path.join(process.env.HOME,".node-red","lib",'flows')).should.be.true();
settings.userDir.should.equal(path.join(process.env.HOME,".node-red")); settings.userDir.should.equal(path.join(process.env.HOME,".node-red"));
done(); done();
} catch(err) { } catch(err) {
@ -94,7 +94,7 @@ describe('LocalFileSystem', function() {
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
var flowFile = 'flows_'+require('os').hostname()+'.json'; var flowFile = 'flows_'+require('os').hostname()+'.json';
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
fs.existsSync(flowFilePath).should.be.false; fs.existsSync(flowFilePath).should.be.false();
localfilesystem.getFlows().then(function(flows) { localfilesystem.getFlows().then(function(flows) {
flows.should.eql([]); flows.should.eql([]);
done(); done();
@ -112,7 +112,7 @@ describe('LocalFileSystem', function() {
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup"); var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
fs.closeSync(fs.openSync(flowFilePath, 'w')); fs.closeSync(fs.openSync(flowFilePath, 'w'));
fs.existsSync(flowFilePath).should.be.true; fs.existsSync(flowFilePath).should.be.true();
localfilesystem.getFlows().then(function(flows) { localfilesystem.getFlows().then(function(flows) {
flows.should.eql([]); flows.should.eql([]);
done(); done();
@ -130,10 +130,10 @@ describe('LocalFileSystem', function() {
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup"); var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
fs.closeSync(fs.openSync(flowFilePath, 'w')); fs.closeSync(fs.openSync(flowFilePath, 'w'));
fs.existsSync(flowFilePath).should.be.true; fs.existsSync(flowFilePath).should.be.true();
fs.existsSync(flowFileBackupPath).should.be.false; fs.existsSync(flowFileBackupPath).should.be.false();
fs.writeFileSync(flowFileBackupPath,JSON.stringify(testFlow)); fs.writeFileSync(flowFileBackupPath,JSON.stringify(testFlow));
fs.existsSync(flowFileBackupPath).should.be.true; fs.existsSync(flowFileBackupPath).should.be.true();
localfilesystem.getFlows().then(function(flows) { localfilesystem.getFlows().then(function(flows) {
flows.should.eql(testFlow); flows.should.eql(testFlow);
done(); done();
@ -150,11 +150,11 @@ describe('LocalFileSystem', function() {
var flowFile = 'flows_'+require('os').hostname()+'.json'; var flowFile = 'flows_'+require('os').hostname()+'.json';
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup"); var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
fs.existsSync(flowFilePath).should.be.false; fs.existsSync(flowFilePath).should.be.false();
fs.existsSync(flowFileBackupPath).should.be.false; fs.existsSync(flowFileBackupPath).should.be.false();
localfilesystem.saveFlows(testFlow).then(function() { localfilesystem.saveFlows(testFlow).then(function() {
fs.existsSync(flowFilePath).should.be.true; fs.existsSync(flowFilePath).should.be.true();
fs.existsSync(flowFileBackupPath).should.be.false; fs.existsSync(flowFileBackupPath).should.be.false();
localfilesystem.getFlows().then(function(flows) { localfilesystem.getFlows().then(function(flows) {
flows.should.eql(testFlow); flows.should.eql(testFlow);
done(); done();
@ -176,12 +176,12 @@ describe('LocalFileSystem', function() {
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
fs.existsSync(defaultFlowFilePath).should.be.false; fs.existsSync(defaultFlowFilePath).should.be.false();
fs.existsSync(flowFilePath).should.be.false; fs.existsSync(flowFilePath).should.be.false();
localfilesystem.saveFlows(testFlow).then(function() { localfilesystem.saveFlows(testFlow).then(function() {
fs.existsSync(defaultFlowFilePath).should.be.false; fs.existsSync(defaultFlowFilePath).should.be.false();
fs.existsSync(flowFilePath).should.be.true; fs.existsSync(flowFilePath).should.be.true();
localfilesystem.getFlows().then(function(flows) { localfilesystem.getFlows().then(function(flows) {
flows.should.eql(testFlow); flows.should.eql(testFlow);
done(); done();
@ -225,21 +225,21 @@ describe('LocalFileSystem', function() {
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup"); var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
fs.existsSync(defaultFlowFilePath).should.be.false; fs.existsSync(defaultFlowFilePath).should.be.false();
fs.existsSync(flowFilePath).should.be.false; fs.existsSync(flowFilePath).should.be.false();
fs.existsSync(flowFileBackupPath).should.be.false; fs.existsSync(flowFileBackupPath).should.be.false();
localfilesystem.saveFlows(testFlow).then(function() { localfilesystem.saveFlows(testFlow).then(function() {
fs.existsSync(flowFileBackupPath).should.be.false; fs.existsSync(flowFileBackupPath).should.be.false();
fs.existsSync(defaultFlowFilePath).should.be.false; fs.existsSync(defaultFlowFilePath).should.be.false();
fs.existsSync(flowFilePath).should.be.true; fs.existsSync(flowFilePath).should.be.true();
var content = fs.readFileSync(flowFilePath,'utf8'); var content = fs.readFileSync(flowFilePath,'utf8');
var testFlow2 = [{"type":"tab","id":"bc5672ad.2741d8","label":"Sheet 2"}]; var testFlow2 = [{"type":"tab","id":"bc5672ad.2741d8","label":"Sheet 2"}];
localfilesystem.saveFlows(testFlow2).then(function() { localfilesystem.saveFlows(testFlow2).then(function() {
fs.existsSync(flowFileBackupPath).should.be.true; fs.existsSync(flowFileBackupPath).should.be.true();
fs.existsSync(defaultFlowFilePath).should.be.false; fs.existsSync(defaultFlowFilePath).should.be.false();
fs.existsSync(flowFilePath).should.be.true; fs.existsSync(flowFilePath).should.be.true();
var backupContent = fs.readFileSync(flowFileBackupPath,'utf8'); var backupContent = fs.readFileSync(flowFileBackupPath,'utf8');
content.should.equal(backupContent); content.should.equal(backupContent);
var content2 = fs.readFileSync(flowFilePath,'utf8'); var content2 = fs.readFileSync(flowFilePath,'utf8');
@ -265,7 +265,7 @@ describe('LocalFileSystem', function() {
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
var credFile = path.join(userDir,"test_cred.json"); var credFile = path.join(userDir,"test_cred.json");
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
fs.existsSync(credFile).should.be.false; fs.existsSync(credFile).should.be.false();
localfilesystem.getCredentials().then(function(creds) { localfilesystem.getCredentials().then(function(creds) {
creds.should.eql({}); creds.should.eql({});
@ -285,12 +285,12 @@ describe('LocalFileSystem', function() {
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
fs.existsSync(credFile).should.be.false; fs.existsSync(credFile).should.be.false();
var credentials = {"abc":{"type":"creds"}}; var credentials = {"abc":{"type":"creds"}};
localfilesystem.saveCredentials(credentials).then(function() { localfilesystem.saveCredentials(credentials).then(function() {
fs.existsSync(credFile).should.be.true; fs.existsSync(credFile).should.be.true();
localfilesystem.getCredentials().then(function(creds) { localfilesystem.getCredentials().then(function(creds) {
creds.should.eql(credentials); creds.should.eql(credentials);
done(); done();
@ -316,14 +316,14 @@ describe('LocalFileSystem', function() {
fs.writeFileSync(credFile,"{}","utf8"); fs.writeFileSync(credFile,"{}","utf8");
fs.existsSync(credFile).should.be.true; fs.existsSync(credFile).should.be.true();
fs.existsSync(credFileBackup).should.be.false; fs.existsSync(credFileBackup).should.be.false();
var credentials = {"abc":{"type":"creds"}}; var credentials = {"abc":{"type":"creds"}};
localfilesystem.saveCredentials(credentials).then(function() { localfilesystem.saveCredentials(credentials).then(function() {
fs.existsSync(credFile).should.be.true; fs.existsSync(credFile).should.be.true();
fs.existsSync(credFileBackup).should.be.true; fs.existsSync(credFileBackup).should.be.true();
done(); done();
}).otherwise(function(err) { }).otherwise(function(err) {
done(err); done(err);
@ -341,12 +341,12 @@ describe('LocalFileSystem', function() {
localfilesystem.init({userDir:userDir, flowFile:flowFilePath, flowFilePretty:true}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath, flowFilePretty:true}).then(function() {
fs.existsSync(credFile).should.be.false; fs.existsSync(credFile).should.be.false();
var credentials = {"abc":{"type":"creds"}}; var credentials = {"abc":{"type":"creds"}};
localfilesystem.saveCredentials(credentials).then(function() { localfilesystem.saveCredentials(credentials).then(function() {
fs.existsSync(credFile).should.be.true; fs.existsSync(credFile).should.be.true();
var content = fs.readFileSync(credFile,"utf8"); var content = fs.readFileSync(credFile,"utf8");
content.split("\n").length.should.be.above(1); content.split("\n").length.should.be.above(1);
localfilesystem.getCredentials().then(function(creds) { localfilesystem.getCredentials().then(function(creds) {
@ -367,7 +367,7 @@ describe('LocalFileSystem', function() {
var settingsFile = path.join(userDir,".settings.json"); var settingsFile = path.join(userDir,".settings.json");
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
fs.existsSync(settingsFile).should.be.false; fs.existsSync(settingsFile).should.be.false();
localfilesystem.getSettings().then(function(settings) { localfilesystem.getSettings().then(function(settings) {
settings.should.eql({}); settings.should.eql({});
done(); done();
@ -383,7 +383,7 @@ describe('LocalFileSystem', function() {
var settingsFile = path.join(userDir,".config.json"); var settingsFile = path.join(userDir,".config.json");
fs.writeFileSync(settingsFile,"[This is not json","utf8"); fs.writeFileSync(settingsFile,"[This is not json","utf8");
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
fs.existsSync(settingsFile).should.be.true; fs.existsSync(settingsFile).should.be.true();
localfilesystem.getSettings().then(function(settings) { localfilesystem.getSettings().then(function(settings) {
settings.should.eql({}); settings.should.eql({});
done(); done();
@ -399,12 +399,12 @@ describe('LocalFileSystem', function() {
var settingsFile = path.join(userDir,".config.json"); var settingsFile = path.join(userDir,".config.json");
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
fs.existsSync(settingsFile).should.be.false; fs.existsSync(settingsFile).should.be.false();
var settings = {"abc":{"type":"creds"}}; var settings = {"abc":{"type":"creds"}};
localfilesystem.saveSettings(settings).then(function() { localfilesystem.saveSettings(settings).then(function() {
fs.existsSync(settingsFile).should.be.true; fs.existsSync(settingsFile).should.be.true();
localfilesystem.getSettings().then(function(_settings) { localfilesystem.getSettings().then(function(_settings) {
_settings.should.eql(settings); _settings.should.eql(settings);
done(); done();
@ -423,7 +423,7 @@ describe('LocalFileSystem', function() {
var sessionsFile = path.join(userDir,".sessions.json"); var sessionsFile = path.join(userDir,".sessions.json");
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
fs.existsSync(sessionsFile).should.be.false; fs.existsSync(sessionsFile).should.be.false();
localfilesystem.getSessions().then(function(sessions) { localfilesystem.getSessions().then(function(sessions) {
sessions.should.eql({}); sessions.should.eql({});
done(); done();
@ -439,7 +439,7 @@ describe('LocalFileSystem', function() {
var sessionsFile = path.join(userDir,".sessions.json"); var sessionsFile = path.join(userDir,".sessions.json");
fs.writeFileSync(sessionsFile,"[This is not json","utf8"); fs.writeFileSync(sessionsFile,"[This is not json","utf8");
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
fs.existsSync(sessionsFile).should.be.true; fs.existsSync(sessionsFile).should.be.true();
localfilesystem.getSessions().then(function(sessions) { localfilesystem.getSessions().then(function(sessions) {
sessions.should.eql({}); sessions.should.eql({});
done(); done();
@ -455,12 +455,12 @@ describe('LocalFileSystem', function() {
var sessionsFile = path.join(userDir,".sessions.json"); var sessionsFile = path.join(userDir,".sessions.json");
localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.init({userDir:userDir}).then(function() {
fs.existsSync(sessionsFile).should.be.false; fs.existsSync(sessionsFile).should.be.false();
var sessions = {"abc":{"type":"creds"}}; var sessions = {"abc":{"type":"creds"}};
localfilesystem.saveSessions(sessions).then(function() { localfilesystem.saveSessions(sessions).then(function() {
fs.existsSync(sessionsFile).should.be.true; fs.existsSync(sessionsFile).should.be.true();
localfilesystem.getSessions().then(function(_sessions) { localfilesystem.getSessions().then(function(_sessions) {
_sessions.should.eql(sessions); _sessions.should.eql(sessions);
done(); done();