1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Resolve dir argument of getLocalNodeFiles function (#1216)

* Resolve dir argument of getLocalNodeFiles function

The getLocalNodeFiles is called 3 times.  Each time it called, the callee needs to resolve the dir argument.
That was not done for several of calls, and local modules (specified in the "nodesDir" setting) were not returned to client because of that.

This fix will allow to make sure the dir is consistently resolved.

* Several changes in "localfilesystem_spec.js":
- Changed checkNodes to verify that every node's file property is resolved, i.e. containst absolute path, not relative.
- Added a unit-test "Finds nodes in settings.nodesDir (string,relative path)"
This commit is contained in:
Andrey Bezugliy 2017-04-10 17:41:20 +03:00 committed by Nick O'Leary
parent 73dfe631ce
commit f987fa13ea
2 changed files with 16 additions and 2 deletions

View File

@ -67,6 +67,8 @@ function getLocalFile(file) {
* @return an array of fully-qualified paths to .js files * @return an array of fully-qualified paths to .js files
*/ */
function getLocalNodeFiles(dir) { function getLocalNodeFiles(dir) {
dir = path.resolve(dir);
var result = []; var result = [];
var files = []; var files = [];
try { try {
@ -205,7 +207,7 @@ function getNodeFiles(disableNodePathScan) {
if (settings.coreNodesDir) { if (settings.coreNodesDir) {
nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir)); nodeFiles = getLocalNodeFiles(path.resolve(settings.coreNodesDir));
var defaultLocalesPath = path.resolve(path.join(settings.coreNodesDir,"core","locales")); var defaultLocalesPath = path.join(settings.coreNodesDir,"core","locales");
i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json"); i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json");
} }

View File

@ -36,6 +36,7 @@ describe("red/nodes/registry/localfilesystem",function() {
for (var i=0;i<shouldHaveNodes.length;i++) { for (var i=0;i<shouldHaveNodes.length;i++) {
nodes.should.have.a.property(shouldHaveNodes[i]); nodes.should.have.a.property(shouldHaveNodes[i]);
nodes[shouldHaveNodes[i]].should.have.a.property('file'); nodes[shouldHaveNodes[i]].should.have.a.property('file');
nodes[shouldHaveNodes[i]].file.should.equal(path.resolve(nodes[shouldHaveNodes[i]].file));
nodes[shouldHaveNodes[i]].should.have.a.property('module',module||'node-red'); nodes[shouldHaveNodes[i]].should.have.a.property('module',module||'node-red');
nodes[shouldHaveNodes[i]].should.have.a.property('name',shouldHaveNodes[i]); nodes[shouldHaveNodes[i]].should.have.a.property('name',shouldHaveNodes[i]);
} }
@ -85,6 +86,17 @@ describe("red/nodes/registry/localfilesystem",function() {
nm.should.have.a.property("nodes"); nm.should.have.a.property("nodes");
checkNodes(nm.nodes,['TestNode5'],['TestNode1']); checkNodes(nm.nodes,['TestNode5'],['TestNode1']);
done(); done();
});
it("Finds nodes in settings.nodesDir (string,relative path)",function(done) {
var relativeUserDir = path.join("test","red","runtime","nodes","resources","userDir");
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:relativeUserDir,coreNodesDir:__dirname}});
var nodeList = localfilesystem.getNodeFiles(true);
nodeList.should.have.a.property("node-red");
var nm = nodeList['node-red'];
nm.should.have.a.property('name','node-red');
nm.should.have.a.property("nodes");
checkNodes(nm.nodes,['TestNode5'],['TestNode1']);
done();
}); });
it("Finds nodes in settings.nodesDir (array)",function(done) { it("Finds nodes in settings.nodesDir (array)",function(done) {
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:[userDir],coreNodesDir:__dirname}}); localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:[userDir],coreNodesDir:__dirname}});