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

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

View File

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

View File

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

View File

@@ -45,7 +45,7 @@ describe("red/nodes/registry/loader",function() {
describe("#init",function() {
it("init",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 {};}));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
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[1].should.be.true;
registry.saveNodeList.called.should.be.false;
localfilesystem.getNodeFiles.lastCall.args[1].should.be.true();
registry.saveNodeList.called.should.be.false();
done();
})
});
@@ -67,7 +67,7 @@ describe("red/nodes/registry/loader",function() {
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.load("foo",true).then(function() {
registry.saveNodeList.called.should.be.true;
registry.saveNodeList.called.should.be.true();
done();
}).otherwise(function(err) {
done(err);
@@ -98,7 +98,7 @@ describe("red/nodes/registry/loader",function() {
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.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[1].should.have.a.property('id',"node-red/TestNode1");
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.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[1].should.eql('test-node-1');
@@ -146,7 +146,7 @@ describe("red/nodes/registry/loader",function() {
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.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[1].should.have.a.property('id',"node-red/MultipleNodes1");
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.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[1].should.eql('test-node-multiple-1a');
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"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
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[1].should.have.a.property('id',"node-red/TestNode2");
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.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[1].should.eql('test-node-2');
@@ -249,7 +249,7 @@ describe("red/nodes/registry/loader",function() {
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.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[1].should.have.a.property('id',"node-red/TestNode3");
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('err','fail');
nodes.registerType.calledOnce.should.be.false;
nodes.registerType.calledOnce.should.be.false();
done();
}).otherwise(function(err) {
@@ -296,7 +296,7 @@ describe("red/nodes/registry/loader",function() {
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.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[1].should.have.a.property('id',"node-red/DoesNotExist");
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.have.a.property('err');
nodes.registerType.calledOnce.should.be.false;
nodes.registerType.calledOnce.should.be.false();
done();
}).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.addModule("TestNodeModule").then(function(result) {
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[1].should.have.a.property('id',"TestNodeModule/TestNode1");
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.not.have.a.property('err');
nodes.registerType.calledOnce.should.be.true;
nodes.registerType.calledOnce.should.be.true();
done();
}).otherwise(function(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.addModule("TestNodeModule").then(function(result) {
result.should.eql("a node list");
registry.addNodeSet.called.should.be.false;
nodes.registerType.called.should.be.false;
registry.addNodeSet.called.should.be.false();
nodes.registerType.called.should.be.false();
done();
}).otherwise(function(err) {
done(err);
@@ -448,8 +448,8 @@ describe("red/nodes/registry/loader",function() {
"name": "TestNode1",
"enabled": false
}).then(function(node) {
node.enabled.should.be.false;
nodes.registerType.called.should.be.false;
node.enabled.should.be.false();
nodes.registerType.called.should.be.false();
done();
}).otherwise(function(err) {
done(err);
@@ -464,8 +464,8 @@ describe("red/nodes/registry/loader",function() {
"name": "TestNode4",
"enabled": true
}).then(function(node) {
node.enabled.should.be.true;
nodes.registerType.called.should.be.false;
node.enabled.should.be.true();
nodes.registerType.called.should.be.false();
node.should.have.property('err');
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");
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"));
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() {
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");
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"));
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"}}}}');
typeRegistry.init(legacySettings);
typeRegistry.load();
legacySettings.set.calledOnce.should.be.true;
legacySettings.set.calledOnce.should.be.true();
legacySettings.set.args[0][1].should.eql(expected);
done();
});
@@ -242,7 +242,7 @@ describe("red/nodes/registry/registry",function() {
it('returns nothing for an unregistered type config', function(done) {
typeRegistry.init(settings);
var config = typeRegistry.getNodeConfig("imaginary-shark");
(config === null).should.be.true;
(config === null).should.be.true();
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-2",testNodeSet2WithError, "0.0.1");
typeRegistry.saveNodeList().then(function() {
s.set.called.should.be.true;
s.set.called.should.be.true();
s.set.lastCall.args[0].should.eql('nodes');
var nodes = s.set.lastCall.args[1];
nodes.should.have.property('test-module');
@@ -446,20 +446,20 @@ describe("red/nodes/registry/registry",function() {
});
it('registers a node constructor', function() {
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[1].should.eql('node-type');
})
it('throws error on duplicate node registration', function() {
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[1].should.eql('node-type');
/*jshint immed: false */
(function(){
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
}).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() {
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);