mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Remove 'loaded' property from external node info object
and fix everything that doing this broke
This commit is contained in:
parent
2a8a885271
commit
b201828236
@ -29,7 +29,7 @@ var settings = require("../settings");
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
getAll: function(req,res) {
|
getAll: function(req,res) {
|
||||||
if (req.get("accept") == "application/json") {
|
if (req.get("accept") == "application/json") {
|
||||||
res.json(redNodes.getNodeList().map(function(n) { delete n.loaded; return n }));
|
res.json(redNodes.getNodeList());
|
||||||
} else {
|
} else {
|
||||||
res.send(redNodes.getNodeConfigs());
|
res.send(redNodes.getNodeConfigs());
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ module.exports = {
|
|||||||
var node = req.body;
|
var node = req.body;
|
||||||
var promise;
|
var promise;
|
||||||
if (node.module) {
|
if (node.module) {
|
||||||
var module = redNodes.getNodeModuleInfo(node.module);
|
var module = redNodes.getModuleInfo(node.module);
|
||||||
if (module) {
|
if (module) {
|
||||||
res.json(400,{message:"Module already loaded"});
|
res.json(400,{message:"Module already loaded"});
|
||||||
return;
|
return;
|
||||||
@ -72,7 +72,7 @@ module.exports = {
|
|||||||
var mod = req.params.mod;
|
var mod = req.params.mod;
|
||||||
try {
|
try {
|
||||||
var promise = null;
|
var promise = null;
|
||||||
var module = redNodes.getNodeModuleInfo(mod);
|
var module = redNodes.getModuleInfo(mod);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
res.send(404);
|
res.send(404);
|
||||||
return;
|
return;
|
||||||
@ -83,9 +83,11 @@ module.exports = {
|
|||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
res.send(204);
|
res.send(204);
|
||||||
}).otherwise(function(err) {
|
}).otherwise(function(err) {
|
||||||
res.json(400,{message:err.toString()});
|
console.log(err.stack);
|
||||||
|
res.json(400,{message:err.toString()});
|
||||||
});
|
});
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
console.log(err.stack);
|
||||||
res.json(400,{message:err.toString()});
|
res.json(400,{message:err.toString()});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -96,7 +98,7 @@ module.exports = {
|
|||||||
if (req.get("accept") === "application/json") {
|
if (req.get("accept") === "application/json") {
|
||||||
result = redNodes.getNodeInfo(id);
|
result = redNodes.getNodeInfo(id);
|
||||||
if (result) {
|
if (result) {
|
||||||
result.version = redNodes.getModuleVersion(req.params.mod);
|
delete result.loaded;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = redNodes.getNodeConfig(id);
|
result = redNodes.getNodeConfig(id);
|
||||||
@ -112,7 +114,7 @@ module.exports = {
|
|||||||
var module = req.params.mod;
|
var module = req.params.mod;
|
||||||
var result = redNodes.getModuleInfo(module);
|
var result = redNodes.getModuleInfo(module);
|
||||||
if (result) {
|
if (result) {
|
||||||
res.send(result);
|
res.json(result);
|
||||||
} else {
|
} else {
|
||||||
res.send(404);
|
res.send(404);
|
||||||
}
|
}
|
||||||
@ -135,6 +137,7 @@ module.exports = {
|
|||||||
if (!node) {
|
if (!node) {
|
||||||
res.send(404);
|
res.send(404);
|
||||||
} else {
|
} else {
|
||||||
|
delete node.loaded;
|
||||||
res.json(putNode(node, body.enabled));
|
res.json(putNode(node, body.enabled));
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
@ -85,12 +85,12 @@ function removeNode(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeModule(module) {
|
function removeModule(module) {
|
||||||
var info = registry.getNodeModuleInfo(module);
|
var info = registry.getModuleInfo(module);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw new Error("Unrecognised module: "+module);
|
throw new Error("Unrecognised module: "+module);
|
||||||
} else {
|
} else {
|
||||||
for (var i=0;i<info.length;i++) {
|
for (var i=0;i<info.nodes.length;i++) {
|
||||||
checkTypeInUse(module+"/"+info[i]);
|
checkTypeInUse(module+"/"+info.nodes[i].name);
|
||||||
}
|
}
|
||||||
return registry.removeModule(module);
|
return registry.removeModule(module);
|
||||||
}
|
}
|
||||||
@ -124,11 +124,8 @@ module.exports = {
|
|||||||
getNodeInfo: registry.getNodeInfo,
|
getNodeInfo: registry.getNodeInfo,
|
||||||
getNodeList: registry.getNodeList,
|
getNodeList: registry.getNodeList,
|
||||||
|
|
||||||
getNodeModuleInfo: registry.getNodeModuleInfo,
|
|
||||||
|
|
||||||
getModuleInfo: registry.getModuleInfo,
|
getModuleInfo: registry.getModuleInfo,
|
||||||
getModuleList: registry.getModuleList,
|
getModuleList: registry.getModuleList,
|
||||||
getModuleVersion: registry.getModuleVersion,
|
|
||||||
|
|
||||||
getNodeConfigs: registry.getNodeConfigs,
|
getNodeConfigs: registry.getNodeConfigs,
|
||||||
getNodeConfig: registry.getNodeConfig,
|
getNodeConfig: registry.getNodeConfig,
|
||||||
|
@ -34,9 +34,6 @@ function filterNodeInfo(n) {
|
|||||||
types: n.types,
|
types: n.types,
|
||||||
enabled: n.enabled
|
enabled: n.enabled
|
||||||
};
|
};
|
||||||
if (n.hasOwnProperty("loaded")) {
|
|
||||||
r.loaded = n.loaded;
|
|
||||||
}
|
|
||||||
if (n.hasOwnProperty("module")) {
|
if (n.hasOwnProperty("module")) {
|
||||||
r.module = n.module;
|
r.module = n.module;
|
||||||
}
|
}
|
||||||
@ -82,7 +79,6 @@ var registry = (function() {
|
|||||||
if (nodes.hasOwnProperty(node)) {
|
if (nodes.hasOwnProperty(node)) {
|
||||||
var config = nodes[node];
|
var config = nodes[node];
|
||||||
var n = filterNodeInfo(config);
|
var n = filterNodeInfo(config);
|
||||||
delete n.loaded;
|
|
||||||
delete n.err;
|
delete n.err;
|
||||||
delete n.file;
|
delete n.file;
|
||||||
delete n.id;
|
delete n.id;
|
||||||
@ -230,13 +226,18 @@ var registry = (function() {
|
|||||||
if (module) {
|
if (module) {
|
||||||
var config = module.nodes[getNode(id)];
|
var config = module.nodes[getNode(id)];
|
||||||
if (config) {
|
if (config) {
|
||||||
return filterNodeInfo(config);
|
var info = filterNodeInfo(config);
|
||||||
|
if (config.hasOwnProperty("loaded")) {
|
||||||
|
info.loaded = config.loaded;
|
||||||
|
}
|
||||||
|
info.version = module.version;
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
getNodeList: function() {
|
getNodeList: function(filter) {
|
||||||
var list = [];
|
var list = [];
|
||||||
for (var module in moduleConfigs) {
|
for (var module in moduleConfigs) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
@ -245,7 +246,11 @@ var registry = (function() {
|
|||||||
for (var node in nodes) {
|
for (var node in nodes) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (nodes.hasOwnProperty(node)) {
|
if (nodes.hasOwnProperty(node)) {
|
||||||
list.push(filterNodeInfo(nodes[node]));
|
var nodeInfo = filterNodeInfo(nodes[node]);
|
||||||
|
nodeInfo.version = moduleConfigs[module].version;
|
||||||
|
if (!filter || filter(nodes[node])) {
|
||||||
|
list.push(nodeInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,16 +262,7 @@ var registry = (function() {
|
|||||||
for (var module in moduleNodes) {
|
for (var module in moduleNodes) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (moduleNodes.hasOwnProperty(module)) {
|
if (moduleNodes.hasOwnProperty(module)) {
|
||||||
var nodes = moduleNodes[module];
|
list.push(registry.getModuleInfo(module));
|
||||||
var m = {
|
|
||||||
name: module,
|
|
||||||
version: moduleConfigs[module].version,
|
|
||||||
nodes: []
|
|
||||||
};
|
|
||||||
for (var i = 0; i < nodes.length; ++i) {
|
|
||||||
m.nodes.push(filterNodeInfo(moduleConfigs[module].nodes[nodes[i]]));
|
|
||||||
}
|
|
||||||
list.push(m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@ -280,16 +276,15 @@ var registry = (function() {
|
|||||||
nodes: []
|
nodes: []
|
||||||
};
|
};
|
||||||
for (var i = 0; i < nodes.length; ++i) {
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
m.nodes.push(filterNodeInfo(moduleConfigs[module].nodes[nodes[i]]));
|
var nodeInfo = filterNodeInfo(moduleConfigs[module].nodes[nodes[i]]);
|
||||||
|
nodeInfo.version = m.version;
|
||||||
|
m.nodes.push(nodeInfo);
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getModuleVersion: function(module) {
|
|
||||||
return moduleConfigs[module].version;
|
|
||||||
},
|
|
||||||
registerNodeConstructor: function(type,constructor) {
|
registerNodeConstructor: function(type,constructor) {
|
||||||
if (nodeConstructors[type]) {
|
if (nodeConstructors[type]) {
|
||||||
throw new Error(type+" already registered");
|
throw new Error(type+" already registered");
|
||||||
@ -373,10 +368,6 @@ var registry = (function() {
|
|||||||
return nodeTypeToId[type];
|
return nodeTypeToId[type];
|
||||||
},
|
},
|
||||||
|
|
||||||
getNodeModuleInfo: function(module) {
|
|
||||||
return moduleNodes[module];
|
|
||||||
},
|
|
||||||
|
|
||||||
enableNodeSet: function(typeOrId) {
|
enableNodeSet: function(typeOrId) {
|
||||||
if (!settings.available()) {
|
if (!settings.available()) {
|
||||||
throw new Error("Settings unavailable");
|
throw new Error("Settings unavailable");
|
||||||
@ -526,7 +517,7 @@ function scanDirForNodesModules(dir,moduleName) {
|
|||||||
var files = fs.readdirSync(dir);
|
var files = fs.readdirSync(dir);
|
||||||
for (var i=0;i<files.length;i++) {
|
for (var i=0;i<files.length;i++) {
|
||||||
var fn = files[i];
|
var fn = files[i];
|
||||||
if (!registry.getNodeModuleInfo(fn)) {
|
if (!registry.getModuleInfo(fn)) {
|
||||||
if (!moduleName || fn == moduleName) {
|
if (!moduleName || fn == moduleName) {
|
||||||
var pkgfn = path.join(dir,fn,"package.json");
|
var pkgfn = path.join(dir,fn,"package.json");
|
||||||
try {
|
try {
|
||||||
@ -626,9 +617,7 @@ function loadNodesFromModule(moduleDir,pkg) {
|
|||||||
function loadNodeConfig(file,module,name,version) {
|
function loadNodeConfig(file,module,name,version) {
|
||||||
var id = module + "/" + name;
|
var id = module + "/" + name;
|
||||||
var info = registry.getNodeInfo(id);
|
var info = registry.getNodeInfo(id);
|
||||||
|
|
||||||
var isEnabled = true;
|
var isEnabled = true;
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
if (info.hasOwnProperty("loaded")) {
|
if (info.hasOwnProperty("loaded")) {
|
||||||
throw new Error(file+" already loaded");
|
throw new Error(file+" already loaded");
|
||||||
@ -819,7 +808,7 @@ function addModule(module) {
|
|||||||
throw new Error("Settings unavailable");
|
throw new Error("Settings unavailable");
|
||||||
}
|
}
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
if (registry.getNodeModuleInfo(module)) {
|
if (registry.getModuleInfo(module)) {
|
||||||
return when.reject(new Error("Module already loaded"));
|
return when.reject(new Error("Module already loaded"));
|
||||||
}
|
}
|
||||||
var moduleFiles = scanTreeForNodesModules(module);
|
var moduleFiles = scanTreeForNodesModules(module);
|
||||||
@ -831,7 +820,9 @@ function addModule(module) {
|
|||||||
moduleFiles.forEach(function(moduleFile) {
|
moduleFiles.forEach(function(moduleFile) {
|
||||||
nodes = nodes.concat(loadNodesFromModule(moduleFile.dir,moduleFile.package));
|
nodes = nodes.concat(loadNodesFromModule(moduleFile.dir,moduleFile.package));
|
||||||
});
|
});
|
||||||
return loadNodeList(nodes);
|
return loadNodeList(nodes).then(function() {
|
||||||
|
return registry.getModuleInfo(module);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -844,11 +835,8 @@ module.exports = {
|
|||||||
getNodeInfo: registry.getNodeInfo,
|
getNodeInfo: registry.getNodeInfo,
|
||||||
getNodeList: registry.getNodeList,
|
getNodeList: registry.getNodeList,
|
||||||
|
|
||||||
getNodeModuleInfo: registry.getNodeModuleInfo,
|
|
||||||
|
|
||||||
getModuleInfo: registry.getModuleInfo,
|
getModuleInfo: registry.getModuleInfo,
|
||||||
getModuleList: registry.getModuleList,
|
getModuleList: registry.getModuleList,
|
||||||
getModuleVersion: registry.getModuleVersion,
|
|
||||||
|
|
||||||
getNodeConfigs: registry.getAllNodeConfigs,
|
getNodeConfigs: registry.getAllNodeConfigs,
|
||||||
getNodeConfig: registry.getNodeConfig,
|
getNodeConfig: registry.getNodeConfig,
|
||||||
|
@ -65,9 +65,8 @@ function start() {
|
|||||||
redNodes.init(settings,storage,app);
|
redNodes.init(settings,storage,app);
|
||||||
redNodes.load().then(function() {
|
redNodes.load().then(function() {
|
||||||
var i;
|
var i;
|
||||||
var nodes = redNodes.getNodeList();
|
var nodeErrors = redNodes.getNodeList(function(n) { return n.err!=null;});
|
||||||
var nodeErrors = nodes.filter(function(n) { return n.err!=null;});
|
var nodeMissing = redNodes.getNodeList(function(n) { return n.module && n.enabled && !n.loaded && !n.err;});
|
||||||
var nodeMissing = nodes.filter(function(n) { return n.module && n.enabled && !n.loaded && !n.err;});
|
|
||||||
if (nodeErrors.length > 0) {
|
if (nodeErrors.length > 0) {
|
||||||
log.warn("------------------------------------------");
|
log.warn("------------------------------------------");
|
||||||
if (settings.verbose) {
|
if (settings.verbose) {
|
||||||
@ -114,15 +113,15 @@ function start() {
|
|||||||
|
|
||||||
|
|
||||||
function reportAddedModules(info) {
|
function reportAddedModules(info) {
|
||||||
comms.publish("node/added",info,false);
|
comms.publish("node/added",info.nodes,false);
|
||||||
if (info.length > 0) {
|
if (info.nodes.length > 0) {
|
||||||
log.info("Added node types:");
|
log.info("Added node types:");
|
||||||
for (var i=0;i<info.length;i++) {
|
for (var i=0;i<info.nodes.length;i++) {
|
||||||
for (var j=0;j<info[i].types.length;j++) {
|
for (var j=0;j<info.nodes[i].types.length;j++) {
|
||||||
log.info(" - "+
|
log.info(" - "+
|
||||||
(info[i].module?info[i].module+":":"")+
|
(info.nodes[i].module?info.nodes[i].module+":":"")+
|
||||||
info[i].types[j]+
|
info.nodes[i].types[j]+
|
||||||
(info[i].err?" : "+info[i].err:"")
|
(info.nodes[i].err?" : "+info.nodes[i].err:"")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,16 +116,12 @@ describe("nodes api", function() {
|
|||||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
||||||
return {"node-red/123":{id:"node-red/123"}}[id];
|
return {"node-red/123":{id:"node-red/123"}}[id];
|
||||||
});
|
});
|
||||||
var getModuleVersion = sinon.stub(redNodes,'getModuleVersion', function(module) {
|
|
||||||
return {"node-red": {version: "0.0.1"}}[module];
|
|
||||||
});
|
|
||||||
request(app)
|
request(app)
|
||||||
.get('/nodes/node-red/123')
|
.get('/nodes/node-red/123')
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
getNodeInfo.restore();
|
getNodeInfo.restore();
|
||||||
getModuleVersion.restore();
|
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@ -210,16 +206,11 @@ describe("nodes api", function() {
|
|||||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo');
|
||||||
return null;
|
getModuleInfo.onCall(0).returns(null);
|
||||||
});
|
getModuleInfo.onCall(1).returns({
|
||||||
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo',function(module) {
|
name:"foo",
|
||||||
if (module === "foo") {
|
nodes:[{id:"123"}]
|
||||||
return {
|
|
||||||
name:"foo",
|
|
||||||
nodes:[{id:"123"}]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var installModule = sinon.stub(server,'installModule', function() {
|
var installModule = sinon.stub(server,'installModule', function() {
|
||||||
return when.resolve({id:"123"});
|
return when.resolve({id:"123"});
|
||||||
@ -231,7 +222,6 @@ describe("nodes api", function() {
|
|||||||
.expect(200)
|
.expect(200)
|
||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
settingsAvailable.restore();
|
settingsAvailable.restore();
|
||||||
getNodeModuleInfo.restore();
|
|
||||||
getModuleInfo.restore();
|
getModuleInfo.restore();
|
||||||
installModule.restore();
|
installModule.restore();
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -248,8 +238,8 @@ describe("nodes api", function() {
|
|||||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo',function(id) {
|
||||||
return {id:"123"};
|
return {nodes:{id:"123"}};
|
||||||
});
|
});
|
||||||
var installModule = sinon.stub(server,'installModule', function() {
|
var installModule = sinon.stub(server,'installModule', function() {
|
||||||
return when.resolve({id:"123"});
|
return when.resolve({id:"123"});
|
||||||
@ -261,7 +251,7 @@ describe("nodes api", function() {
|
|||||||
.expect(400)
|
.expect(400)
|
||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
settingsAvailable.restore();
|
settingsAvailable.restore();
|
||||||
getNodeModuleInfo.restore();
|
getModuleInfo.restore();
|
||||||
installModule.restore();
|
installModule.restore();
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -274,7 +264,7 @@ describe("nodes api", function() {
|
|||||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo',function(id) {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
var installModule = sinon.stub(server,'installModule', function() {
|
var installModule = sinon.stub(server,'installModule', function() {
|
||||||
@ -287,7 +277,7 @@ describe("nodes api", function() {
|
|||||||
.expect(400)
|
.expect(400)
|
||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
settingsAvailable.restore();
|
settingsAvailable.restore();
|
||||||
getNodeModuleInfo.restore();
|
getModuleInfo.restore();
|
||||||
installModule.restore();
|
installModule.restore();
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -300,7 +290,7 @@ describe("nodes api", function() {
|
|||||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo',function(id) {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
var installModule = sinon.stub(server,'installModule', function() {
|
var installModule = sinon.stub(server,'installModule', function() {
|
||||||
@ -315,7 +305,7 @@ describe("nodes api", function() {
|
|||||||
.expect(404)
|
.expect(404)
|
||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
settingsAvailable.restore();
|
settingsAvailable.restore();
|
||||||
getNodeModuleInfo.restore();
|
getModuleInfo.restore();
|
||||||
installModule.restore();
|
installModule.restore();
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -350,8 +340,8 @@ describe("nodes api", function() {
|
|||||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo',function(id) {
|
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo',function(id) {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo',function(id) {
|
||||||
return {id:"123"};
|
return {nodes:[{id:"123"}]};
|
||||||
});
|
});
|
||||||
var uninstallModule = sinon.stub(server,'uninstallModule', function() {
|
var uninstallModule = sinon.stub(server,'uninstallModule', function() {
|
||||||
return when.resolve({id:"123"});
|
return when.resolve({id:"123"});
|
||||||
@ -363,7 +353,7 @@ describe("nodes api", function() {
|
|||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
settingsAvailable.restore();
|
settingsAvailable.restore();
|
||||||
getNodeInfo.restore();
|
getNodeInfo.restore();
|
||||||
getNodeModuleInfo.restore();
|
getModuleInfo.restore();
|
||||||
uninstallModule.restore();
|
uninstallModule.restore();
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -379,7 +369,7 @@ describe("nodes api", function() {
|
|||||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo',function(id) {
|
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo',function(id) {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo',function(id) {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -389,7 +379,7 @@ describe("nodes api", function() {
|
|||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
settingsAvailable.restore();
|
settingsAvailable.restore();
|
||||||
getNodeInfo.restore();
|
getNodeInfo.restore();
|
||||||
getNodeModuleInfo.restore();
|
getModuleInfo.restore();
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@ -404,8 +394,8 @@ describe("nodes api", function() {
|
|||||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo',function(id) {
|
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo',function(id) {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
var getModuleInfo = sinon.stub(redNodes,'getModuleInfo',function(id) {
|
||||||
return {id:"123"};
|
return {nodes:[{id:"123"}]};
|
||||||
});
|
});
|
||||||
var uninstallModule = sinon.stub(server,'uninstallModule', function() {
|
var uninstallModule = sinon.stub(server,'uninstallModule', function() {
|
||||||
return when.reject(new Error("test error"));
|
return when.reject(new Error("test error"));
|
||||||
@ -417,7 +407,7 @@ describe("nodes api", function() {
|
|||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
settingsAvailable.restore();
|
settingsAvailable.restore();
|
||||||
getNodeInfo.restore();
|
getNodeInfo.restore();
|
||||||
getNodeModuleInfo.restore();
|
getModuleInfo.restore();
|
||||||
uninstallModule.restore();
|
uninstallModule.restore();
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -219,13 +219,13 @@ describe("red/nodes/index", function() {
|
|||||||
return randomNodeInfo;
|
return randomNodeInfo;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sinon.stub(registry,"getNodeModuleInfo",function(module) {
|
sinon.stub(registry,"getModuleInfo",function(module) {
|
||||||
if (module == "node-red") {
|
if (module == "node-red") {
|
||||||
return ["foo"];
|
return {nodes:[{name:"foo"}]};
|
||||||
} else if (module == "doesnotexist") {
|
} else if (module == "doesnotexist") {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return randomModuleInfo.nodes;
|
return randomModuleInfo;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sinon.stub(registry,"removeModule",function(id) {
|
sinon.stub(registry,"removeModule",function(id) {
|
||||||
@ -234,7 +234,7 @@ describe("red/nodes/index", function() {
|
|||||||
});
|
});
|
||||||
after(function() {
|
after(function() {
|
||||||
registry.getNodeInfo.restore();
|
registry.getNodeInfo.restore();
|
||||||
registry.getNodeModuleInfo.restore();
|
registry.getModuleInfo.restore();
|
||||||
registry.removeModule.restore();
|
registry.removeModule.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,16 +40,52 @@ describe('red/nodes/registry', function() {
|
|||||||
}
|
}
|
||||||
var settings = stubSettings({},false,null);
|
var settings = stubSettings({},false,null);
|
||||||
var settingsWithStorage = stubSettings({},true,null);
|
var settingsWithStorage = stubSettings({},true,null);
|
||||||
var settingsWithStorageAndInitialConfig = stubSettings({},true,{"node-red":{module:"testModule",name:"testName",version:"testVersion"}});
|
var settingsWithStorageAndInitialConfig = stubSettings({},true,{"node-red":{module:"testModule",name:"testName",version:"testVersion",nodes:{"node":{id:"node-red/testName",name:"test",types:["a","b"],enabled:true}}}});
|
||||||
|
|
||||||
it('loads initial config', function(done) {
|
it('loads initial config', function(done) {
|
||||||
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
||||||
var version = typeRegistry.getModuleVersion("node-red");
|
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||||
should.exist(version);
|
|
||||||
version.should.eql("testVersion");
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('migrates legacy format', function(done) {
|
||||||
|
var settings = {
|
||||||
|
available: function() { return true; },
|
||||||
|
set: sinon.stub().returns(when.resolve()),
|
||||||
|
get: function() { return {
|
||||||
|
"123": {
|
||||||
|
"name": "72-sentiment.js",
|
||||||
|
"types": [
|
||||||
|
"sentiment"
|
||||||
|
],
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"456": {
|
||||||
|
"name": "20-inject.js",
|
||||||
|
"types": [
|
||||||
|
"inject"
|
||||||
|
],
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"789": {
|
||||||
|
"name": "testModule:a-module.js",
|
||||||
|
"types": [
|
||||||
|
"example"
|
||||||
|
],
|
||||||
|
"enabled":true,
|
||||||
|
"module":"testModule"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
};
|
||||||
|
var expected = JSON.parse('{"node-red":{"name":"node-red","nodes":{"sentiment":{"name":"sentiment","types":["sentiment"],"enabled":true,"module":"node-red"},"inject":{"name":"inject","types":["inject"],"enabled":true,"module":"node-red"}}},"testModule":{"name":"testModule","nodes":{"a-module.js":{"name":"a-module.js","types":["example"],"enabled":true,"module":"testModule"}}}}');
|
||||||
|
typeRegistry.init(settings);
|
||||||
|
settings.set.calledOnce.should.be.true;
|
||||||
|
settings.set.args[0][1].should.eql(expected);
|
||||||
|
done();
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
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() {
|
||||||
@ -356,14 +392,18 @@ describe('red/nodes/registry', function() {
|
|||||||
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 id = list[0].id;
|
var id = "node-red/TestNode1";
|
||||||
var type = list[0].types[0];
|
var type = "test-node-1";
|
||||||
|
|
||||||
|
|
||||||
var info = typeRegistry.getNodeInfo(id);
|
var info = typeRegistry.getNodeInfo(id);
|
||||||
|
info.should.have.property("loaded");
|
||||||
|
delete info.loaded;
|
||||||
list[0].should.eql(info);
|
list[0].should.eql(info);
|
||||||
|
|
||||||
var info2 = typeRegistry.getNodeInfo(type);
|
var info2 = typeRegistry.getNodeInfo(type);
|
||||||
|
info2.should.have.property("loaded");
|
||||||
|
delete info2.loaded;
|
||||||
list[0].should.eql(info2);
|
list[0].should.eql(info2);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
@ -472,13 +512,10 @@ describe('red/nodes/registry', function() {
|
|||||||
typeRegistry.init(settingsWithStorage);
|
typeRegistry.init(settingsWithStorage);
|
||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
|
|
||||||
typeRegistry.addModule("TestNodeModule").then(function(nodes) {
|
typeRegistry.addModule("TestNodeModule").then(function(modInfo) {
|
||||||
var list = typeRegistry.getModuleList();
|
var info = typeRegistry.getModuleInfo("TestNodeModule");
|
||||||
|
|
||||||
var module = typeRegistry.getModuleInfo(list[0].name);
|
|
||||||
module.should.have.property("name", list[0].name);
|
|
||||||
module.should.have.property("nodes", nodes);
|
|
||||||
|
|
||||||
|
modInfo.should.eql(info);
|
||||||
should.not.exist(typeRegistry.getModuleInfo("does-not-exist"));
|
should.not.exist(typeRegistry.getModuleInfo("does-not-exist"));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
@ -597,7 +634,7 @@ describe('red/nodes/registry', 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(modInfo) {
|
||||||
list = typeRegistry.getNodeList();
|
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","TestNodeModule/TestNodeMod1");
|
list[0].should.have.property("id","TestNodeModule/TestNodeMod1");
|
||||||
@ -614,8 +651,6 @@ describe('red/nodes/registry', function() {
|
|||||||
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);
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
@ -671,9 +706,6 @@ describe('red/nodes/registry', function() {
|
|||||||
modules[0].should.have.property("name","TestNodeModule");
|
modules[0].should.have.property("name","TestNodeModule");
|
||||||
modules[0].should.have.property("version","0.0.1");
|
modules[0].should.have.property("version","0.0.1");
|
||||||
|
|
||||||
var version = typeRegistry.getModuleVersion("TestNodeModule");
|
|
||||||
version.should.eql("0.0.1");
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
|
@ -105,11 +105,11 @@ describe("red/server", function() {
|
|||||||
commsStart.restore();
|
commsStart.restore();
|
||||||
});
|
});
|
||||||
it("reports errored/missing modules",function(done) {
|
it("reports errored/missing modules",function(done) {
|
||||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function() {
|
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
|
||||||
return [
|
return [
|
||||||
{ err:"errored",name:"errName" }, // error
|
{ err:"errored",name:"errName" }, // error
|
||||||
{ module:"module",enabled:true,loaded:false,types:["typeA","typeB"]} // missing
|
{ module:"module",enabled:true,loaded:false,types:["typeA","typeB"]} // missing
|
||||||
];
|
].filter(cb);
|
||||||
});
|
});
|
||||||
server.init({},{testSettings: true, httpAdminRoot:"/", load:function() { return when.resolve();}});
|
server.init({},{testSettings: true, httpAdminRoot:"/", load:function() { return when.resolve();}});
|
||||||
server.start().then(function() {
|
server.start().then(function() {
|
||||||
@ -132,13 +132,13 @@ describe("red/server", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("initiates load of missing modules",function(done) {
|
it("initiates load of missing modules",function(done) {
|
||||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function() {
|
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
|
||||||
return [
|
return [
|
||||||
{ err:"errored",name:"errName" }, // error
|
{ err:"errored",name:"errName" }, // error
|
||||||
{ err:"errored",name:"errName" }, // error
|
{ err:"errored",name:"errName" }, // error
|
||||||
{ module:"module",enabled:true,loaded:false,types:["typeA","typeB"]}, // missing
|
{ module:"module",enabled:true,loaded:false,types:["typeA","typeB"]}, // missing
|
||||||
{ module:"node-red",enabled:true,loaded:false,types:["typeC","typeD"]} // missing
|
{ module:"node-red",enabled:true,loaded:false,types:["typeC","typeD"]} // missing
|
||||||
];
|
].filter(cb);
|
||||||
});
|
});
|
||||||
var serverInstallModule = sinon.stub(server,"installModule",function(name) { return when.resolve();});
|
var serverInstallModule = sinon.stub(server,"installModule",function(name) { return when.resolve();});
|
||||||
server.init({},{testSettings: true, autoInstallModules:true, httpAdminRoot:"/", load:function() { return when.resolve();}});
|
server.init({},{testSettings: true, autoInstallModules:true, httpAdminRoot:"/", load:function() { return when.resolve();}});
|
||||||
@ -161,10 +161,10 @@ describe("red/server", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("reports errored modules when verbose is enabled",function(done) {
|
it("reports errored modules when verbose is enabled",function(done) {
|
||||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function() {
|
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
|
||||||
return [
|
return [
|
||||||
{ err:"errored",name:"errName" } // error
|
{ err:"errored",name:"errName" } // error
|
||||||
];
|
].filter(cb);
|
||||||
});
|
});
|
||||||
server.init({},{testSettings: true, verbose:true, httpAdminRoot:"/", load:function() { return when.resolve();}});
|
server.init({},{testSettings: true, verbose:true, httpAdminRoot:"/", load:function() { return when.resolve();}});
|
||||||
server.start().then(function() {
|
server.start().then(function() {
|
||||||
@ -240,17 +240,17 @@ describe("red/server", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports added modules", function() {
|
it("reports added modules", function() {
|
||||||
var nodes = [
|
var nodes = {nodes:[
|
||||||
{types:["a"]},
|
{types:["a"]},
|
||||||
{module:"foo",types:["b"]},
|
{module:"foo",types:["b"]},
|
||||||
{types:["c"],err:"error"}
|
{types:["c"],err:"error"}
|
||||||
];
|
]};
|
||||||
var result = server.reportAddedModules(nodes);
|
var result = server.reportAddedModules(nodes);
|
||||||
|
|
||||||
result.should.equal(nodes);
|
result.should.equal(nodes);
|
||||||
commsMessages.should.have.length(1);
|
commsMessages.should.have.length(1);
|
||||||
commsMessages[0].topic.should.equal("node/added");
|
commsMessages[0].topic.should.equal("node/added");
|
||||||
commsMessages[0].msg.should.eql(nodes);
|
commsMessages[0].msg.should.eql(nodes.nodes);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports removed modules", function() {
|
it("reports removed modules", function() {
|
||||||
@ -305,7 +305,7 @@ describe("red/server", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("succeeds when module is found", function(done) {
|
it("succeeds when module is found", function(done) {
|
||||||
var nodeInfo = {module:"foo",types:["a"]};
|
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
||||||
var exec = sinon.stub(child_process,"exec",function(cmd,opt,cb) {
|
var exec = sinon.stub(child_process,"exec",function(cmd,opt,cb) {
|
||||||
cb(null,"","");
|
cb(null,"","");
|
||||||
});
|
});
|
||||||
@ -317,7 +317,7 @@ describe("red/server", function() {
|
|||||||
info.should.eql(nodeInfo);
|
info.should.eql(nodeInfo);
|
||||||
commsMessages.should.have.length(1);
|
commsMessages.should.have.length(1);
|
||||||
commsMessages[0].topic.should.equal("node/added");
|
commsMessages[0].topic.should.equal("node/added");
|
||||||
commsMessages[0].msg.should.eql(nodeInfo);
|
commsMessages[0].msg.should.eql(nodeInfo.nodes);
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).otherwise(function(err) {
|
||||||
done(err);
|
done(err);
|
||||||
|
Loading…
Reference in New Issue
Block a user