mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle missing file/modules in Add node api
This commit is contained in:
parent
4d6846047f
commit
7042d87444
@ -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));
|
||||
});
|
||||
|
@ -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({});
|
||||
|
Loading…
Reference in New Issue
Block a user