mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Remove add/removeNode by filename api
Only support add/remove by module name
This commit is contained in:
@@ -147,33 +147,15 @@ describe("red/nodes/index", function() {
|
||||
return randomNodeInfo;
|
||||
}
|
||||
});
|
||||
sinon.stub(registry,"removeNode",function(id) {
|
||||
return randomNodeInfo;
|
||||
});
|
||||
sinon.stub(registry,"disableNode",function(id) {
|
||||
return randomNodeInfo;
|
||||
});
|
||||
});
|
||||
after(function() {
|
||||
registry.getNodeInfo.restore();
|
||||
registry.removeNode.restore();
|
||||
registry.disableNode.restore();
|
||||
});
|
||||
|
||||
it(': allows an unused node type to be removed',function(done) {
|
||||
index.init(settings, storage);
|
||||
index.registerType('test', TestNode);
|
||||
index.loadFlows().then(function() {
|
||||
var info = index.removeNode("5678");
|
||||
registry.removeNode.calledOnce.should.be.true;
|
||||
registry.removeNode.calledWith("5678").should.be.true;
|
||||
info.should.eql(randomNodeInfo);
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it(': allows an unused node type to be disabled',function(done) {
|
||||
index.init(settings, storage);
|
||||
index.registerType('test', TestNode);
|
||||
@@ -188,21 +170,6 @@ describe("red/nodes/index", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it(': prevents removing a node type that is in use',function(done) {
|
||||
index.init(settings, storage);
|
||||
index.registerType('test', TestNode);
|
||||
index.loadFlows().then(function() {
|
||||
/*jshint immed: false */
|
||||
(function() {
|
||||
index.removeNode("test");
|
||||
}).should.throw();
|
||||
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it(': prevents disabling a node type that is in use',function(done) {
|
||||
index.init(settings, storage);
|
||||
index.registerType('test', TestNode);
|
||||
@@ -218,20 +185,6 @@ describe("red/nodes/index", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it(': prevents removing a node type that is unknown',function(done) {
|
||||
index.init(settings, storage);
|
||||
index.registerType('test', TestNode);
|
||||
index.loadFlows().then(function() {
|
||||
/*jshint immed: false */
|
||||
(function() {
|
||||
index.removeNode("doesnotexist");
|
||||
}).should.throw();
|
||||
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
it(': prevents disabling a node type that is unknown',function(done) {
|
||||
index.init(settings, storage);
|
||||
index.registerType('test', TestNode);
|
||||
|
@@ -343,60 +343,6 @@ describe('red/nodes/registry', function() {
|
||||
|
||||
});
|
||||
|
||||
it('allows nodes to be added by filename', function(done) {
|
||||
var settings = {
|
||||
available: function() { return true; },
|
||||
set: function(s,v) {return when.resolve();},
|
||||
get: function(s) { return null;}
|
||||
}
|
||||
typeRegistry.init(settings);
|
||||
typeRegistry.load("wontexist",true).then(function(){
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.be.empty;
|
||||
|
||||
// TODO: Needs module and name params for loadNodeConfig
|
||||
typeRegistry.addNode(resourcesDir + "TestNode1/TestNode1.js").then(function(node) {
|
||||
list = typeRegistry.getNodeList();
|
||||
list[0].should.have.property("id","node-red/TestNode1");
|
||||
list[0].should.have.property("name","TestNode1");
|
||||
list[0].should.have.property("module","node-red");
|
||||
list[0].should.have.property("types",["test-node-1"]);
|
||||
list[0].should.have.property("enabled",true);
|
||||
list[0].should.not.have.property("err");
|
||||
|
||||
node.should.be.an.Array.and.have.lengthOf(1);
|
||||
node.should.eql(list);
|
||||
|
||||
done();
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails to add non-existent filename', function(done) {
|
||||
typeRegistry.init(settingsWithStorage);
|
||||
typeRegistry.load("wontexist",true).then(function(){
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.be.empty;
|
||||
typeRegistry.addNode(resourcesDir + "DoesNotExist/DoesNotExist.js").then(function(nodes) {
|
||||
nodes.should.be.an.Array.and.have.lengthOf(1);
|
||||
nodes[0].should.have.property("id");
|
||||
nodes[0].should.have.property("types",[]);
|
||||
nodes[0].should.have.property("err");
|
||||
done();
|
||||
}).otherwise(function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns node info by type or id', function(done) {
|
||||
typeRegistry.init(settings);
|
||||
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
||||
@@ -548,75 +494,6 @@ describe('red/nodes/registry', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects adding duplicate nodes', function(done) {
|
||||
typeRegistry.init(settingsWithStorage);
|
||||
typeRegistry.load(resourcesDir + "TestNode1",true).then(function(){
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.have.lengthOf(1);
|
||||
|
||||
typeRegistry.addNode({file:resourcesDir + "TestNode1" + path.sep + "TestNode1.js"}).then(function(node) {
|
||||
done(new Error("duplicate node loaded"));
|
||||
}).otherwise(function(e) {
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.have.lengthOf(1);
|
||||
done();
|
||||
});
|
||||
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('removes nodes from the registry', function(done) {
|
||||
typeRegistry.init(settingsWithStorage);
|
||||
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.have.lengthOf(1);
|
||||
list[0].should.have.property("id","node-red/TestNode1");
|
||||
list[0].should.have.property("name","TestNode1");
|
||||
list[0].should.have.property("module","node-red");
|
||||
list[0].should.have.property("types",["test-node-1"]);
|
||||
list[0].should.have.property("enabled",true);
|
||||
list[0].should.have.property("loaded",true);
|
||||
|
||||
typeRegistry.getNodeConfigs().length.should.be.greaterThan(0);
|
||||
|
||||
var info = typeRegistry.removeNode(list[0].id);
|
||||
|
||||
info.should.have.property("id",list[0].id);
|
||||
info.should.have.property("enabled",false);
|
||||
info.should.have.property("loaded",false);
|
||||
|
||||
typeRegistry.getNodeList().should.be.an.Array.and.be.empty;
|
||||
typeRegistry.getNodeConfigs().length.should.equal(0);
|
||||
|
||||
var nodeConstructor = typeRegistry.get("test-node-1");
|
||||
(typeof nodeConstructor).should.be.equal("undefined");
|
||||
|
||||
done();
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects removing unknown nodes from the registry', function(done) {
|
||||
typeRegistry.init(settings);
|
||||
typeRegistry.load("wontexist",true).then(function() {
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.be.empty;
|
||||
|
||||
|
||||
/*jshint immed: false */
|
||||
(function() {
|
||||
typeRegistry.removeNode("1234");
|
||||
}).should.throw();
|
||||
|
||||
done();
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('scans the node_modules path for node files', function(done) {
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
@@ -1073,10 +950,6 @@ describe('red/nodes/registry', function() {
|
||||
(function() {
|
||||
typeRegistry.removeModule("123");
|
||||
}).should.throw("Settings unavailable");
|
||||
/*jshint immed: false */
|
||||
(function() {
|
||||
typeRegistry.addNode("123");
|
||||
}).should.throw("Settings unavailable");
|
||||
|
||||
done();
|
||||
});
|
||||
|
Reference in New Issue
Block a user