1
0
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:
Hiroki Uchikawa 2018-04-23 10:45:30 +09:00 committed by HirokiUchikawa
parent e046fc1ac5
commit 0be9c88106
4 changed files with 14 additions and 12 deletions

View File

@ -37,7 +37,7 @@ function init(_settings) {
function load() {
// load & init plugins in settings.contextStorage
var plugins = settings.contextStorage;
var alias = null;
var isAlias = false;
if (plugins) {
noContextStorage = false;
for(var pluginName in plugins){
@ -45,7 +45,7 @@ function load() {
continue;
}
if(pluginName === "default" && typeof plugins[pluginName] === "string"){
alias = plugins[pluginName];
isAlias = true;
continue;
}
var plugin;
@ -67,9 +67,9 @@ function load() {
throw new Error(log._("context.error-module-not-defined", {storage:pluginName}));
}
}
if(alias){
if(externalContexts.hasOwnProperty(alias)){
externalContexts["default"] = externalContexts[alias];
if(isAlias){
if(externalContexts.hasOwnProperty(plugins["default"])){
externalContexts["default"] = externalContexts[plugins["default"]];
}else{
throw new Error(log._("context.error-invalid-default-module", {storage:plugins["default"]}));
}

View File

@ -79,6 +79,7 @@ describe("runtime", function() {
var redNodesGetNodeList;
var redNodesLoadFlows;
var redNodesStartFlows;
var redNodesLoadContextsPlugin;
beforeEach(function() {
storageInit = sinon.stub(storage,"init",function(settings) {return when.resolve();});
@ -91,6 +92,7 @@ describe("runtime", function() {
redNodesCleanModuleList = sinon.stub(redNodes,"cleanModuleList",function(){});
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows",function() {return when.resolve()});
redNodesStartFlows = sinon.stub(redNodes,"startFlows",function() {});
redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin",function() {});
});
afterEach(function() {
storageInit.restore();
@ -104,6 +106,7 @@ describe("runtime", function() {
redNodesCleanModuleList.restore();
redNodesLoadFlows.restore();
redNodesStartFlows.restore();
redNodesLoadContextsPlugin.restore();
});
it("reports errored/missing modules",function(done) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {

View File

@ -123,7 +123,7 @@ describe('context', function() {
should.not.exist(context.get("foo"));
});
it.skip('enumerates context keys', function() {
it('enumerates context keys', function() {
var context = Context.get("1","flowA");
var keys = context.keys();
@ -168,6 +168,7 @@ describe('context', function() {
stubGet.reset();
stubSet.reset();
stubKeys.reset();
stubDelete.reset();
Context.clean({allNodes:{}});
fs.remove(testDir,done);
});
@ -418,7 +419,7 @@ describe('context', function() {
var result = parseKey(input);
result.storage.should.eql(expectedModule);
result.key.should.eql(expectedKey);
};
}
it('should return module and key', function() {
returnModuleAndKey("$test.aaa","test","aaa");

View File

@ -153,11 +153,9 @@ describe("red/util", function() {
var v = util.getMessageProperty({a:"foo"},"msg.b");
should.not.exist(v);
});
it('should throw error if property parent does not exist', function() {
/*jshint immed: false */
(function() {
util.getMessageProperty({a:"foo"},"msg.a.b.c");
}).should.throw();
it('should return undefined if property parent does not exist', function() {
var v = util.getMessageProperty({a:"foo"},"msg.a.b.c");
should.not.exist(v);
});
it('retrieves a property with array syntax', function() {
var v = util.getMessageProperty({a:["foo","bar"]},"msg.a[0]");