WIP: runtime api for node modules

This commit is contained in:
Nick O'Leary
2015-11-17 21:12:43 +00:00
parent f62b7afede
commit d673846e3d
10 changed files with 74 additions and 75 deletions

View File

@@ -44,7 +44,7 @@ describe("red/nodes/registry/loader",function() {
})
describe("#init",function() {
it("init",function() {
loader.init({});
loader.init({events:{on:function(){},removeListener:function(){}}});
localfilesystem.init.called.should.be.true;
});
});
@@ -53,7 +53,7 @@ describe("red/nodes/registry/loader",function() {
it("load empty set without settings available", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
loader.init({available:function(){return false;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
loader.load("foo",true).then(function() {
localfilesystem.getNodeFiles.called.should.be.true;
localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo');
@@ -65,7 +65,7 @@ describe("red/nodes/registry/loader",function() {
it("load empty set with settings available triggers registery save", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load("foo",true).then(function() {
registry.saveNodeList.called.should.be.true;
done();
@@ -96,7 +96,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true;
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
@@ -143,7 +143,7 @@ describe("red/nodes/registry/loader",function() {
// This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true;
registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
@@ -194,7 +194,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true;
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
@@ -243,7 +243,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true;
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
@@ -290,7 +290,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
registry.addNodeSet.called.should.be.true;
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
@@ -317,7 +317,7 @@ describe("red/nodes/registry/loader",function() {
describe("#addModule",function() {
it("throws error if settings unavailable", function() {
loader.init({available:function(){return false;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
/*jshint immed: false */
(function(){
loader.addModule("test-module");
@@ -326,7 +326,7 @@ describe("red/nodes/registry/loader",function() {
it("returns rejected error if module already loaded", function(done) {
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.addModule("test-module").otherwise(function(err) {
err.code.should.eql("module_already_loaded");
@@ -338,7 +338,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(localfilesystem,"getModuleFiles",function() {
throw new Error("failure");
}));
loader.init({available:function(){return true;}});
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
loader.addModule("test-module").otherwise(function(err) {
err.message.should.eql("failure");
done();
@@ -370,7 +370,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({available:function(){return true;}});
loader.init({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;
@@ -420,7 +420,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({available:function(){return true;}});
loader.init({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;

View File

@@ -45,7 +45,7 @@ describe("red/nodes/registry/localfilesystem",function() {
}
describe("#getNodeFiles",function() {
it("Finds all the node files in the resources tree",function(done) {
localfilesystem.init({});
localfilesystem.init({events:{emit:function(){}},settings:{}});
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red'];
@@ -56,7 +56,7 @@ describe("red/nodes/registry/localfilesystem",function() {
done();
});
it("Excludes node files from settings",function(done) {
localfilesystem.init({nodesExcludes:['TestNode1.js']});
localfilesystem.init({events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js']}});
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red'];
@@ -66,7 +66,7 @@ describe("red/nodes/registry/localfilesystem",function() {
done();
});
it("Finds nodes in userDir/nodes",function(done) {
localfilesystem.init({userDir:userDir});
localfilesystem.init({events:{emit:function(){}},settings:{userDir:userDir}});
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red'];
@@ -77,7 +77,7 @@ describe("red/nodes/registry/localfilesystem",function() {
});
it("Finds nodes in settings.nodesDir (string)",function(done) {
localfilesystem.init({nodesDir:userDir});
localfilesystem.init({events:{emit:function(){}},settings:{nodesDir:userDir}});
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red'];
@@ -87,7 +87,7 @@ describe("red/nodes/registry/localfilesystem",function() {
done();
});
it("Finds nodes in settings.nodesDir (array)",function(done) {
localfilesystem.init({nodesDir:[userDir]});
localfilesystem.init({events:{emit:function(){}},settings:{nodesDir:[userDir]}});
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red'];
@@ -106,7 +106,7 @@ describe("red/nodes/registry/localfilesystem",function() {
}
return _join.apply(null,arguments);
}));
localfilesystem.init({});
localfilesystem.init({events:{emit:function(){}},settings:{}});
var nodeList = localfilesystem.getNodeFiles(moduleDir,false);
nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red'];
@@ -126,6 +126,9 @@ describe("red/nodes/registry/localfilesystem",function() {
done();
});
it.skip("finds locales directory");
it.skip("finds icon path directory");
});
describe("#getModuleFiles",function() {
it("gets a nodes module files",function(done) {
@@ -138,7 +141,7 @@ describe("red/nodes/registry/localfilesystem",function() {
}
return _join.apply(null,arguments);
}));
localfilesystem.init({},moduleDir,true);
localfilesystem.init({events:{emit:function(){}},settings:{}},moduleDir,true);
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
nodeModule.should.have.a.property('TestNodeModule');
nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule');
@@ -162,12 +165,14 @@ describe("red/nodes/registry/localfilesystem",function() {
}
return _join.apply(null,arguments);
}));
localfilesystem.init({},moduleDir,true);
localfilesystem.init({events:{emit:function(){}},settings:{}},moduleDir,true);
/*jshint immed: false */
(function(){
localfilesystem.getModuleFiles('WontExistModule');
}).should.throw();
done();
});
it.skip("finds locales directory");
it.skip("finds icon path directory");
});
});