mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Improve processing when default is an alias
and fix test cases
This commit is contained in:
parent
e046fc1ac5
commit
0be9c88106
@ -37,7 +37,7 @@ function init(_settings) {
|
|||||||
function load() {
|
function load() {
|
||||||
// load & init plugins in settings.contextStorage
|
// load & init plugins in settings.contextStorage
|
||||||
var plugins = settings.contextStorage;
|
var plugins = settings.contextStorage;
|
||||||
var alias = null;
|
var isAlias = false;
|
||||||
if (plugins) {
|
if (plugins) {
|
||||||
noContextStorage = false;
|
noContextStorage = false;
|
||||||
for(var pluginName in plugins){
|
for(var pluginName in plugins){
|
||||||
@ -45,7 +45,7 @@ function load() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(pluginName === "default" && typeof plugins[pluginName] === "string"){
|
if(pluginName === "default" && typeof plugins[pluginName] === "string"){
|
||||||
alias = plugins[pluginName];
|
isAlias = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var plugin;
|
var plugin;
|
||||||
@ -67,9 +67,9 @@ function load() {
|
|||||||
throw new Error(log._("context.error-module-not-defined", {storage:pluginName}));
|
throw new Error(log._("context.error-module-not-defined", {storage:pluginName}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(alias){
|
if(isAlias){
|
||||||
if(externalContexts.hasOwnProperty(alias)){
|
if(externalContexts.hasOwnProperty(plugins["default"])){
|
||||||
externalContexts["default"] = externalContexts[alias];
|
externalContexts["default"] = externalContexts[plugins["default"]];
|
||||||
}else{
|
}else{
|
||||||
throw new Error(log._("context.error-invalid-default-module", {storage:plugins["default"]}));
|
throw new Error(log._("context.error-invalid-default-module", {storage:plugins["default"]}));
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ describe("runtime", function() {
|
|||||||
var redNodesGetNodeList;
|
var redNodesGetNodeList;
|
||||||
var redNodesLoadFlows;
|
var redNodesLoadFlows;
|
||||||
var redNodesStartFlows;
|
var redNodesStartFlows;
|
||||||
|
var redNodesLoadContextsPlugin;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
storageInit = sinon.stub(storage,"init",function(settings) {return when.resolve();});
|
storageInit = sinon.stub(storage,"init",function(settings) {return when.resolve();});
|
||||||
@ -91,6 +92,7 @@ describe("runtime", function() {
|
|||||||
redNodesCleanModuleList = sinon.stub(redNodes,"cleanModuleList",function(){});
|
redNodesCleanModuleList = sinon.stub(redNodes,"cleanModuleList",function(){});
|
||||||
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows",function() {return when.resolve()});
|
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows",function() {return when.resolve()});
|
||||||
redNodesStartFlows = sinon.stub(redNodes,"startFlows",function() {});
|
redNodesStartFlows = sinon.stub(redNodes,"startFlows",function() {});
|
||||||
|
redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin",function() {});
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
storageInit.restore();
|
storageInit.restore();
|
||||||
@ -104,6 +106,7 @@ describe("runtime", function() {
|
|||||||
redNodesCleanModuleList.restore();
|
redNodesCleanModuleList.restore();
|
||||||
redNodesLoadFlows.restore();
|
redNodesLoadFlows.restore();
|
||||||
redNodesStartFlows.restore();
|
redNodesStartFlows.restore();
|
||||||
|
redNodesLoadContextsPlugin.restore();
|
||||||
});
|
});
|
||||||
it("reports errored/missing modules",function(done) {
|
it("reports errored/missing modules",function(done) {
|
||||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
|
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
|
||||||
|
@ -123,7 +123,7 @@ describe('context', function() {
|
|||||||
should.not.exist(context.get("foo"));
|
should.not.exist(context.get("foo"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('enumerates context keys', function() {
|
it('enumerates context keys', function() {
|
||||||
var context = Context.get("1","flowA");
|
var context = Context.get("1","flowA");
|
||||||
|
|
||||||
var keys = context.keys();
|
var keys = context.keys();
|
||||||
@ -168,6 +168,7 @@ describe('context', function() {
|
|||||||
stubGet.reset();
|
stubGet.reset();
|
||||||
stubSet.reset();
|
stubSet.reset();
|
||||||
stubKeys.reset();
|
stubKeys.reset();
|
||||||
|
stubDelete.reset();
|
||||||
Context.clean({allNodes:{}});
|
Context.clean({allNodes:{}});
|
||||||
fs.remove(testDir,done);
|
fs.remove(testDir,done);
|
||||||
});
|
});
|
||||||
@ -418,7 +419,7 @@ describe('context', function() {
|
|||||||
var result = parseKey(input);
|
var result = parseKey(input);
|
||||||
result.storage.should.eql(expectedModule);
|
result.storage.should.eql(expectedModule);
|
||||||
result.key.should.eql(expectedKey);
|
result.key.should.eql(expectedKey);
|
||||||
};
|
}
|
||||||
|
|
||||||
it('should return module and key', function() {
|
it('should return module and key', function() {
|
||||||
returnModuleAndKey("$test.aaa","test","aaa");
|
returnModuleAndKey("$test.aaa","test","aaa");
|
||||||
|
@ -153,11 +153,9 @@ describe("red/util", function() {
|
|||||||
var v = util.getMessageProperty({a:"foo"},"msg.b");
|
var v = util.getMessageProperty({a:"foo"},"msg.b");
|
||||||
should.not.exist(v);
|
should.not.exist(v);
|
||||||
});
|
});
|
||||||
it('should throw error if property parent does not exist', function() {
|
it('should return undefined if property parent does not exist', function() {
|
||||||
/*jshint immed: false */
|
var v = util.getMessageProperty({a:"foo"},"msg.a.b.c");
|
||||||
(function() {
|
should.not.exist(v);
|
||||||
util.getMessageProperty({a:"foo"},"msg.a.b.c");
|
|
||||||
}).should.throw();
|
|
||||||
});
|
});
|
||||||
it('retrieves a property with array syntax', function() {
|
it('retrieves a property with array syntax', function() {
|
||||||
var v = util.getMessageProperty({a:["foo","bar"]},"msg.a[0]");
|
var v = util.getMessageProperty({a:["foo","bar"]},"msg.a[0]");
|
||||||
|
Loading…
Reference in New Issue
Block a user