mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Registry tests for plugins and enable/disable in CLI
This commit is contained in:
parent
deeaa09360
commit
8d16f3c8be
@ -29,9 +29,9 @@ afterEach(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('NodeRegistry', function() {
|
describe('NodeRegistry', function() {
|
||||||
|
|
||||||
var resourcesDir = __dirname+ path.sep + "resources" + path.sep;
|
var resourcesDir = __dirname+ path.sep + "resources" + path.sep;
|
||||||
|
|
||||||
function stubSettings(s,available) {
|
function stubSettings(s,available) {
|
||||||
s.available = function() {return available;}
|
s.available = function() {return available;}
|
||||||
s.set = function(s,v) { return when.resolve()},
|
s.set = function(s,v) { return when.resolve()},
|
||||||
@ -40,17 +40,17 @@ describe('NodeRegistry', function() {
|
|||||||
}
|
}
|
||||||
var settings = stubSettings({},false);
|
var settings = stubSettings({},false);
|
||||||
var settingsWithStorage = stubSettings({},true);
|
var settingsWithStorage = stubSettings({},true);
|
||||||
|
|
||||||
it('automatically registers new nodes',function() {
|
it('automatically registers new nodes',function() {
|
||||||
var testNode = RedNodes.getNode('123');
|
var testNode = RedNodes.getNode('123');
|
||||||
should.not.exist(n);
|
should.not.exist(n);
|
||||||
var n = new RedNode({id:'123',type:'abc'});
|
var n = new RedNode({id:'123',type:'abc'});
|
||||||
|
|
||||||
var newNode = RedNodes.getNode('123');
|
var newNode = RedNodes.getNode('123');
|
||||||
|
|
||||||
should.strictEqual(n,newNode);
|
should.strictEqual(n,newNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles nodes that export a function', function(done) {
|
it('handles nodes that export a function', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
||||||
@ -61,18 +61,18 @@ describe('NodeRegistry', function() {
|
|||||||
list[0].should.have.property("types",["test-node-1"]);
|
list[0].should.have.property("types",["test-node-1"]);
|
||||||
list[0].should.have.property("enabled",true);
|
list[0].should.have.property("enabled",true);
|
||||||
list[0].should.not.have.property("err");
|
list[0].should.not.have.property("err");
|
||||||
|
|
||||||
var nodeConstructor = typeRegistry.get("test-node-1");
|
var nodeConstructor = typeRegistry.get("test-node-1");
|
||||||
nodeConstructor.should.be.type("function");
|
nodeConstructor.should.be.type("function");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('handles nodes that export a function returning a resolving promise', function(done) {
|
it('handles nodes that export a function returning a resolving promise', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load(resourcesDir + "TestNode2",true).then(function() {
|
typeRegistry.load(resourcesDir + "TestNode2",true).then(function() {
|
||||||
@ -85,14 +85,14 @@ describe('NodeRegistry', function() {
|
|||||||
list[0].should.not.have.property("err");
|
list[0].should.not.have.property("err");
|
||||||
var nodeConstructor = typeRegistry.get("test-node-2");
|
var nodeConstructor = typeRegistry.get("test-node-2");
|
||||||
nodeConstructor.should.be.type("function");
|
nodeConstructor.should.be.type("function");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles nodes that export a function returning a rejecting promise', function(done) {
|
it('handles nodes that export a function returning a rejecting promise', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load(resourcesDir + "TestNode3",true).then(function() {
|
typeRegistry.load(resourcesDir + "TestNode3",true).then(function() {
|
||||||
@ -106,14 +106,14 @@ describe('NodeRegistry', function() {
|
|||||||
|
|
||||||
var nodeConstructor = typeRegistry.get("test-node-3");
|
var nodeConstructor = typeRegistry.get("test-node-3");
|
||||||
(nodeConstructor === null).should.be.true;
|
(nodeConstructor === null).should.be.true;
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles files containing multiple nodes', function(done) {
|
it('handles files containing multiple nodes', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load(resourcesDir + "MultipleNodes1",true).then(function() {
|
typeRegistry.load(resourcesDir + "MultipleNodes1",true).then(function() {
|
||||||
@ -124,19 +124,19 @@ describe('NodeRegistry', function() {
|
|||||||
list[0].should.have.property("types",["test-node-multiple-1a","test-node-multiple-1b"]);
|
list[0].should.have.property("types",["test-node-multiple-1a","test-node-multiple-1b"]);
|
||||||
list[0].should.have.property("enabled",true);
|
list[0].should.have.property("enabled",true);
|
||||||
list[0].should.not.have.property("err");
|
list[0].should.not.have.property("err");
|
||||||
|
|
||||||
var nodeConstructor = typeRegistry.get("test-node-multiple-1a");
|
var nodeConstructor = typeRegistry.get("test-node-multiple-1a");
|
||||||
nodeConstructor.should.be.type("function");
|
nodeConstructor.should.be.type("function");
|
||||||
|
|
||||||
nodeConstructor = typeRegistry.get("test-node-multiple-1b");
|
nodeConstructor = typeRegistry.get("test-node-multiple-1b");
|
||||||
nodeConstructor.should.be.type("function");
|
nodeConstructor.should.be.type("function");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles nested directories', function(done) {
|
it('handles nested directories', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load(resourcesDir + "NestedDirectoryNode",true).then(function() {
|
typeRegistry.load(resourcesDir + "NestedDirectoryNode",true).then(function() {
|
||||||
@ -152,7 +152,7 @@ describe('NodeRegistry', function() {
|
|||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits type-registered and node-icon-dir events', function(done) {
|
it('emits type-registered and node-icon-dir events', function(done) {
|
||||||
var eventEmitSpy = sinon.spy(events,"emit");
|
var eventEmitSpy = sinon.spy(events,"emit");
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
@ -163,16 +163,16 @@ describe('NodeRegistry', function() {
|
|||||||
list[0].should.have.property("types",["nested-node-1"]);
|
list[0].should.have.property("types",["nested-node-1"]);
|
||||||
list[0].should.have.property("enabled",true);
|
list[0].should.have.property("enabled",true);
|
||||||
list[0].should.not.have.property("err");
|
list[0].should.not.have.property("err");
|
||||||
|
|
||||||
eventEmitSpy.callCount.should.equal(2);
|
eventEmitSpy.callCount.should.equal(2);
|
||||||
|
|
||||||
eventEmitSpy.firstCall.args[0].should.be.equal("node-icon-dir");
|
eventEmitSpy.firstCall.args[0].should.be.equal("node-icon-dir");
|
||||||
eventEmitSpy.firstCall.args[1].should.be.equal(
|
eventEmitSpy.firstCall.args[1].should.be.equal(
|
||||||
resourcesDir + "NestedDirectoryNode" + path.sep + "NestedNode" + path.sep + "icons");
|
resourcesDir + "NestedDirectoryNode" + path.sep + "NestedNode" + path.sep + "icons");
|
||||||
|
|
||||||
eventEmitSpy.secondCall.args[0].should.be.equal("type-registered");
|
eventEmitSpy.secondCall.args[0].should.be.equal("type-registered");
|
||||||
eventEmitSpy.secondCall.args[1].should.be.equal("nested-node-1");
|
eventEmitSpy.secondCall.args[1].should.be.equal("nested-node-1");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
@ -180,25 +180,25 @@ describe('NodeRegistry', function() {
|
|||||||
eventEmitSpy.restore();
|
eventEmitSpy.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects a duplicate node type registration', function(done) {
|
it('rejects a duplicate node type registration', function(done) {
|
||||||
|
|
||||||
typeRegistry.init(stubSettings({
|
typeRegistry.init(stubSettings({
|
||||||
nodesDir:[resourcesDir + "TestNode1",resourcesDir + "DuplicateTestNode"]
|
nodesDir:[resourcesDir + "TestNode1",resourcesDir + "DuplicateTestNode"]
|
||||||
},false));
|
},false));
|
||||||
typeRegistry.load("wontexist",true).then(function() {
|
typeRegistry.load("wontexist",true).then(function() {
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
|
|
||||||
list.should.be.an.Array.and.have.lengthOf(2);
|
list.should.be.an.Array.and.have.lengthOf(2);
|
||||||
list[0].should.have.property("id");
|
list[0].should.have.property("id");
|
||||||
list[0].should.have.property("name","TestNode1.js");
|
list[0].should.have.property("name","TestNode1.js");
|
||||||
list[0].should.have.property("types",["test-node-1"]);
|
list[0].should.have.property("types",["test-node-1"]);
|
||||||
list[0].should.have.property("enabled",true);
|
list[0].should.have.property("enabled",true);
|
||||||
list[0].should.not.have.property("err");
|
list[0].should.not.have.property("err");
|
||||||
|
|
||||||
list[1].should.have.property("id");
|
list[1].should.have.property("id");
|
||||||
list[1].id.should.not.equal(list[0].id);
|
list[1].id.should.not.equal(list[0].id);
|
||||||
|
|
||||||
list[1].should.have.property("name","TestNode1.js");
|
list[1].should.have.property("name","TestNode1.js");
|
||||||
list[1].should.have.property("types",["test-node-1"]);
|
list[1].should.have.property("types",["test-node-1"]);
|
||||||
list[1].should.have.property("enabled",true);
|
list[1].should.have.property("enabled",true);
|
||||||
@ -208,13 +208,13 @@ describe('NodeRegistry', function() {
|
|||||||
var nodeConstructor = typeRegistry.get("test-node-1");
|
var nodeConstructor = typeRegistry.get("test-node-1");
|
||||||
// Verify the duplicate node hasn't replaced the original one
|
// Verify the duplicate node hasn't replaced the original one
|
||||||
nodeConstructor.name.should.be.equal("TestNode");
|
nodeConstructor.name.should.be.equal("TestNode");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles nodesDir as a string', function(done) {
|
it('handles nodesDir as a string', function(done) {
|
||||||
|
|
||||||
typeRegistry.init(stubSettings({
|
typeRegistry.init(stubSettings({
|
||||||
@ -228,9 +228,9 @@ describe('NodeRegistry', function() {
|
|||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done("Loading of non-existing nodesDir should succeed");
|
done("Loading of non-existing nodesDir should succeed");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles invalid nodesDir',function(done) {
|
it('handles invalid nodesDir',function(done) {
|
||||||
|
|
||||||
typeRegistry.init(stubSettings({
|
typeRegistry.init(stubSettings({
|
||||||
@ -244,7 +244,7 @@ describe('NodeRegistry', function() {
|
|||||||
done("Loading of non-existing nodesDir should succeed");
|
done("Loading of non-existing nodesDir should succeed");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns nothing for an unregistered type config', function() {
|
it('returns nothing for an unregistered type config', function() {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
@ -254,7 +254,7 @@ describe('NodeRegistry', function() {
|
|||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('excludes node files listed in nodesExcludes',function(done) {
|
it('excludes node files listed in nodesExcludes',function(done) {
|
||||||
typeRegistry.init(stubSettings({
|
typeRegistry.init(stubSettings({
|
||||||
nodesExcludes: [ "TestNode1.js" ],
|
nodesExcludes: [ "TestNode1.js" ],
|
||||||
@ -269,19 +269,19 @@ describe('NodeRegistry', function() {
|
|||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the node configurations', function(done) {
|
it('returns the node configurations', function(done) {
|
||||||
typeRegistry.init(stubSettings({
|
typeRegistry.init(stubSettings({
|
||||||
nodesDir:[resourcesDir + "TestNode1",resourcesDir + "TestNode2"]
|
nodesDir:[resourcesDir + "TestNode1",resourcesDir + "TestNode2"]
|
||||||
},false));
|
},false));
|
||||||
typeRegistry.load("wontexist",true).then(function() {
|
typeRegistry.load("wontexist",true).then(function() {
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
|
|
||||||
var nodeConfigs = typeRegistry.getNodeConfigs();
|
var nodeConfigs = typeRegistry.getNodeConfigs();
|
||||||
|
|
||||||
// TODO: this is brittle...
|
// TODO: this is brittle...
|
||||||
nodeConfigs.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n<script type=\"text/x-red\" data-template-name=\"test-node-2\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-2\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-2',{});</script>\n<style></style>\n");
|
nodeConfigs.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n<script type=\"text/x-red\" data-template-name=\"test-node-2\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-2\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-2',{});</script>\n<style></style>\n");
|
||||||
|
|
||||||
var nodeId = list[0].id;
|
var nodeId = list[0].id;
|
||||||
var nodeConfig = typeRegistry.getNodeConfig(nodeId);
|
var nodeConfig = typeRegistry.getNodeConfig(nodeId);
|
||||||
nodeConfig.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n");
|
nodeConfig.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n");
|
||||||
@ -290,7 +290,7 @@ describe('NodeRegistry', function() {
|
|||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stores the node list', function(done) {
|
it('stores the node list', function(done) {
|
||||||
var settings = {
|
var settings = {
|
||||||
nodesDir:[resourcesDir + "TestNode1",resourcesDir + "TestNode2",resourcesDir + "TestNode3"],
|
nodesDir:[resourcesDir + "TestNode1",resourcesDir + "TestNode2",resourcesDir + "TestNode3"],
|
||||||
@ -303,39 +303,39 @@ describe('NodeRegistry', function() {
|
|||||||
typeRegistry.load("wontexist",true).then(function() {
|
typeRegistry.load("wontexist",true).then(function() {
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.Array.and.have.length(3);
|
list.should.be.Array.and.have.length(3);
|
||||||
|
|
||||||
settingsSave.callCount.should.equal(1);
|
settingsSave.callCount.should.equal(1);
|
||||||
settingsSave.firstCall.args[0].should.be.equal("nodes");
|
settingsSave.firstCall.args[0].should.be.equal("nodes");
|
||||||
var savedList = settingsSave.firstCall.args[1];
|
var savedList = settingsSave.firstCall.args[1];
|
||||||
|
|
||||||
savedList[list[0].id].name == list[0].name;
|
savedList[list[0].id].name == list[0].name;
|
||||||
savedList[list[1].id].name == list[1].name;
|
savedList[list[1].id].name == list[1].name;
|
||||||
savedList[list[2].id].name == list[2].name;
|
savedList[list[2].id].name == list[2].name;
|
||||||
|
|
||||||
savedList[list[0].id].should.not.have.property("err");
|
savedList[list[0].id].should.not.have.property("err");
|
||||||
savedList[list[1].id].should.not.have.property("err");
|
savedList[list[1].id].should.not.have.property("err");
|
||||||
savedList[list[2].id].should.not.have.property("err");
|
savedList[list[2].id].should.not.have.property("err");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
settingsSave.restore();
|
settingsSave.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows nodes to be added by filename', function(done) {
|
it('allows nodes to be added by filename', function(done) {
|
||||||
var settings = {
|
var settings = {
|
||||||
available: function() { return true; },
|
available: function() { return true; },
|
||||||
set: function(s,v) {return when.resolve();},
|
set: function(s,v) {return when.resolve();},
|
||||||
get: function(s) { return null;}
|
get: function(s) { return null;}
|
||||||
}
|
}
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.be.empty;
|
list.should.be.an.Array.and.be.empty;
|
||||||
|
|
||||||
typeRegistry.addNode(resourcesDir + "TestNode1/TestNode1.js").then(function(node) {
|
typeRegistry.addNode(resourcesDir + "TestNode1/TestNode1.js").then(function(node) {
|
||||||
list = typeRegistry.getNodeList();
|
list = typeRegistry.getNodeList();
|
||||||
list[0].should.have.property("id");
|
list[0].should.have.property("id");
|
||||||
@ -343,20 +343,20 @@ describe('NodeRegistry', function() {
|
|||||||
list[0].should.have.property("types",["test-node-1"]);
|
list[0].should.have.property("types",["test-node-1"]);
|
||||||
list[0].should.have.property("enabled",true);
|
list[0].should.have.property("enabled",true);
|
||||||
list[0].should.not.have.property("err");
|
list[0].should.not.have.property("err");
|
||||||
|
|
||||||
node.should.be.an.Array.and.have.lengthOf(1);
|
node.should.be.an.Array.and.have.lengthOf(1);
|
||||||
node.should.eql(list);
|
node.should.eql(list);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails to add non-existent filename', function(done) {
|
it('fails to add non-existent filename', function(done) {
|
||||||
typeRegistry.init(settingsWithStorage);
|
typeRegistry.init(settingsWithStorage);
|
||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
@ -371,47 +371,149 @@ describe('NodeRegistry', function() {
|
|||||||
}).otherwise(function(e) {
|
}).otherwise(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns node info by type or id', function(done) {
|
it('returns node info by type or id', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.have.lengthOf(1);
|
list.should.be.an.Array.and.have.lengthOf(1);
|
||||||
|
|
||||||
var id = list[0].id;
|
var id = list[0].id;
|
||||||
var type = list[0].types[0];
|
var type = list[0].types[0];
|
||||||
|
|
||||||
list[0].should.have.property("id");
|
list[0].should.have.property("id");
|
||||||
list[0].should.have.property("name","TestNode1.js");
|
list[0].should.have.property("name","TestNode1.js");
|
||||||
list[0].should.have.property("types",["test-node-1"]);
|
list[0].should.have.property("types",["test-node-1"]);
|
||||||
list[0].should.have.property("enabled",true);
|
list[0].should.have.property("enabled",true);
|
||||||
list[0].should.not.have.property("err");
|
list[0].should.not.have.property("err");
|
||||||
|
|
||||||
var info = typeRegistry.getNodeInfo(id);
|
var info = typeRegistry.getNodeInfo(id);
|
||||||
list[0].should.eql(info);
|
list[0].should.eql(info);
|
||||||
|
|
||||||
var info2 = typeRegistry.getNodeInfo(type);
|
var info2 = typeRegistry.getNodeInfo(type);
|
||||||
list[0].should.eql(info2);
|
list[0].should.eql(info2);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns plugins list', function(done) {
|
||||||
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
|
|
||||||
|
var pathJoin = (function() {
|
||||||
|
var _join = path.join;
|
||||||
|
return sinon.stub(path,"join",function() {
|
||||||
|
if (arguments.length == 3 && arguments[2] == "package.json") {
|
||||||
|
return _join(resourcesDir,"TestNodeModule" + path.sep + "node_modules" + path.sep,arguments[1],arguments[2]);
|
||||||
|
}
|
||||||
|
if (arguments.length == 2 && arguments[1] == "TestNodeModule") {
|
||||||
|
return _join(resourcesDir,"TestNodeModule" + path.sep + "node_modules" + path.sep,arguments[1]);
|
||||||
|
}
|
||||||
|
return _join.apply(this,arguments);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
var readdirSync = (function() {
|
||||||
|
var originalReaddirSync = fs.readdirSync;
|
||||||
|
var callCount = 0;
|
||||||
|
return sinon.stub(fs,"readdirSync",function(dir) {
|
||||||
|
var result = [];
|
||||||
|
if (callCount == 1) {
|
||||||
|
result = originalReaddirSync(resourcesDir + "TestNodeModule" + path.sep + "node_modules");
|
||||||
|
}
|
||||||
|
callCount++;
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
typeRegistry.init(settingsWithStorage);
|
||||||
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
|
|
||||||
|
typeRegistry.addModule("TestNodeModule").then(function() {
|
||||||
|
var list = typeRegistry.getPluginList();
|
||||||
|
list.should.be.an.Array.and.have.lengthOf(1);
|
||||||
|
list[0].should.have.property("name", "TestNodeModule");
|
||||||
|
list[0].should.have.property("nodes");
|
||||||
|
list[0].nodes.should.be.an.Array.and.have.lengthOf(2);
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(function(e) {
|
||||||
|
done(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
}).catch(function(e) {
|
||||||
|
done(e);
|
||||||
|
}).finally(function() {
|
||||||
|
readdirSync.restore();
|
||||||
|
pathJoin.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns plugin info', function(done) {
|
||||||
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
|
|
||||||
|
var pathJoin = (function() {
|
||||||
|
var _join = path.join;
|
||||||
|
return sinon.stub(path,"join",function() {
|
||||||
|
if (arguments.length == 3 && arguments[2] == "package.json") {
|
||||||
|
return _join(resourcesDir,"TestNodeModule" + path.sep + "node_modules" + path.sep,arguments[1],arguments[2]);
|
||||||
|
}
|
||||||
|
if (arguments.length == 2 && arguments[1] == "TestNodeModule") {
|
||||||
|
return _join(resourcesDir,"TestNodeModule" + path.sep + "node_modules" + path.sep,arguments[1]);
|
||||||
|
}
|
||||||
|
return _join.apply(this,arguments);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
var readdirSync = (function() {
|
||||||
|
var originalReaddirSync = fs.readdirSync;
|
||||||
|
var callCount = 0;
|
||||||
|
return sinon.stub(fs,"readdirSync",function(dir) {
|
||||||
|
var result = [];
|
||||||
|
if (callCount == 1) {
|
||||||
|
result = originalReaddirSync(resourcesDir + "TestNodeModule" + path.sep + "node_modules");
|
||||||
|
}
|
||||||
|
callCount++;
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
typeRegistry.init(settingsWithStorage);
|
||||||
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
|
|
||||||
|
typeRegistry.addModule("TestNodeModule").then(function(nodes) {
|
||||||
|
var list = typeRegistry.getPluginList();
|
||||||
|
|
||||||
|
var plugin = typeRegistry.getPluginInfo(list[0].name);
|
||||||
|
plugin.should.have.property("name", list[0].name);
|
||||||
|
plugin.should.have.property("nodes", nodes);
|
||||||
|
done();
|
||||||
|
}).catch(function(e) {
|
||||||
|
done(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
}).catch(function(e) {
|
||||||
|
done(e);
|
||||||
|
}).finally(function() {
|
||||||
|
readdirSync.restore();
|
||||||
|
pathJoin.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects adding duplicate nodes', function(done) {
|
it('rejects adding duplicate nodes', function(done) {
|
||||||
typeRegistry.init(settingsWithStorage);
|
typeRegistry.init(settingsWithStorage);
|
||||||
typeRegistry.load(resourcesDir + "TestNode1",true).then(function(){
|
typeRegistry.load(resourcesDir + "TestNode1",true).then(function(){
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.have.lengthOf(1);
|
list.should.be.an.Array.and.have.lengthOf(1);
|
||||||
|
|
||||||
typeRegistry.addNode({file:resourcesDir + "TestNode1" + path.sep + "TestNode1.js"}).then(function(node) {
|
typeRegistry.addNode({file:resourcesDir + "TestNode1" + path.sep + "TestNode1.js"}).then(function(node) {
|
||||||
done(new Error("duplicate node loaded"));
|
done(new Error("duplicate node loaded"));
|
||||||
}).otherwise(function(e) {
|
}).otherwise(function(e) {
|
||||||
@ -419,12 +521,12 @@ describe('NodeRegistry', function() {
|
|||||||
list.should.be.an.Array.and.have.lengthOf(1);
|
list.should.be.an.Array.and.have.lengthOf(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes nodes from the registry', function(done) {
|
it('removes nodes from the registry', function(done) {
|
||||||
typeRegistry.init(settingsWithStorage);
|
typeRegistry.init(settingsWithStorage);
|
||||||
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
||||||
@ -437,33 +539,33 @@ describe('NodeRegistry', function() {
|
|||||||
list[0].should.have.property("loaded",true);
|
list[0].should.have.property("loaded",true);
|
||||||
|
|
||||||
typeRegistry.getNodeConfigs().length.should.be.greaterThan(0);
|
typeRegistry.getNodeConfigs().length.should.be.greaterThan(0);
|
||||||
|
|
||||||
var info = typeRegistry.removeNode(list[0].id);
|
var info = typeRegistry.removeNode(list[0].id);
|
||||||
|
|
||||||
info.should.have.property("id",list[0].id);
|
info.should.have.property("id",list[0].id);
|
||||||
info.should.have.property("enabled",false);
|
info.should.have.property("enabled",false);
|
||||||
info.should.have.property("loaded",false);
|
info.should.have.property("loaded",false);
|
||||||
|
|
||||||
typeRegistry.getNodeList().should.be.an.Array.and.be.empty;
|
typeRegistry.getNodeList().should.be.an.Array.and.be.empty;
|
||||||
typeRegistry.getNodeConfigs().length.should.equal(0);
|
typeRegistry.getNodeConfigs().length.should.equal(0);
|
||||||
|
|
||||||
var nodeConstructor = typeRegistry.get("test-node-1");
|
var nodeConstructor = typeRegistry.get("test-node-1");
|
||||||
(typeof nodeConstructor).should.be.equal("undefined");
|
(typeof nodeConstructor).should.be.equal("undefined");
|
||||||
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects removing unknown nodes from the registry', function(done) {
|
it('rejects removing unknown nodes from the registry', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load("wontexist",true).then(function() {
|
typeRegistry.load("wontexist",true).then(function() {
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.be.empty;
|
list.should.be.an.Array.and.be.empty;
|
||||||
|
|
||||||
|
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
(function() {
|
(function() {
|
||||||
typeRegistry.removeNode("1234");
|
typeRegistry.removeNode("1234");
|
||||||
@ -474,11 +576,11 @@ describe('NodeRegistry', function() {
|
|||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scans the node_modules path for node files', function(done) {
|
it('scans the node_modules path for node files', function(done) {
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
var eventEmitSpy = sinon.spy(events,"emit");
|
var eventEmitSpy = sinon.spy(events,"emit");
|
||||||
var pathJoin = (function() {
|
var pathJoin = (function() {
|
||||||
var _join = path.join;
|
var _join = path.join;
|
||||||
@ -492,7 +594,7 @@ describe('NodeRegistry', function() {
|
|||||||
return _join.apply(this,arguments);
|
return _join.apply(this,arguments);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var readdirSync = (function() {
|
var readdirSync = (function() {
|
||||||
var originalReaddirSync = fs.readdirSync;
|
var originalReaddirSync = fs.readdirSync;
|
||||||
var callCount = 0;
|
var callCount = 0;
|
||||||
@ -505,7 +607,7 @@ describe('NodeRegistry', function() {
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load("wontexist",false).then(function(){
|
typeRegistry.load("wontexist",false).then(function(){
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
@ -521,17 +623,17 @@ describe('NodeRegistry', function() {
|
|||||||
list[1].should.have.property("types",["test-node-mod-2"]);
|
list[1].should.have.property("types",["test-node-mod-2"]);
|
||||||
list[1].should.have.property("enabled",true);
|
list[1].should.have.property("enabled",true);
|
||||||
list[1].should.have.property("err");
|
list[1].should.have.property("err");
|
||||||
|
|
||||||
|
|
||||||
eventEmitSpy.callCount.should.equal(2);
|
eventEmitSpy.callCount.should.equal(2);
|
||||||
|
|
||||||
eventEmitSpy.firstCall.args[0].should.be.equal("node-icon-dir");
|
eventEmitSpy.firstCall.args[0].should.be.equal("node-icon-dir");
|
||||||
eventEmitSpy.firstCall.args[1].should.be.equal(
|
eventEmitSpy.firstCall.args[1].should.be.equal(
|
||||||
resourcesDir + "TestNodeModule" + path.sep+ "node_modules" + path.sep + "TestNodeModule" + path.sep + "icons");
|
resourcesDir + "TestNodeModule" + path.sep+ "node_modules" + path.sep + "TestNodeModule" + path.sep + "icons");
|
||||||
|
|
||||||
eventEmitSpy.secondCall.args[0].should.be.equal("type-registered");
|
eventEmitSpy.secondCall.args[0].should.be.equal("type-registered");
|
||||||
eventEmitSpy.secondCall.args[1].should.be.equal("test-node-mod-1");
|
eventEmitSpy.secondCall.args[1].should.be.equal("test-node-mod-1");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
@ -541,7 +643,7 @@ describe('NodeRegistry', function() {
|
|||||||
eventEmitSpy.restore();
|
eventEmitSpy.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows nodes to be added by module name', function(done) {
|
it('allows nodes to be added by module name', function(done) {
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
@ -558,7 +660,7 @@ describe('NodeRegistry', function() {
|
|||||||
return _join.apply(this,arguments);
|
return _join.apply(this,arguments);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var readdirSync = (function() {
|
var readdirSync = (function() {
|
||||||
var originalReaddirSync = fs.readdirSync;
|
var originalReaddirSync = fs.readdirSync;
|
||||||
var callCount = 0;
|
var callCount = 0;
|
||||||
@ -575,7 +677,7 @@ describe('NodeRegistry', function() {
|
|||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.be.empty;
|
list.should.be.an.Array.and.be.empty;
|
||||||
|
|
||||||
typeRegistry.addModule("TestNodeModule").then(function(node) {
|
typeRegistry.addModule("TestNodeModule").then(function(node) {
|
||||||
list = typeRegistry.getNodeList();
|
list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.have.lengthOf(2);
|
list.should.be.an.Array.and.have.lengthOf(2);
|
||||||
@ -590,14 +692,14 @@ describe('NodeRegistry', function() {
|
|||||||
list[1].should.have.property("types",["test-node-mod-2"]);
|
list[1].should.have.property("types",["test-node-mod-2"]);
|
||||||
list[1].should.have.property("enabled",true);
|
list[1].should.have.property("enabled",true);
|
||||||
list[1].should.have.property("err");
|
list[1].should.have.property("err");
|
||||||
|
|
||||||
node.should.eql(list);
|
node.should.eql(list);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
@ -605,8 +707,8 @@ describe('NodeRegistry', function() {
|
|||||||
pathJoin.restore();
|
pathJoin.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('rejects adding duplicate node modules', function(done) {
|
it('rejects adding duplicate node modules', function(done) {
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
@ -623,7 +725,7 @@ describe('NodeRegistry', function() {
|
|||||||
return _join.apply(this,arguments);
|
return _join.apply(this,arguments);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var readdirSync = (function() {
|
var readdirSync = (function() {
|
||||||
var originalReaddirSync = fs.readdirSync;
|
var originalReaddirSync = fs.readdirSync;
|
||||||
var callCount = 0;
|
var callCount = 0;
|
||||||
@ -653,26 +755,26 @@ describe('NodeRegistry', function() {
|
|||||||
pathJoin.restore();
|
pathJoin.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('fails to add non-existent module name', function(done) {
|
it('fails to add non-existent module name', function(done) {
|
||||||
typeRegistry.init(settingsWithStorage);
|
typeRegistry.init(settingsWithStorage);
|
||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.be.empty;
|
list.should.be.an.Array.and.be.empty;
|
||||||
|
|
||||||
typeRegistry.addModule("DoesNotExistModule").then(function(node) {
|
typeRegistry.addModule("DoesNotExistModule").then(function(node) {
|
||||||
done(new Error("ENOENT not thrown"));
|
done(new Error("ENOENT not thrown"));
|
||||||
}).otherwise(function(e) {
|
}).otherwise(function(e) {
|
||||||
e.code.should.eql("MODULE_NOT_FOUND");
|
e.code.should.eql("MODULE_NOT_FOUND");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes nodes from the registry by module', function(done) {
|
it('removes nodes from the registry by module', function(done) {
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
@ -689,7 +791,7 @@ describe('NodeRegistry', function() {
|
|||||||
return _join.apply(this,arguments);
|
return _join.apply(this,arguments);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var readdirSync = (function() {
|
var readdirSync = (function() {
|
||||||
var originalReaddirSync = fs.readdirSync;
|
var originalReaddirSync = fs.readdirSync;
|
||||||
var callCount = 0;
|
var callCount = 0;
|
||||||
@ -708,14 +810,14 @@ describe('NodeRegistry', function() {
|
|||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.have.lengthOf(2);
|
list.should.be.an.Array.and.have.lengthOf(2);
|
||||||
var res = typeRegistry.removeModule("TestNodeModule");
|
var res = typeRegistry.removeModule("TestNodeModule");
|
||||||
|
|
||||||
res.should.be.an.Array.and.have.lengthOf(2);
|
res.should.be.an.Array.and.have.lengthOf(2);
|
||||||
res[0].should.have.a.property("id",list[0].id);
|
res[0].should.have.a.property("id",list[0].id);
|
||||||
res[1].should.have.a.property("id",list[1].id);
|
res[1].should.have.a.property("id",list[1].id);
|
||||||
|
|
||||||
list = typeRegistry.getNodeList();
|
list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.be.empty;
|
list.should.be.an.Array.and.be.empty;
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
@ -723,29 +825,29 @@ describe('NodeRegistry', function() {
|
|||||||
readdirSync.restore();
|
readdirSync.restore();
|
||||||
pathJoin.restore();
|
pathJoin.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails to remove non-existent module name', function(done) {
|
it('fails to remove non-existent module name', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.be.empty;
|
list.should.be.an.Array.and.be.empty;
|
||||||
|
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
(function() {
|
(function() {
|
||||||
typeRegistry.removeModule("DoesNotExistModule");
|
typeRegistry.removeModule("DoesNotExistModule");
|
||||||
}).should.throw();
|
}).should.throw();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('allows nodes to be enabled and disabled', function(done) {
|
it('allows nodes to be enabled and disabled by hex-id', function(done) {
|
||||||
typeRegistry.init(settingsWithStorage);
|
typeRegistry.init(settingsWithStorage);
|
||||||
typeRegistry.load(resourcesDir+path.sep+"TestNode1",true).then(function() {
|
typeRegistry.load(resourcesDir+path.sep+"TestNode1",true).then(function() {
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
@ -753,28 +855,28 @@ describe('NodeRegistry', function() {
|
|||||||
list[0].should.have.property("id");
|
list[0].should.have.property("id");
|
||||||
list[0].should.have.property("name","TestNode1.js");
|
list[0].should.have.property("name","TestNode1.js");
|
||||||
list[0].should.have.property("enabled",true);
|
list[0].should.have.property("enabled",true);
|
||||||
|
|
||||||
var nodeConfig = typeRegistry.getNodeConfigs();
|
var nodeConfig = typeRegistry.getNodeConfigs();
|
||||||
nodeConfig.length.should.be.greaterThan(0);
|
nodeConfig.length.should.be.greaterThan(0);
|
||||||
|
|
||||||
var info = typeRegistry.disableNode(list[0].id);
|
var info = typeRegistry.disableNode(list[0].id);
|
||||||
info.should.have.property("id",list[0].id);
|
info.should.have.property("id",list[0].id);
|
||||||
info.should.have.property("enabled",false);
|
info.should.have.property("enabled",false);
|
||||||
|
|
||||||
var list2 = typeRegistry.getNodeList();
|
var list2 = typeRegistry.getNodeList();
|
||||||
list2.should.be.an.Array.and.have.lengthOf(1);
|
list2.should.be.an.Array.and.have.lengthOf(1);
|
||||||
list2[0].should.have.property("enabled",false);
|
list2[0].should.have.property("enabled",false);
|
||||||
|
|
||||||
typeRegistry.getNodeConfigs().length.should.equal(0);
|
typeRegistry.getNodeConfigs().length.should.equal(0);
|
||||||
|
|
||||||
var info2 = typeRegistry.enableNode(list[0].id);
|
var info2 = typeRegistry.enableNode(list[0].id);
|
||||||
info2.should.have.property("id",list[0].id);
|
info2.should.have.property("id",list[0].id);
|
||||||
info2.should.have.property("enabled",true);
|
info2.should.have.property("enabled",true);
|
||||||
|
|
||||||
var list3 = typeRegistry.getNodeList();
|
var list3 = typeRegistry.getNodeList();
|
||||||
list3.should.be.an.Array.and.have.lengthOf(1);
|
list3.should.be.an.Array.and.have.lengthOf(1);
|
||||||
list3[0].should.have.property("enabled",true);
|
list3[0].should.have.property("enabled",true);
|
||||||
|
|
||||||
var nodeConfig2 = typeRegistry.getNodeConfigs();
|
var nodeConfig2 = typeRegistry.getNodeConfigs();
|
||||||
nodeConfig2.should.eql(nodeConfig);
|
nodeConfig2.should.eql(nodeConfig);
|
||||||
|
|
||||||
@ -783,23 +885,66 @@ describe('NodeRegistry', function() {
|
|||||||
done(e);
|
done(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows nodes to be enabled and disabled by node-type', function(done) {
|
||||||
|
typeRegistry.init(settingsWithStorage);
|
||||||
|
typeRegistry.load(resourcesDir+path.sep+"TestNode1",true).then(function() {
|
||||||
|
var list = typeRegistry.getNodeList();
|
||||||
|
|
||||||
|
list.should.be.an.Array.and.have.lengthOf(1);
|
||||||
|
list[0].should.have.property("id");
|
||||||
|
list[0].should.have.property("name","TestNode1.js");
|
||||||
|
list[0].should.have.property("types",["test-node-1"]);
|
||||||
|
list[0].should.have.property("enabled",true);
|
||||||
|
|
||||||
|
var nodeConfig = typeRegistry.getNodeConfigs();
|
||||||
|
nodeConfig.length.should.be.greaterThan(0);
|
||||||
|
|
||||||
|
var info = typeRegistry.disableNode(list[0].types[0]);
|
||||||
|
info.should.have.property("id",list[0].id);
|
||||||
|
info.should.have.property("types",list[0].types);
|
||||||
|
info.should.have.property("enabled",false);
|
||||||
|
|
||||||
|
var list2 = typeRegistry.getNodeList();
|
||||||
|
list2.should.be.an.Array.and.have.lengthOf(1);
|
||||||
|
list2[0].should.have.property("enabled",false);
|
||||||
|
|
||||||
|
typeRegistry.getNodeConfigs().length.should.equal(0);
|
||||||
|
|
||||||
|
var info2 = typeRegistry.enableNode(list[0].types[0]);
|
||||||
|
info2.should.have.property("id",list[0].id);
|
||||||
|
info2.should.have.property("types",list[0].types);
|
||||||
|
info2.should.have.property("enabled",true);
|
||||||
|
|
||||||
|
var list3 = typeRegistry.getNodeList();
|
||||||
|
list3.should.be.an.Array.and.have.lengthOf(1);
|
||||||
|
list3[0].should.have.property("enabled",true);
|
||||||
|
|
||||||
|
var nodeConfig2 = typeRegistry.getNodeConfigs();
|
||||||
|
nodeConfig2.should.eql(nodeConfig);
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(function(e) {
|
||||||
|
done(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('fails to enable/disable non-existent nodes', function(done) {
|
it('fails to enable/disable non-existent nodes', function(done) {
|
||||||
typeRegistry.init(settings);
|
typeRegistry.init(settings);
|
||||||
typeRegistry.load("wontexist",true).then(function() {
|
typeRegistry.load("wontexist",true).then(function() {
|
||||||
var list = typeRegistry.getNodeList();
|
var list = typeRegistry.getNodeList();
|
||||||
list.should.be.an.Array.and.be.empty;
|
list.should.be.an.Array.and.be.empty;
|
||||||
|
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
(function() {
|
(function() {
|
||||||
typeRegistry.disableNode("123");
|
typeRegistry.disableNode("123");
|
||||||
}).should.throw();
|
}).should.throw();
|
||||||
|
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
(function() {
|
(function() {
|
||||||
typeRegistry.enableNode("123");
|
typeRegistry.enableNode("123");
|
||||||
}).should.throw();
|
}).should.throw();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user