diff --git a/red/runtime/nodes/registry/loader.js b/red/runtime/nodes/registry/loader.js
index f88463609..10c37c294 100644
--- a/red/runtime/nodes/registry/loader.js
+++ b/red/runtime/nodes/registry/loader.js
@@ -62,6 +62,17 @@ function copyObjectProperties(src,dst,copyList,blockList) {
}
}
}
+function requireModule(name) {
+ var moduleInfo = registry.getModuleInfo(name);
+ if (moduleInfo && moduleInfo.path) {
+ var relPath = path.relative(__dirname, moduleInfo.path);
+ return require(relPath);
+ } else {
+ var err = new Error(`Cannot find module '${name}'`);
+ err.code = "MODULE_NOT_FOUND";
+ throw err;
+ }
+}
function createNodeApi(node) {
var red = {
@@ -71,6 +82,7 @@ function createNodeApi(node) {
events: runtime.events,
util: runtime.util,
version: runtime.version,
+ require: requireModule
}
copyObjectProperties(runtime.nodes,red.nodes,["createNode","getNode","eachNode","addCredentials","getCredentials","deleteCredentials" ]);
red.nodes.registerType = function(type,constructor,opts) {
@@ -112,6 +124,7 @@ function createNodeApi(node) {
function loadNodeFiles(nodeFiles) {
var promises = [];
+ var nodes = [];
for (var module in nodeFiles) {
/* istanbul ignore else */
if (nodeFiles.hasOwnProperty(module)) {
@@ -119,6 +132,7 @@ function loadNodeFiles(nodeFiles) {
!semver.satisfies(runtime.version().replace(/(\-[1-9A-Za-z-][0-9A-Za-z-\.]*)?(\+[0-9A-Za-z-\.]+)?$/,""), nodeFiles[module].redVersion)) {
//TODO: log it
runtime.log.warn("["+module+"] "+runtime.log._("server.node-version-mismatch",{version:nodeFiles[module].redVersion}));
+ nodeFiles[module].err = "version_mismatch";
continue;
}
if (module == "node-red" || !registry.getModuleInfo(module)) {
@@ -148,7 +162,14 @@ function loadNodeFiles(nodeFiles) {
}
try {
- promises.push(loadNodeConfig(nodeFiles[module].nodes[node]))
+ promises.push(loadNodeConfig(nodeFiles[module].nodes[node]).then((function() {
+ var m = module;
+ var n = node;
+ return function(nodeSet) {
+ nodeFiles[m].nodes[n] = nodeSet;
+ nodes.push(nodeSet);
+ }
+ })()));
} catch(err) {
//
}
@@ -158,16 +179,19 @@ function loadNodeFiles(nodeFiles) {
}
}
return when.settle(promises).then(function(results) {
- var nodes = results.map(function(r) {
- registry.addNodeSet(r.value.id,r.value,r.value.version);
- return r.value;
- });
+ for (var module in nodeFiles) {
+ if (nodeFiles.hasOwnProperty(module)) {
+ if (!nodeFiles[module].err) {
+ registry.addModule(nodeFiles[module]);
+ }
+ }
+ }
return loadNodeSetList(nodes);
});
}
function loadNodeConfig(fileInfo) {
- return when.promise(function(resolve) {
+ return new Promise(function(resolve) {
var file = fileInfo.file;
var module = fileInfo.module;
var name = fileInfo.name;
@@ -292,7 +316,7 @@ function loadNodeSet(node) {
var nodeDir = path.dirname(node.file);
var nodeFn = path.basename(node.file);
if (!node.enabled) {
- return when.resolve(node);
+ return Promise.resolve(node);
} else {
}
try {
@@ -316,7 +340,7 @@ function loadNodeSet(node) {
if (loadPromise == null) {
node.enabled = true;
node.loaded = true;
- loadPromise = when.resolve(node);
+ loadPromise = Promise.resolve(node);
}
return loadPromise;
} catch(err) {
@@ -333,7 +357,7 @@ function loadNodeSet(node) {
}
}
}
- return when.resolve(node);
+ return Promise.resolve(node);
}
}
@@ -365,19 +389,19 @@ function addModule(module) {
// TODO: nls
var e = new Error("module_already_loaded");
e.code = "module_already_loaded";
- return when.reject(e);
+ return Promise.reject(e);
}
try {
var moduleFiles = localfilesystem.getModuleFiles(module);
return loadNodeFiles(moduleFiles);
} catch(err) {
- return when.reject(err);
+ return Promise.reject(err);
}
}
function loadNodeHelp(node,lang) {
var base = path.basename(node.template);
- var localePath = undefined;
+ var localePath;
if (node.module === 'node-red') {
var cat_dir = path.dirname(node.template);
var cat = path.basename(cat_dir);
diff --git a/red/runtime/nodes/registry/localfilesystem.js b/red/runtime/nodes/registry/localfilesystem.js
index c2f0f9359..b8a516597 100644
--- a/red/runtime/nodes/registry/localfilesystem.js
+++ b/red/runtime/nodes/registry/localfilesystem.js
@@ -14,7 +14,6 @@
* limitations under the License.
**/
-var when = require("when");
var fs = require("fs");
var path = require("path");
@@ -85,6 +84,7 @@ function getLocalNodeFiles(dir) {
var result = [];
var files = [];
+ var icons = [];
try {
files = fs.readdirSync(dir);
} catch(err) {
@@ -103,14 +103,16 @@ function getLocalNodeFiles(dir) {
} else if (stats.isDirectory()) {
// Ignore /.dirs/, /lib/ /node_modules/
if (!/^(\..*|lib|icons|node_modules|test|locales)$/.test(fn)) {
- result = result.concat(getLocalNodeFiles(path.join(dir,fn)));
+ var subDirResults = getLocalNodeFiles(path.join(dir,fn));
+ result = result.concat(subDirResults.files);
+ icons = icons.concat(subDirResults.icons);
} else if (fn === "icons") {
var iconList = scanIconDir(path.join(dir,fn));
- events.emit("node-icon-dir",{name:'node-red',path:path.join(dir,fn),icons:iconList});
+ icons.push({path:path.join(dir,fn),icons:iconList});
}
}
});
- return result;
+ return {files: result, icons: icons}
}
function scanDirForNodesModules(dir,moduleName) {
@@ -198,7 +200,7 @@ function getModuleNodeFiles(module) {
var nodes = pkg['node-red'].nodes||{};
var results = [];
var iconDirs = [];
-
+ var iconList = [];
for (var n in nodes) {
/* istanbul ignore else */
if (nodes.hasOwnProperty(n)) {
@@ -213,47 +215,54 @@ function getModuleNodeFiles(module) {
if (iconDirs.indexOf(iconDir) == -1) {
try {
fs.statSync(iconDir);
- var iconList = scanIconDir(iconDir);
- events.emit("node-icon-dir",{name:pkg.name,path:iconDir,icons:iconList});
+ var icons = scanIconDir(iconDir);
+ iconList.push({path:iconDir,icons:icons});
iconDirs.push(iconDir);
} catch(err) {
}
}
}
}
+ var result = {files:results,icons:iconList};
+
var examplesDir = path.join(moduleDir,"examples");
try {
fs.statSync(examplesDir)
events.emit("node-examples-dir",{name:pkg.name,path:examplesDir});
} catch(err) {
}
- return results;
+ return result;
}
function getNodeFiles(disableNodePathScan) {
var dir;
// Find all of the nodes to load
var nodeFiles = [];
+ var results;
var dir = path.resolve(__dirname + '/../../../../public/icons');
- var iconList = scanIconDir(dir);
- events.emit("node-icon-dir",{name:'node-red',path:dir,icons:iconList});
+ var iconList = [{path:dir,icons:scanIconDir(dir)}];
if (settings.coreNodesDir) {
- nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
+ results = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
+ nodeFiles = nodeFiles.concat(results.files);
+ iconList = iconList.concat(results.icons);
+
var defaultLocalesPath = path.join(settings.coreNodesDir,"core","locales");
i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json");
}
if (settings.userDir) {
dir = path.join(settings.userDir,"lib","icons");
- iconList = scanIconDir(dir);
- if (iconList.length > 0) {
- events.emit("node-icon-dir",{name:'Library',path:dir,icons:iconList});
+ var icons = scanIconDir(dir);
+ if (icons.length > 0) {
+ iconList.push({path:dir,icons:icons});
}
dir = path.join(settings.userDir,"nodes");
- nodeFiles = nodeFiles.concat(getLocalNodeFiles(dir));
+ results = getLocalNodeFiles(path.resolve(dir));
+ nodeFiles = nodeFiles.concat(results.files);
+ iconList = iconList.concat(results.icons);
}
if (settings.nodesDir) {
dir = settings.nodesDir;
@@ -261,7 +270,9 @@ function getNodeFiles(disableNodePathScan) {
dir = [dir];
}
for (var i=0;i
icon_paths[module.name].push(path.resolve(icon.path)) )
}
-
- if (version) {
- moduleConfigs[set.module].version = version;
- }
- moduleConfigs[set.module].local = set.local;
-
- moduleConfigs[set.module].nodes[set.name] = set;
- nodeList.push(id);
nodeConfigCache = null;
}
+
function removeNode(id) {
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
if (!config) {
@@ -346,6 +343,7 @@ function getModuleInfo(module) {
name: module,
version: moduleConfigs[module].version,
local: moduleConfigs[module].local,
+ path: moduleConfigs[module].path,
nodes: []
};
for (var i = 0; i < nodes.length; ++i) {
@@ -592,6 +590,7 @@ var iconCache = {};
var defaultIcon = path.resolve(__dirname + '/../../../../public/icons/arrow-in.png');
function nodeIconDir(dir) {
+ return;
icon_paths[dir.name] = icon_paths[dir.name] || [];
icon_paths[dir.name].push(path.resolve(dir.path));
@@ -647,11 +646,11 @@ function getNodeIcons() {
for (var module in moduleConfigs) {
if (moduleConfigs.hasOwnProperty(module)) {
if (moduleConfigs[module].icons) {
- iconList[module] = moduleConfigs[module].icons;
+ iconList[module] = [];
+ moduleConfigs[module].icons.forEach(icon=>{ iconList[module] = iconList[module].concat(icon.icons) });
}
}
}
-
return iconList;
}
@@ -663,7 +662,9 @@ var registry = module.exports = {
registerNodeConstructor: registerNodeConstructor,
getNodeConstructor: getNodeConstructor,
- addNodeSet: addNodeSet,
+
+ addModule: addModule,
+
enableNodeSet: enableNodeSet,
disableNodeSet: disableNodeSet,
diff --git a/test/red/runtime/nodes/registry/loader_spec.js b/test/red/runtime/nodes/registry/loader_spec.js
index 87e1c060b..d34d802a3 100644
--- a/test/red/runtime/nodes/registry/loader_spec.js
+++ b/test/red/runtime/nodes/registry/loader_spec.js
@@ -79,6 +79,7 @@ describe("red/nodes/registry/loader",function() {
var result = {};
result["node-red"] = {
"name": "node-red",
+ "version": "1.2.3",
"nodes": {
"TestNode1": {
"file": path.join(resourcesDir,"TestNode1","TestNode1.js"),
@@ -91,34 +92,39 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
// This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
- registry.addNodeSet.called.should.be.true();
- registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode1");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
- registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
- registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-1');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
+ registry.addModule.called.should.be.true();
+ var module = registry.addModule.lastCall.args[0];
+ module.should.have.property("name","node-red");
+ module.should.have.property("version","1.2.3");
+ module.should.have.property("nodes");
+ module.nodes.should.have.property("TestNode1");
+ module.nodes.TestNode1.should.have.property("id","node-red/TestNode1");
+ module.nodes.TestNode1.should.have.property("module","node-red");
+ module.nodes.TestNode1.should.have.property("name","TestNode1");
+ module.nodes.TestNode1.should.have.property("file");
+ module.nodes.TestNode1.should.have.property("template");
+ module.nodes.TestNode1.should.have.property("enabled",true);
+ module.nodes.TestNode1.should.have.property("loaded",true);
+ module.nodes.TestNode1.should.have.property("types");
+ module.nodes.TestNode1.types.should.have.a.length(1);
+ module.nodes.TestNode1.types[0].should.eql('test-node-1');
+ module.nodes.TestNode1.should.have.property("config");
+ module.nodes.TestNode1.should.have.property("help");
+ module.nodes.TestNode1.should.have.property("namespace","node-red");
nodes.registerType.calledOnce.should.be.true();
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode1');
nodes.registerType.lastCall.args[1].should.eql('test-node-1');
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -128,6 +134,7 @@ describe("red/nodes/registry/loader",function() {
var result = {};
result["node-red"] = {
"name": "node-red",
+ "version": "4.5.6",
"nodes": {
"MultipleNodes1": {
"file": path.join(resourcesDir,"MultipleNodes1","MultipleNodes1.js"),
@@ -140,27 +147,33 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
// This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
- registry.addNodeSet.called.should.be.true();
- registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/MultipleNodes1");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
- registry.addNodeSet.lastCall.args[1].types.should.have.a.length(2);
- registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-multiple-1a');
- registry.addNodeSet.lastCall.args[1].types[1].should.eql('test-node-multiple-1b');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
+
+ registry.addModule.called.should.be.true();
+ var module = registry.addModule.lastCall.args[0];
+ module.should.have.property("name","node-red");
+ module.should.have.property("version","4.5.6");
+ module.should.have.property("nodes");
+ module.nodes.should.have.property("MultipleNodes1");
+ module.nodes.MultipleNodes1.should.have.property("id","node-red/MultipleNodes1");
+ module.nodes.MultipleNodes1.should.have.property("module","node-red");
+ module.nodes.MultipleNodes1.should.have.property("name","MultipleNodes1");
+ module.nodes.MultipleNodes1.should.have.property("file");
+ module.nodes.MultipleNodes1.should.have.property("template");
+ module.nodes.MultipleNodes1.should.have.property("enabled",true);
+ module.nodes.MultipleNodes1.should.have.property("loaded",true);
+ module.nodes.MultipleNodes1.should.have.property("types");
+ module.nodes.MultipleNodes1.types.should.have.a.length(2);
+ module.nodes.MultipleNodes1.types[0].should.eql('test-node-multiple-1a');
+ module.nodes.MultipleNodes1.types[1].should.eql('test-node-multiple-1b');
+ module.nodes.MultipleNodes1.should.have.property("config");
+ module.nodes.MultipleNodes1.should.have.property("help");
+ module.nodes.MultipleNodes1.should.have.property("namespace","node-red");
nodes.registerType.calledTwice.should.be.true();
nodes.registerType.firstCall.args[0].should.eql('node-red/MultipleNodes1');
@@ -168,8 +181,9 @@ describe("red/nodes/registry/loader",function() {
nodes.registerType.secondCall.args[0].should.eql('node-red/MultipleNodes1');
nodes.registerType.secondCall.args[1].should.eql('test-node-multiple-1b');
+
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -180,6 +194,7 @@ describe("red/nodes/registry/loader",function() {
var result = {};
result["node-red"] = {
"name": "node-red",
+ "version":"2.4.6",
"nodes": {
"TestNode2": {
"file": path.join(resourcesDir,"TestNode2","TestNode2.js"),
@@ -192,34 +207,41 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
// This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
- registry.addNodeSet.called.should.be.true();
- registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode2");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
- registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
- registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-2');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
+
+ registry.addModule.called.should.be.true();
+ var module = registry.addModule.lastCall.args[0];
+ module.should.have.property("name","node-red");
+ module.should.have.property("version","2.4.6");
+ module.should.have.property("nodes");
+ module.nodes.should.have.property("TestNode2");
+ module.nodes.TestNode2.should.have.property("id","node-red/TestNode2");
+ module.nodes.TestNode2.should.have.property("module","node-red");
+ module.nodes.TestNode2.should.have.property("name","TestNode2");
+ module.nodes.TestNode2.should.have.property("file");
+ module.nodes.TestNode2.should.have.property("template");
+ module.nodes.TestNode2.should.have.property("enabled",true);
+ module.nodes.TestNode2.should.have.property("loaded",true);
+ module.nodes.TestNode2.should.have.property("types");
+ module.nodes.TestNode2.types.should.have.a.length(1);
+ module.nodes.TestNode2.types[0].should.eql('test-node-2');
+ module.nodes.TestNode2.should.have.property("config");
+ module.nodes.TestNode2.should.have.property("help");
+ module.nodes.TestNode2.should.have.property("namespace","node-red");
+ module.nodes.TestNode2.should.not.have.property('err');
nodes.registerType.calledOnce.should.be.true();
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode2');
nodes.registerType.lastCall.args[1].should.eql('test-node-2');
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -230,6 +252,7 @@ describe("red/nodes/registry/loader",function() {
var result = {};
result["node-red"] = {
"name": "node-red",
+ "version":"1.2.3",
"nodes": {
"TestNode3": {
"file": path.join(resourcesDir,"TestNode3","TestNode3.js"),
@@ -242,32 +265,38 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
// This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
- registry.addNodeSet.called.should.be.true();
- registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode3");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
- registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
- registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-3');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('err','fail');
+ registry.addModule.called.should.be.true();
+ var module = registry.addModule.lastCall.args[0];
+ module.should.have.property("name","node-red");
+ module.should.have.property("version","1.2.3");
+ module.should.have.property("nodes");
+ module.nodes.should.have.property("TestNode3");
+ module.nodes.TestNode3.should.have.property("id","node-red/TestNode3");
+ module.nodes.TestNode3.should.have.property("module","node-red");
+ module.nodes.TestNode3.should.have.property("name","TestNode3");
+ module.nodes.TestNode3.should.have.property("file");
+ module.nodes.TestNode3.should.have.property("template");
+ module.nodes.TestNode3.should.have.property("enabled",true);
+ module.nodes.TestNode3.should.have.property("loaded",false);
+ module.nodes.TestNode3.should.have.property("types");
+ module.nodes.TestNode3.types.should.have.a.length(1);
+ module.nodes.TestNode3.types[0].should.eql('test-node-3');
+ module.nodes.TestNode3.should.have.property("config");
+ module.nodes.TestNode3.should.have.property("help");
+ module.nodes.TestNode3.should.have.property("namespace","node-red");
+ module.nodes.TestNode3.should.have.property('err','fail');
- nodes.registerType.calledOnce.should.be.false();
+ nodes.registerType.called.should.be.false();
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -277,6 +306,7 @@ describe("red/nodes/registry/loader",function() {
var result = {};
result["node-red"] = {
"name": "node-red",
+ "version":"1.2.3",
"nodes": {
"DoesNotExist": {
"file": path.join(resourcesDir,"doesnotexist"),
@@ -289,31 +319,37 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
// This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
- registry.addNodeSet.called.should.be.true();
- registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DoesNotExist");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
- registry.addNodeSet.lastCall.args[1].types.should.have.a.length(0);
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('config');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('help');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('err');
+ registry.addModule.called.should.be.true();
+ var module = registry.addModule.lastCall.args[0];
+ module.should.have.property("name","node-red");
+ module.should.have.property("version","1.2.3");
+ module.should.have.property("nodes");
+ module.nodes.should.have.property("DoesNotExist");
+ module.nodes.DoesNotExist.should.have.property("id","node-red/DoesNotExist");
+ module.nodes.DoesNotExist.should.have.property("module","node-red");
+ module.nodes.DoesNotExist.should.have.property("name","DoesNotExist");
+ module.nodes.DoesNotExist.should.have.property("file");
+ module.nodes.DoesNotExist.should.have.property("template");
+ module.nodes.DoesNotExist.should.have.property("enabled",true);
+ module.nodes.DoesNotExist.should.have.property("loaded",false);
+ module.nodes.DoesNotExist.should.have.property("types");
+ module.nodes.DoesNotExist.types.should.have.a.length(0);
+ module.nodes.DoesNotExist.should.not.have.property("config");
+ module.nodes.DoesNotExist.should.not.have.property("help");
+ module.nodes.DoesNotExist.should.not.have.property("namespace","node-red");
+ module.nodes.DoesNotExist.should.have.property('err');
- nodes.registerType.calledOnce.should.be.false();
+ nodes.registerType.called.should.be.false();
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -323,6 +359,7 @@ describe("red/nodes/registry/loader",function() {
var result = {};
result["node-red"] = {
"name": "node-red",
+ "version": "1.2.3",
"nodes": {
"DuffNode": {
"file": path.join(resourcesDir,"DuffNode","DuffNode.js"),
@@ -335,32 +372,39 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
// This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) {
- registry.addNodeSet.called.should.be.true();
- registry.addNodeSet.lastCall.args[0].should.eql("node-red/DuffNode");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DuffNode");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
- registry.addNodeSet.lastCall.args[1].types.should.have.a.length(0);
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('config');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('help');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('err');
- registry.addNodeSet.lastCall.args[1].err.should.endWith("DuffNode.html does not exist");
- nodes.registerType.calledOnce.should.be.false();
+ registry.addModule.called.should.be.true();
+ var module = registry.addModule.lastCall.args[0];
+ module.should.have.property("name","node-red");
+ module.should.have.property("version","1.2.3");
+ module.should.have.property("nodes");
+ module.nodes.should.have.property("DuffNode");
+ module.nodes.DuffNode.should.have.property("id","node-red/DuffNode");
+ module.nodes.DuffNode.should.have.property("module","node-red");
+ module.nodes.DuffNode.should.have.property("name","DuffNode");
+ module.nodes.DuffNode.should.have.property("file");
+ module.nodes.DuffNode.should.have.property("template");
+ module.nodes.DuffNode.should.have.property("enabled",true);
+ module.nodes.DuffNode.should.have.property("loaded",false);
+ module.nodes.DuffNode.should.have.property("types");
+ module.nodes.DuffNode.types.should.have.a.length(0);
+ module.nodes.DuffNode.should.not.have.property("config");
+ module.nodes.DuffNode.should.not.have.property("help");
+ module.nodes.DuffNode.should.not.have.property("namespace","node-red");
+ module.nodes.DuffNode.should.have.property('err');
+ module.nodes.DuffNode.err.should.endWith("DuffNode.html does not exist");
+
+ nodes.registerType.called.should.be.false();
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -379,7 +423,7 @@ describe("red/nodes/registry/loader",function() {
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
- loader.addModule("test-module").otherwise(function(err) {
+ loader.addModule("test-module").catch(function(err) {
err.code.should.eql("module_already_loaded");
done();
});
@@ -390,7 +434,7 @@ describe("red/nodes/registry/loader",function() {
throw new Error("failure");
}));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
- loader.addModule("test-module").otherwise(function(err) {
+ loader.addModule("test-module").catch(function(err) {
err.message.should.eql("failure");
done();
});
@@ -419,29 +463,36 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.addModule("TestNodeModule").then(function(result) {
result.should.eql("a node list");
- registry.addNodeSet.calledOnce.should.be.true();
- registry.addNodeSet.lastCall.args[0].should.eql("TestNodeModule/TestNode1");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"TestNodeModule/TestNode1");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"TestNodeModule");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
- registry.addNodeSet.lastCall.args[1].should.have.a.property('version',"1.2.3");
- registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
- registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
- registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-mod-1');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
- registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','TestNodeModule');
- registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
+
+ registry.addModule.called.should.be.true();
+ var module = registry.addModule.lastCall.args[0];
+ module.should.have.property("name","TestNodeModule");
+ module.should.have.property("version","1.2.3");
+ module.should.have.property("nodes");
+ module.nodes.should.have.property("TestNode1");
+ module.nodes.TestNode1.should.have.property("id","TestNodeModule/TestNode1");
+ module.nodes.TestNode1.should.have.property("module","TestNodeModule");
+ module.nodes.TestNode1.should.have.property("name","TestNode1");
+ module.nodes.TestNode1.should.have.property("file");
+ module.nodes.TestNode1.should.have.property("template");
+ module.nodes.TestNode1.should.have.property("enabled",true);
+ module.nodes.TestNode1.should.have.property("loaded",true);
+ module.nodes.TestNode1.should.have.property("types");
+ module.nodes.TestNode1.types.should.have.a.length(1);
+ module.nodes.TestNode1.types[0].should.eql('test-node-mod-1');
+ module.nodes.TestNode1.should.have.property("config");
+ module.nodes.TestNode1.should.have.property("help");
+ module.nodes.TestNode1.should.have.property("namespace","TestNodeModule");
+ module.nodes.TestNode1.should.not.have.property('err');
nodes.registerType.calledOnce.should.be.true();
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -469,15 +520,15 @@ describe("red/nodes/registry/loader",function() {
}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
- stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
+ stubs.push(sinon.stub(registry,"addModule", function(){ return }));
stubs.push(sinon.stub(nodes,"registerType"));
loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
loader.addModule("TestNodeModule").then(function(result) {
result.should.eql("a node list");
- registry.addNodeSet.called.should.be.false();
+ registry.addModule.called.should.be.false();
nodes.registerType.called.should.be.false();
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -498,7 +549,7 @@ describe("red/nodes/registry/loader",function() {
node.enabled.should.be.false();
nodes.registerType.called.should.be.false();
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -517,7 +568,7 @@ describe("red/nodes/registry/loader",function() {
node.err.toString().should.eql("Error: fail to require (line:1)");
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
diff --git a/test/red/runtime/nodes/registry/localfilesystem_spec.js b/test/red/runtime/nodes/registry/localfilesystem_spec.js
index d240e2ca5..2ffc220f4 100644
--- a/test/red/runtime/nodes/registry/localfilesystem_spec.js
+++ b/test/red/runtime/nodes/registry/localfilesystem_spec.js
@@ -166,7 +166,15 @@ describe("red/nodes/registry/localfilesystem",function() {
}},
settings:{coreNodesDir:resourcesDir}
});
- localfilesystem.getNodeFiles(true);
+ var list = localfilesystem.getNodeFiles(true);
+ list.should.have.property("node-red");
+ list["node-red"].should.have.property("icons");
+ list["node-red"].icons.should.have.length(2);
+ //list["node-red"].icons[1].should.have.property("path",path.join(__dirname,"resources/local/NestedDirectoryNode/NestedNode/icons"))
+ list["node-red"].icons[1].should.have.property("icons");
+ list["node-red"].icons[1].icons.should.have.length(1);
+ list["node-red"].icons[1].icons[0].should.eql("arrow-in.png");
+ done();
});
it("scans icons dir in library",function(done) {
var count = 0;
@@ -188,7 +196,15 @@ describe("red/nodes/registry/localfilesystem",function() {
}},
settings:{userDir:userDir}
});
- localfilesystem.getNodeFiles(true);
+ var list = localfilesystem.getNodeFiles(true);
+ list.should.have.property("node-red");
+ list["node-red"].should.have.property("icons");
+ list["node-red"].icons.should.have.length(2);
+ //list["node-red"].icons[1].should.have.property("path",path.join(__dirname,"resources/userDir/lib/icons"))
+ list["node-red"].icons[1].should.have.property("icons");
+ list["node-red"].icons[1].icons.should.have.length(1);
+ list["node-red"].icons[1].icons[0].should.eql("test_icon.png");
+ done();
});
});
describe("#getModuleFiles",function() {
@@ -256,6 +272,14 @@ describe("red/nodes/registry/localfilesystem",function() {
settings:{coreNodesDir:moduleDir}
});
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
+ nodeModule.should.have.property("TestNodeModule");
+ nodeModule.TestNodeModule.should.have.property('icons');
+
+ nodeModule.TestNodeModule.icons.should.have.length(1);
+ nodeModule.TestNodeModule.icons[0].should.have.property("path");
+ nodeModule.TestNodeModule.icons[0].should.have.property("icons");
+ nodeModule.TestNodeModule.icons[0].icons[0].should.eql("arrow-in.png");
+ done();
});
});
});
diff --git a/test/red/runtime/nodes/registry/registry_spec.js b/test/red/runtime/nodes/registry/registry_spec.js
index cdfba8c45..c5b9f6b5a 100644
--- a/test/red/runtime/nodes/registry/registry_spec.js
+++ b/test/red/runtime/nodes/registry/registry_spec.js
@@ -132,7 +132,7 @@ describe("red/nodes/registry/registry",function() {
});
- describe('#addNodeSet', function() {
+ describe.skip('#addNodeSet', function() {
it('adds a node set for an unknown module', function() {
typeRegistry.init(settings);
@@ -290,29 +290,34 @@ describe("red/nodes/registry/registry",function() {
describe('#saveNodeList',function() {
it('rejects when settings unavailable',function(done) {
- typeRegistry.init(stubSettings({},false,{}));
- typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
- typeRegistry.saveNodeList().otherwise(function(err) {
+ typeRegistry.init(stubSettings({},false,{}),null,events);
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {"test-name":{module:"test-module",name:"test-name",types:[]}}});
+ typeRegistry.saveNodeList().catch(function(err) {
done();
});
});
it('saves the list',function(done) {
var s = stubSettings({},true,{});
typeRegistry.init(s);
- typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
- typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":testNodeSet1,
+ "test-name-2":testNodeSet2WithError
+ }});
+
typeRegistry.saveNodeList().then(function() {
s.set.called.should.be.true();
s.set.lastCall.args[0].should.eql('nodes');
var nodes = s.set.lastCall.args[1];
nodes.should.have.property('test-module');
for (var n in nodes['test-module'].nodes) {
- var nn = nodes['test-module'].nodes[n];
- nn.should.not.have.property('err');
- nn.should.not.have.property('id');
+ if (nodes['test-module'].nodes.hasOwnProperty(n)) {
+ var nn = nodes['test-module'].nodes[n];
+ nn.should.not.have.property('err');
+ nn.should.not.have.property('id');
+ }
}
done();
- }).otherwise(function(err) {
+ }).catch(function(err) {
done(err);
});
});
@@ -338,7 +343,9 @@ describe("red/nodes/registry/registry",function() {
it('removes a known module', function() {
var s = stubSettings({},true,{});
typeRegistry.init(s);
- typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":testNodeSet1
+ }});
var moduleList = typeRegistry.getModuleList();
moduleList.should.have.a.property("test-module");
typeRegistry.getNodeList().should.have.lengthOf(1);
@@ -355,27 +362,28 @@ describe("red/nodes/registry/registry",function() {
typeRegistry.init(settings,{
getNodeHelp: function(config) { return "HE"+config.name+"LP" }
});
- typeRegistry.addNodeSet("test-module/test-name",{
- id: "test-module/test-name",
- module: "test-module",
- name: "test-name",
- enabled: true,
- loaded: false,
- config: "configA",
- types: [ "test-a","test-b"]
- }, "0.0.1");
- typeRegistry.getNodeConfig("test-module/test-name").should.eql('\nconfigAHEtest-nameLP');
- typeRegistry.getAllNodeConfigs().should.eql('\n\nconfigAHEtest-nameLP');
- typeRegistry.addNodeSet("test-module/test-name-2",{
- id: "test-module/test-name-2",
- module: "test-module",
- name: "test-name-2",
- enabled: true,
- loaded: false,
- config: "configB",
- types: [ "test-c","test-d"]
- }, "0.0.1");
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":{
+ id: "test-module/test-name",
+ module: "test-module",
+ name: "test-name",
+ enabled: true,
+ loaded: false,
+ config: "configA",
+ types: [ "test-a","test-b"]
+ },
+ "test-name-2":{
+ id: "test-module/test-name-2",
+ module: "test-module",
+ name: "test-name-2",
+ enabled: true,
+ loaded: false,
+ config: "configB",
+ types: [ "test-c","test-d"]
+ }
+ }});
+ typeRegistry.getNodeConfig("test-module/test-name").should.eql('\nconfigAHEtest-nameLP');
typeRegistry.getNodeConfig("test-module/test-name-2").should.eql('\nconfigBHEtest-name-2LP');
typeRegistry.getAllNodeConfigs().should.eql('\n\nconfigAHEtest-nameLP\n\nconfigBHEtest-name-2LP');
});
@@ -383,16 +391,18 @@ describe("red/nodes/registry/registry",function() {
describe('#getModuleInfo', function() {
it('returns module info', function() {
typeRegistry.init(settings,{});
- typeRegistry.addNodeSet("test-module/test-name",{
- id: "test-module/test-name",
- module: "test-module",
- name: "test-name",
- enabled: true,
- loaded: false,
- config: "configA",
- types: [ "test-a","test-b"],
- file: "abc"
- }, "0.0.1");
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":{
+ id: "test-module/test-name",
+ module: "test-module",
+ name: "test-name",
+ enabled: true,
+ loaded: false,
+ config: "configA",
+ types: [ "test-a","test-b"],
+ file: "abc"
+ }
+ }});
var moduleInfo = typeRegistry.getModuleInfo("test-module");
moduleInfo.should.have.a.property('name','test-module');
moduleInfo.should.have.a.property('version','0.0.1');
@@ -405,16 +415,18 @@ describe("red/nodes/registry/registry",function() {
describe('#getNodeInfo', function() {
it('returns node info', function() {
typeRegistry.init(settings,{});
- typeRegistry.addNodeSet("test-module/test-name",{
- id: "test-module/test-name",
- module: "test-module",
- name: "test-name",
- enabled: true,
- loaded: false,
- config: "configA",
- types: [ "test-a","test-b"],
- file: "abc"
- }, "0.0.1");
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":{
+ id: "test-module/test-name",
+ module: "test-module",
+ name: "test-name",
+ enabled: true,
+ loaded: false,
+ config: "configA",
+ types: [ "test-a","test-b"],
+ file: "abc"
+ }
+ }});
var nodeSetInfo = typeRegistry.getNodeInfo("test-module/test-name");
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
nodeSetInfo.should.not.have.a.property('config');
@@ -424,17 +436,19 @@ describe("red/nodes/registry/registry",function() {
describe('#getFullNodeInfo', function() {
it('returns node info', function() {
typeRegistry.init(settings,{});
- typeRegistry.addNodeSet("test-module/test-name",{
- id: "test-module/test-name",
- module: "test-module",
- name: "test-name",
- enabled: true,
- loaded: false,
- config: "configA",
- types: [ "test-a","test-b"],
- file: "abc"
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":{
+ id: "test-module/test-name",
+ module: "test-module",
+ name: "test-name",
+ enabled: true,
+ loaded: false,
+ config: "configA",
+ types: [ "test-a","test-b"],
+ file: "abc"
- }, "0.0.1");
+ }
+ }});
var nodeSetInfo = typeRegistry.getFullNodeInfo("test-module/test-name");
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
nodeSetInfo.should.have.a.property('config');
@@ -447,26 +461,28 @@ describe("red/nodes/registry/registry",function() {
describe('#getNodeList', function() {
it("returns a filtered list", function() {
typeRegistry.init(settings,{});
- typeRegistry.addNodeSet("test-module/test-name",{
- id: "test-module/test-name",
- module: "test-module",
- name: "test-name",
- enabled: true,
- loaded: false,
- config: "configA",
- types: [ "test-a","test-b"],
- file: "abc"
- }, "0.0.1");
- typeRegistry.addNodeSet("test-module/test-name-2",{
- id: "test-module/test-name-2",
- module: "test-module",
- name: "test-name-2",
- enabled: true,
- loaded: false,
- config: "configB",
- types: [ "test-c","test-d"],
- file: "def"
- }, "0.0.1");
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":{
+ id: "test-module/test-name",
+ module: "test-module",
+ name: "test-name",
+ enabled: true,
+ loaded: false,
+ config: "configA",
+ types: [ "test-a","test-b"],
+ file: "abc"
+ },
+ "test-name-2":{
+ id: "test-module/test-name-2",
+ module: "test-module",
+ name: "test-name-2",
+ enabled: true,
+ loaded: false,
+ config: "configB",
+ types: [ "test-c","test-d"],
+ file: "def"
+ }
+ }});
var filterCallCount = 0;
var filteredList = typeRegistry.getNodeList(function(n) { filterCallCount++; return n.name === 'test-name-2';});
filterCallCount.should.eql(2);
@@ -532,10 +548,22 @@ describe("red/nodes/registry/registry",function() {
});
it('returns a registered icon' , function() {
- var testIcon = path.resolve(__dirname+'/../../../../resources/icons/test_icon.png');
- events.emit("node-icon-dir",{name:"test-module", path: path.resolve(__dirname+'/../../../../resources/icons'), icons:[]});
+ var testIcon = path.resolve(__dirname+'/../../../../resources/icons/');
+ typeRegistry.init(settings,{});
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":{
+ id: "test-module/test-name",
+ module: "test-module",
+ name: "test-name",
+ enabled: true,
+ loaded: false,
+ config: "configA",
+ types: [ "test-a","test-b"],
+ file: "abc"
+ }
+ },icons: [{path:testIcon,icons:['test_icon.png']}]});
var iconPath = typeRegistry.getNodeIconPath('test-module','test_icon.png');
- iconPath.should.eql(testIcon);
+ iconPath.should.eql(testIcon+"/test_icon.png");
});
it('returns the debug icon when getting an unknown module', function() {
@@ -552,14 +580,26 @@ describe("red/nodes/registry/registry",function() {
});
it('returns an icon list of registered node module', function() {
- typeRegistry.addNodeSet("test-module/test-name",testNodeSet1,"0.0.1");
- events.emit("node-icon-dir",{name:"test-module", path:"",icons:["test_icon1.png"]});
+ var testIcon = path.resolve(__dirname+'/resources/userDir/lib/icons/');
+ typeRegistry.init(settings,{},events);
+ typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
+ "test-name":{
+ id: "test-module/test-name",
+ module: "test-module",
+ name: "test-name",
+ enabled: true,
+ loaded: false,
+ config: "configA",
+ types: [ "test-a","test-b"],
+ file: "abc"
+ }
+ },icons: [{path:testIcon,icons:['test_icon.png']}]});
var iconList = typeRegistry.getNodeIcons();
- iconList.should.eql({"test-module":["test_icon1.png"]});
+ iconList.should.eql({"test-module":["test_icon.png"]});
});
- it('returns an icon list of unregistered node module', function() {
- events.emit("node-icon-dir",{name:"test-module", path:"", icons:["test_icon1.png", "test_icon2.png"]});
+ it.skip('returns an icon list of unregistered node module', function() {
+ // events.emit("node-icon-dir",{name:"test-module", path:"", icons:["test_icon1.png", "test_icon2.png"]});
var iconList = typeRegistry.getNodeIcons();
iconList.should.eql({"test-module":["test_icon1.png","test_icon2.png"]});
});
diff --git a/test/red/runtime/nodes/resources/local/NestedDirectoryNode/NestedNode/icons/arrow-in.png b/test/red/runtime/nodes/resources/local/NestedDirectoryNode/NestedNode/icons/arrow-in.png
new file mode 100644
index 000000000..e38f39146
Binary files /dev/null and b/test/red/runtime/nodes/resources/local/NestedDirectoryNode/NestedNode/icons/arrow-in.png differ
diff --git a/test/red/runtime/nodes/resources/local/NestedDirectoryNode/NestedNode/icons/file.txt b/test/red/runtime/nodes/resources/local/NestedDirectoryNode/NestedNode/icons/file.txt
deleted file mode 100644
index 59a29af14..000000000
--- a/test/red/runtime/nodes/resources/local/NestedDirectoryNode/NestedNode/icons/file.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-This file exists just to ensure the 'icons' directory is in the repository.
-TODO: a future test needs to ensure the right icon files are loaded - this
- directory can be used for that
diff --git a/test/red/runtime/nodes/resources/local/TestNodeModule/node_modules/TestNodeModule/icons/file.txt b/test/red/runtime/nodes/resources/local/TestNodeModule/node_modules/TestNodeModule/icons/file.txt
deleted file mode 100644
index 59a29af14..000000000
--- a/test/red/runtime/nodes/resources/local/TestNodeModule/node_modules/TestNodeModule/icons/file.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-This file exists just to ensure the 'icons' directory is in the repository.
-TODO: a future test needs to ensure the right icon files are loaded - this
- directory can be used for that