Handle missing file/modules in Add node api

This commit is contained in:
Nick O'Leary 2014-08-18 21:59:19 +01:00
parent 4d6846047f
commit 7042d87444
2 changed files with 39 additions and 1 deletions

View File

@ -466,6 +466,11 @@ function addNode(options) {
}
} else if (options.module) {
var moduleFiles = scanTreeForNodesModules(options.module);
if (moduleFiles.length === 0) {
var err = new Error("Cannot find module '" + options.module + "'");
err.code = 'MODULE_NOT_FOUND';
return when.reject(err);
}
moduleFiles.forEach(function(moduleFile) {
nodes = nodes.concat(loadNodesFromModule(moduleFile.dir,moduleFile.package));
});

View File

@ -310,6 +310,22 @@ describe('NodeRegistry', function() {
});
});
it('fails to add non-existent filename', function(done) {
typeRegistry.init({});
typeRegistry.load("wontexist",true).then(function(){
var list = typeRegistry.getNodeList();
list.should.be.an.Array.and.be.empty;
typeRegistry.addNode({file: resourcesDir + "DoesNotExist/DoesNotExist.js"}).then(function(node) {
done(new Error("ENOENT not thrown"));
}).otherwise(function(e) {
e.code.should.eql("ENOENT");
done();
});
}).catch(function(e) {
done(e);
});
});
it('returns node info by type or id', function(done) {
typeRegistry.init({});
@ -501,7 +517,6 @@ describe('NodeRegistry', function() {
});
})();
typeRegistry.init({});
typeRegistry.load("wontexist",true).then(function(){
var list = typeRegistry.getNodeList();
@ -537,6 +552,24 @@ describe('NodeRegistry', function() {
});
});
it('fails to add non-existent module name', function(done) {
typeRegistry.init({});
typeRegistry.load("wontexist",true).then(function(){
var list = typeRegistry.getNodeList();
list.should.be.an.Array.and.be.empty;
typeRegistry.addNode({module: "DoesNotExistModule"}).then(function(node) {
done(new Error("ENOENT not thrown"));
}).otherwise(function(e) {
e.code.should.eql("MODULE_NOT_FOUND");
done();
});
}).catch(function(e) {
done(e);
});
});
it('allows nodes to be enabled and disabled', function(done) {
typeRegistry.init({});