mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
WIP: runtime api for node modules
This commit is contained in:
parent
f62b7afede
commit
d673846e3d
@ -38,7 +38,7 @@ function checkBuild() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var RED = {
|
module.exports = {
|
||||||
init: function(httpServer,userSettings) {
|
init: function(httpServer,userSettings) {
|
||||||
server = httpServer;
|
server = httpServer;
|
||||||
|
|
||||||
@ -79,12 +79,12 @@ var RED = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
nodes: runtime.api,
|
nodes: runtime.api,
|
||||||
events: runtime.events,
|
|
||||||
log: runtime.log,
|
log: runtime.log,
|
||||||
comms: api.comms,
|
|
||||||
settings:runtime.settings,
|
settings:runtime.settings,
|
||||||
util: runtime.util,
|
util: runtime.util,
|
||||||
version: runtime.version,
|
version: runtime.version,
|
||||||
|
|
||||||
|
comms: api.comms,
|
||||||
library: api.library,
|
library: api.library,
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
|
|
||||||
@ -93,5 +93,3 @@ var RED = {
|
|||||||
get httpNode() { return nodeApp },
|
get httpNode() { return nodeApp },
|
||||||
get server() { return server }
|
get server() { return server }
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = RED;
|
|
||||||
|
@ -66,7 +66,7 @@ function start() {
|
|||||||
}
|
}
|
||||||
log.info(log._("runtime.version",{component:"Node.js ",version:process.version}));
|
log.info(log._("runtime.version",{component:"Node.js ",version:process.version}));
|
||||||
log.info(log._("server.loading"));
|
log.info(log._("server.loading"));
|
||||||
redNodes.init(settings,storage);
|
redNodes.init(runtime);
|
||||||
return redNodes.load().then(function() {
|
return redNodes.load().then(function() {
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
|
@ -64,11 +64,11 @@ function createNode(node,def) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(_settings,storage) {
|
function init(runtime) {
|
||||||
settings = _settings;
|
settings = runtime.settings;
|
||||||
credentials.init(storage);
|
credentials.init(runtime.storage);
|
||||||
flows.init(_settings,storage);
|
flows.init(runtime.settings,runtime.storage);
|
||||||
registry.init(_settings);
|
registry.init(runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableNode(id) {
|
function disableNode(id) {
|
||||||
|
@ -25,11 +25,11 @@ var installer = require("./installer");
|
|||||||
|
|
||||||
var settings;
|
var settings;
|
||||||
|
|
||||||
function init(_settings) {
|
function init(runtime) {
|
||||||
settings = _settings;
|
settings = runtime.settings;
|
||||||
installer.init(settings);
|
installer.init(runtime.settings);
|
||||||
loader.init(settings);
|
loader.init(runtime);
|
||||||
registry.init(settings,loader);
|
registry.init(runtime.settings,loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addModule(module) {
|
function addModule(module) {
|
||||||
|
@ -19,23 +19,25 @@ var fs = require("fs");
|
|||||||
var path = require("path");
|
var path = require("path");
|
||||||
var semver = require("semver");
|
var semver = require("semver");
|
||||||
|
|
||||||
var events = require("../../events");
|
|
||||||
|
|
||||||
var localfilesystem = require("./localfilesystem");
|
var localfilesystem = require("./localfilesystem");
|
||||||
var registry = require("./registry");
|
var registry = require("./registry");
|
||||||
|
|
||||||
var RED;
|
var RED;
|
||||||
var settings;
|
var settings;
|
||||||
|
var runtime;
|
||||||
|
|
||||||
var i18n = require("../../i18n");
|
function registerMessageCatalog(info) {
|
||||||
|
runtime.i18n.registerMessageCatalog(info.namespace,info.dir,info.file);
|
||||||
|
}
|
||||||
|
|
||||||
events.on("node-locales-dir", function(info) {
|
function init(_runtime) {
|
||||||
i18n.registerMessageCatalog(info.namespace,info.dir,info.file);
|
runtime = _runtime;
|
||||||
});
|
settings = runtime.settings;
|
||||||
|
localfilesystem.init(runtime);
|
||||||
function init(_settings) {
|
if (runtime.events) {
|
||||||
settings = _settings;
|
runtime.events.removeListener("node-locales-dir", registerMessageCatalog);
|
||||||
localfilesystem.init(settings);
|
runtime.events.on("node-locales-dir", registerMessageCatalog);
|
||||||
|
}
|
||||||
RED = require('../../../red');
|
RED = require('../../../red');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ function loadNodeFiles(nodeFiles) {
|
|||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (nodeFiles.hasOwnProperty(module)) {
|
if (nodeFiles.hasOwnProperty(module)) {
|
||||||
if (nodeFiles[module].redVersion &&
|
if (nodeFiles[module].redVersion &&
|
||||||
!semver.satisfies(RED.version().replace("-git",""), nodeFiles[module].redVersion)) {
|
!semver.satisfies(runtime.version().replace("-git",""), nodeFiles[module].redVersion)) {
|
||||||
//TODO: log it
|
//TODO: log it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -195,7 +197,7 @@ function loadNodeConfig(fileInfo) {
|
|||||||
fs.stat(path.join(path.dirname(file),"locales"),function(err,stat) {
|
fs.stat(path.join(path.dirname(file),"locales"),function(err,stat) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
node.namespace = node.id;
|
node.namespace = node.id;
|
||||||
i18n.registerMessageCatalog(node.id,
|
runtime.i18n.registerMessageCatalog(node.id,
|
||||||
path.join(path.dirname(file),"locales"),
|
path.join(path.dirname(file),"locales"),
|
||||||
path.basename(file,".js")+".json")
|
path.basename(file,".js")+".json")
|
||||||
.then(function() {
|
.then(function() {
|
||||||
@ -211,20 +213,6 @@ function loadNodeConfig(fileInfo) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//function getAPIForNode(node) {
|
|
||||||
// var red = {
|
|
||||||
// nodes: RED.nodes,
|
|
||||||
// library: RED.library,
|
|
||||||
// credentials: RED.credentials,
|
|
||||||
// events: RED.events,
|
|
||||||
// log: RED.log,
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the specified node into the runtime
|
* Loads the specified node into the runtime
|
||||||
* @param node a node info object - see loadNodeConfig
|
* @param node a node info object - see loadNodeConfig
|
||||||
|
@ -18,15 +18,18 @@ var when = require("when");
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
var events = require("../../events");
|
var events;
|
||||||
var log = require("../../log");
|
var log;
|
||||||
|
|
||||||
var settings;
|
var settings;
|
||||||
var defaultNodesDir = path.resolve(path.join(__dirname,"..","..","..","..","nodes"));
|
var defaultNodesDir = path.resolve(path.join(__dirname,"..","..","..","..","nodes"));
|
||||||
var disableNodePathScan = false;
|
var disableNodePathScan = false;
|
||||||
|
|
||||||
function init(_settings,_defaultNodesDir,_disableNodePathScan) {
|
function init(runtime,_defaultNodesDir,_disableNodePathScan) {
|
||||||
settings = _settings;
|
settings = runtime.settings;
|
||||||
|
events = runtime.events;
|
||||||
|
log = runtime.log;
|
||||||
|
|
||||||
if (_disableNodePathScan) {
|
if (_disableNodePathScan) {
|
||||||
disableNodePathScan = _disableNodePathScan;
|
disableNodePathScan = _disableNodePathScan;
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ describe('Credentials', function() {
|
|||||||
var settings = {
|
var settings = {
|
||||||
available: function() { return false;}
|
available: function() { return false;}
|
||||||
}
|
}
|
||||||
index.init(settings, storage);
|
index.init({settings:settings, storage:storage});
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
|
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
|
||||||
|
@ -59,6 +59,11 @@ describe("red/nodes/index", function() {
|
|||||||
available: function() { return false }
|
available: function() { return false }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var runtime = {
|
||||||
|
settings: settings,
|
||||||
|
storage: storage
|
||||||
|
};
|
||||||
|
|
||||||
function TestNode(n) {
|
function TestNode(n) {
|
||||||
index.createNode(this, n);
|
index.createNode(this, n);
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -68,7 +73,7 @@ describe("red/nodes/index", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('nodes are initialised with credentials',function(done) {
|
it('nodes are initialised with credentials',function(done) {
|
||||||
index.init(settings, storage);
|
index.init(runtime);
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
|
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
|
||||||
@ -81,7 +86,7 @@ describe("red/nodes/index", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('flows should be initialised',function(done) {
|
it('flows should be initialised',function(done) {
|
||||||
index.init(settings, storage);
|
index.init(runtime);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
should.deepEqual(testFlows, index.getFlows());
|
should.deepEqual(testFlows, index.getFlows());
|
||||||
done();
|
done();
|
||||||
@ -168,7 +173,7 @@ describe("red/nodes/index", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it(': allows an unused node type to be disabled',function(done) {
|
it(': allows an unused node type to be disabled',function(done) {
|
||||||
index.init(settings, storage);
|
index.init(runtime);
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
var info = index.disableNode("5678");
|
var info = index.disableNode("5678");
|
||||||
@ -182,7 +187,7 @@ describe("red/nodes/index", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it(': prevents disabling a node type that is in use',function(done) {
|
it(': prevents disabling a node type that is in use',function(done) {
|
||||||
index.init(settings, storage);
|
index.init(runtime);
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
@ -197,7 +202,7 @@ describe("red/nodes/index", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it(': prevents disabling a node type that is unknown',function(done) {
|
it(': prevents disabling a node type that is unknown',function(done) {
|
||||||
index.init(settings, storage);
|
index.init(runtime);
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
@ -250,7 +255,7 @@ describe("red/nodes/index", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it(': prevents removing a module that is in use',function(done) {
|
it(': prevents removing a module that is in use',function(done) {
|
||||||
index.init(settings, storage);
|
index.init(runtime);
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
@ -265,7 +270,7 @@ describe("red/nodes/index", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it(': prevents removing a module that is unknown',function(done) {
|
it(': prevents removing a module that is unknown',function(done) {
|
||||||
index.init(settings, storage);
|
index.init(runtime);
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
|
@ -44,7 +44,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
})
|
})
|
||||||
describe("#init",function() {
|
describe("#init",function() {
|
||||||
it("init",function() {
|
it("init",function() {
|
||||||
loader.init({});
|
loader.init({events:{on:function(){},removeListener:function(){}}});
|
||||||
localfilesystem.init.called.should.be.true;
|
localfilesystem.init.called.should.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -53,7 +53,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
it("load empty set without settings available", function(done) {
|
it("load empty set without settings available", function(done) {
|
||||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
||||||
loader.init({available:function(){return false;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
|
||||||
loader.load("foo",true).then(function() {
|
loader.load("foo",true).then(function() {
|
||||||
localfilesystem.getNodeFiles.called.should.be.true;
|
localfilesystem.getNodeFiles.called.should.be.true;
|
||||||
localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo');
|
localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo');
|
||||||
@ -65,7 +65,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
it("load empty set with settings available triggers registery save", function(done) {
|
it("load empty set with settings available triggers registery save", function(done) {
|
||||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load("foo",true).then(function() {
|
loader.load("foo",true).then(function() {
|
||||||
registry.saveNodeList.called.should.be.true;
|
registry.saveNodeList.called.should.be.true;
|
||||||
done();
|
done();
|
||||||
@ -96,7 +96,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true;
|
registry.addNodeSet.called.should.be.true;
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
|
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
|
||||||
@ -143,7 +143,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
// This module isn't already loaded
|
// This module isn't already loaded
|
||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true;
|
registry.addNodeSet.called.should.be.true;
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
|
registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
|
||||||
@ -194,7 +194,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true;
|
registry.addNodeSet.called.should.be.true;
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
|
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
|
||||||
@ -243,7 +243,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true;
|
registry.addNodeSet.called.should.be.true;
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
|
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
|
||||||
@ -290,7 +290,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||||
|
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.load().then(function(result) {
|
loader.load().then(function(result) {
|
||||||
registry.addNodeSet.called.should.be.true;
|
registry.addNodeSet.called.should.be.true;
|
||||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
|
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
|
||||||
@ -317,7 +317,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
|
|
||||||
describe("#addModule",function() {
|
describe("#addModule",function() {
|
||||||
it("throws error if settings unavailable", function() {
|
it("throws error if settings unavailable", function() {
|
||||||
loader.init({available:function(){return false;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
(function(){
|
(function(){
|
||||||
loader.addModule("test-module");
|
loader.addModule("test-module");
|
||||||
@ -326,7 +326,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
|
|
||||||
it("returns rejected error if module already loaded", function(done) {
|
it("returns rejected error if module already loaded", function(done) {
|
||||||
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
|
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
|
|
||||||
loader.addModule("test-module").otherwise(function(err) {
|
loader.addModule("test-module").otherwise(function(err) {
|
||||||
err.code.should.eql("module_already_loaded");
|
err.code.should.eql("module_already_loaded");
|
||||||
@ -338,7 +338,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(localfilesystem,"getModuleFiles",function() {
|
stubs.push(sinon.stub(localfilesystem,"getModuleFiles",function() {
|
||||||
throw new Error("failure");
|
throw new Error("failure");
|
||||||
}));
|
}));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.addModule("test-module").otherwise(function(err) {
|
loader.addModule("test-module").otherwise(function(err) {
|
||||||
err.message.should.eql("failure");
|
err.message.should.eql("failure");
|
||||||
done();
|
done();
|
||||||
@ -370,7 +370,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||||
loader.addModule("TestNodeModule").then(function(result) {
|
loader.addModule("TestNodeModule").then(function(result) {
|
||||||
result.should.eql("a node list");
|
result.should.eql("a node list");
|
||||||
registry.addNodeSet.calledOnce.should.be.true;
|
registry.addNodeSet.calledOnce.should.be.true;
|
||||||
@ -420,7 +420,7 @@ describe("red/nodes/registry/loader",function() {
|
|||||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||||
stubs.push(sinon.stub(nodes,"registerType"));
|
stubs.push(sinon.stub(nodes,"registerType"));
|
||||||
loader.init({available:function(){return true;}});
|
loader.init({events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
|
||||||
loader.addModule("TestNodeModule").then(function(result) {
|
loader.addModule("TestNodeModule").then(function(result) {
|
||||||
result.should.eql("a node list");
|
result.should.eql("a node list");
|
||||||
registry.addNodeSet.called.should.be.false;
|
registry.addNodeSet.called.should.be.false;
|
||||||
|
@ -45,7 +45,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
describe("#getNodeFiles",function() {
|
describe("#getNodeFiles",function() {
|
||||||
it("Finds all the node files in the resources tree",function(done) {
|
it("Finds all the node files in the resources tree",function(done) {
|
||||||
localfilesystem.init({});
|
localfilesystem.init({events:{emit:function(){}},settings:{}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
|
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
@ -56,7 +56,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it("Excludes node files from settings",function(done) {
|
it("Excludes node files from settings",function(done) {
|
||||||
localfilesystem.init({nodesExcludes:['TestNode1.js']});
|
localfilesystem.init({events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js']}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
|
var nodeList = localfilesystem.getNodeFiles(resourcesDir,true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
@ -66,7 +66,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it("Finds nodes in userDir/nodes",function(done) {
|
it("Finds nodes in userDir/nodes",function(done) {
|
||||||
localfilesystem.init({userDir:userDir});
|
localfilesystem.init({events:{emit:function(){}},settings:{userDir:userDir}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
@ -77,7 +77,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Finds nodes in settings.nodesDir (string)",function(done) {
|
it("Finds nodes in settings.nodesDir (string)",function(done) {
|
||||||
localfilesystem.init({nodesDir:userDir});
|
localfilesystem.init({events:{emit:function(){}},settings:{nodesDir:userDir}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
@ -87,7 +87,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it("Finds nodes in settings.nodesDir (array)",function(done) {
|
it("Finds nodes in settings.nodesDir (array)",function(done) {
|
||||||
localfilesystem.init({nodesDir:[userDir]});
|
localfilesystem.init({events:{emit:function(){}},settings:{nodesDir:[userDir]}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
var nodeList = localfilesystem.getNodeFiles(__dirname,true);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
@ -106,7 +106,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
return _join.apply(null,arguments);
|
return _join.apply(null,arguments);
|
||||||
}));
|
}));
|
||||||
localfilesystem.init({});
|
localfilesystem.init({events:{emit:function(){}},settings:{}});
|
||||||
var nodeList = localfilesystem.getNodeFiles(moduleDir,false);
|
var nodeList = localfilesystem.getNodeFiles(moduleDir,false);
|
||||||
nodeList.should.have.a.property("node-red");
|
nodeList.should.have.a.property("node-red");
|
||||||
var nm = nodeList['node-red'];
|
var nm = nodeList['node-red'];
|
||||||
@ -126,6 +126,9 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
it.skip("finds locales directory");
|
||||||
|
it.skip("finds icon path directory");
|
||||||
|
|
||||||
});
|
});
|
||||||
describe("#getModuleFiles",function() {
|
describe("#getModuleFiles",function() {
|
||||||
it("gets a nodes module files",function(done) {
|
it("gets a nodes module files",function(done) {
|
||||||
@ -138,7 +141,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
return _join.apply(null,arguments);
|
return _join.apply(null,arguments);
|
||||||
}));
|
}));
|
||||||
localfilesystem.init({},moduleDir,true);
|
localfilesystem.init({events:{emit:function(){}},settings:{}},moduleDir,true);
|
||||||
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
||||||
nodeModule.should.have.a.property('TestNodeModule');
|
nodeModule.should.have.a.property('TestNodeModule');
|
||||||
nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule');
|
nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule');
|
||||||
@ -162,12 +165,14 @@ describe("red/nodes/registry/localfilesystem",function() {
|
|||||||
}
|
}
|
||||||
return _join.apply(null,arguments);
|
return _join.apply(null,arguments);
|
||||||
}));
|
}));
|
||||||
localfilesystem.init({},moduleDir,true);
|
localfilesystem.init({events:{emit:function(){}},settings:{}},moduleDir,true);
|
||||||
/*jshint immed: false */
|
/*jshint immed: false */
|
||||||
(function(){
|
(function(){
|
||||||
localfilesystem.getModuleFiles('WontExistModule');
|
localfilesystem.getModuleFiles('WontExistModule');
|
||||||
}).should.throw();
|
}).should.throw();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
it.skip("finds locales directory");
|
||||||
|
it.skip("finds icon path directory");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user