From 0be9c88106d3665ea82fe9ace2e0237d16281ade Mon Sep 17 00:00:00 2001 From: Hiroki Uchikawa Date: Mon, 23 Apr 2018 10:45:30 +0900 Subject: [PATCH] Improve processing when default is an alias and fix test cases --- red/runtime/nodes/context/index.js | 10 +++++----- test/red/runtime/index_spec.js | 3 +++ test/red/runtime/nodes/context/index_spec.js | 5 +++-- test/red/runtime/util_spec.js | 8 +++----- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/red/runtime/nodes/context/index.js b/red/runtime/nodes/context/index.js index 31721e659..a0821531e 100644 --- a/red/runtime/nodes/context/index.js +++ b/red/runtime/nodes/context/index.js @@ -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"]})); } diff --git a/test/red/runtime/index_spec.js b/test/red/runtime/index_spec.js index 4e30c1e8a..d67c12ee1 100644 --- a/test/red/runtime/index_spec.js +++ b/test/red/runtime/index_spec.js @@ -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) { diff --git a/test/red/runtime/nodes/context/index_spec.js b/test/red/runtime/nodes/context/index_spec.js index bc9e6aff6..33fbd79b8 100644 --- a/test/red/runtime/nodes/context/index_spec.js +++ b/test/red/runtime/nodes/context/index_spec.js @@ -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"); diff --git a/test/red/runtime/util_spec.js b/test/red/runtime/util_spec.js index 1b7438efd..c3e797d26 100644 --- a/test/red/runtime/util_spec.js +++ b/test/red/runtime/util_spec.js @@ -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]");