From 9f5e6a4b377da3c955bbee1da2db1085073bc5e0 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 12 Nov 2015 07:56:23 +0000 Subject: [PATCH] Update tests for runtime/api separation --- red/runtime/settings.js | 2 +- test/red/api/index_spec.js | 22 +++--- test/red/api/nodes_spec.js | 6 -- test/red/api/theme_spec.js | 1 - test/red/i18n_spec.js | 0 .../node_modules/ShouldNotLoad.html | 4 - .../NestedNode/node_modules/ShouldNotLoad.js | 5 -- .../node_modules/EmptyModule/file.txt | 1 - .../TestNodeModule/TestNodeModule.html | 5 -- .../TestNodeModule/TestNodeModule.js | 5 -- .../TestNodeModule/TestNodeModule2.html | 5 -- .../TestNodeModule/TestNodeModule2.js | 4 - .../TestNodeModule/icons/file.txt | 3 - .../node_modules/TestNodeModule/package.json | 11 --- test/red/red_spec.js | 24 +++--- test/red/{ => runtime}/comms_spec.js | 74 +++++++++---------- test/red/{ => runtime}/events_spec.js | 5 +- test/red/runtime/i18n_spec.js | 22 ++++++ .../index_spec.js} | 58 +++++++-------- test/red/{ => runtime}/log_spec.js | 14 ++-- test/red/{ => runtime}/nodes/Node_spec.js | 8 +- .../{ => runtime}/nodes/credentials_spec.js | 8 +- .../{ => runtime}/nodes/flows/Flow_spec.js | 10 +-- .../{ => runtime}/nodes/flows/index_spec.js | 14 ++-- .../{ => runtime}/nodes/flows/util_spec.js | 6 +- test/red/{ => runtime}/nodes/index_spec.js | 24 +++--- .../nodes/registry/deprecated_spec.js | 2 +- .../nodes/registry/index_spec.js | 66 ++++++++--------- .../nodes/registry/installer_spec.js | 6 +- .../nodes/registry/loader_spec.js | 0 .../nodes/registry/localfilesystem_spec.js | 0 .../nodes/registry/registry_spec.js | 2 +- .../DuplicateTestNode/TestNode1.html | 0 .../resources/DuplicateTestNode/TestNode1.js | 0 .../MultipleNodes1/MultipleNodes1.html | 0 .../MultipleNodes1/MultipleNodes1.js | 0 .../NestedNode/NestedNode.html | 0 .../NestedNode/NestedNode.js | 0 .../NestedNode/icons/file.txt | 0 .../NestedNode/lib/ShouldNotLoad.html | 0 .../NestedNode/lib/ShouldNotLoad.js | 0 .../NestedNode/test/ShouldNotLoad.html | 0 .../NestedNode/test/ShouldNotLoad.js | 0 .../nodes/resources/TestNode1/TestNode1.html | 0 .../nodes/resources/TestNode1/TestNode1.js | 0 .../nodes/resources/TestNode2/TestNode2.html | 0 .../nodes/resources/TestNode2/TestNode2.js | 0 .../nodes/resources/TestNode3/TestNode3.html | 0 .../nodes/resources/TestNode3/TestNode3.js | 0 test/red/{ => runtime}/settings_spec.js | 3 +- test/red/{ => runtime}/storage/index_spec.js | 54 +++++++------- .../storage/localfilesystem_spec.js | 54 +++++++------- test/red/{ => runtime}/util_spec.js | 2 +- 53 files changed, 246 insertions(+), 284 deletions(-) delete mode 100644 test/red/i18n_spec.js delete mode 100644 test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.html delete mode 100644 test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.js delete mode 100644 test/red/nodes/resources/TestNodeModule/node_modules/EmptyModule/file.txt delete mode 100644 test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.html delete mode 100644 test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.js delete mode 100644 test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.html delete mode 100644 test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.js delete mode 100644 test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/icons/file.txt delete mode 100644 test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/package.json rename test/red/{ => runtime}/comms_spec.js (97%) rename test/red/{ => runtime}/events_spec.js (83%) create mode 100644 test/red/runtime/i18n_spec.js rename test/red/{runtime_spec.js => runtime/index_spec.js} (88%) rename test/red/{ => runtime}/log_spec.js (97%) rename test/red/{ => runtime}/nodes/Node_spec.js (98%) rename test/red/{ => runtime}/nodes/credentials_spec.js (97%) rename test/red/{ => runtime}/nodes/flows/Flow_spec.js (99%) rename test/red/{ => runtime}/nodes/flows/index_spec.js (97%) rename test/red/{ => runtime}/nodes/flows/util_spec.js (99%) rename test/red/{ => runtime}/nodes/index_spec.js (91%) rename test/red/{ => runtime}/nodes/registry/deprecated_spec.js (91%) rename test/red/{ => runtime}/nodes/registry/index_spec.js (98%) rename test/red/{ => runtime}/nodes/registry/installer_spec.js (96%) rename test/red/{ => runtime}/nodes/registry/loader_spec.js (100%) rename test/red/{ => runtime}/nodes/registry/localfilesystem_spec.js (100%) rename test/red/{ => runtime}/nodes/registry/registry_spec.js (99%) rename test/red/{ => runtime}/nodes/resources/DuplicateTestNode/TestNode1.html (100%) rename test/red/{ => runtime}/nodes/resources/DuplicateTestNode/TestNode1.js (100%) rename test/red/{ => runtime}/nodes/resources/MultipleNodes1/MultipleNodes1.html (100%) rename test/red/{ => runtime}/nodes/resources/MultipleNodes1/MultipleNodes1.js (100%) rename test/red/{ => runtime}/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.html (100%) rename test/red/{ => runtime}/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.js (100%) rename test/red/{ => runtime}/nodes/resources/NestedDirectoryNode/NestedNode/icons/file.txt (100%) rename test/red/{ => runtime}/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.html (100%) rename test/red/{ => runtime}/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.js (100%) rename test/red/{ => runtime}/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.html (100%) rename test/red/{ => runtime}/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.js (100%) rename test/red/{ => runtime}/nodes/resources/TestNode1/TestNode1.html (100%) rename test/red/{ => runtime}/nodes/resources/TestNode1/TestNode1.js (100%) rename test/red/{ => runtime}/nodes/resources/TestNode2/TestNode2.html (100%) rename test/red/{ => runtime}/nodes/resources/TestNode2/TestNode2.js (100%) rename test/red/{ => runtime}/nodes/resources/TestNode3/TestNode3.html (100%) rename test/red/{ => runtime}/nodes/resources/TestNode3/TestNode3.js (100%) rename test/red/{ => runtime}/settings_spec.js (98%) rename test/red/{ => runtime}/storage/index_spec.js (95%) rename test/red/{ => runtime}/storage/localfilesystem_spec.js (98%) rename test/red/{ => runtime}/util_spec.js (98%) diff --git a/red/runtime/settings.js b/red/runtime/settings.js index 46d5d353f..a284c280c 100644 --- a/red/runtime/settings.js +++ b/red/runtime/settings.js @@ -28,7 +28,7 @@ var persistentSettings = { userSettings = settings; for (var i in settings) { /* istanbul ignore else */ - if (settings.hasOwnProperty(i)) { + if (settings.hasOwnProperty(i) && typeof settings[i] !== "function") { (function() { var j = i; persistentSettings.__defineGetter__(j,function() { return userSettings[j]; }); diff --git a/test/red/api/index_spec.js b/test/red/api/index_spec.js index d53633a4a..cf4ec02d6 100644 --- a/test/red/api/index_spec.js +++ b/test/red/api/index_spec.js @@ -28,13 +28,11 @@ describe("api index", function() { describe("disables editor", function() { before(function() { - app = express(); - api.init(app,{ - settings:{disableEditor:true}, - api:{ - - } + api.init({ + settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:true}, + events: {on:function(){},removeListener: function(){}} }); + app = api.adminApp(); }); it('does not serve the editor', function(done) { @@ -69,11 +67,11 @@ describe("api index", function() { }) }); before(function() { - app = express(); - api.init(app,{ - settings:{adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}}, + api.init({ + settings:{httpNodeRoot:true, httpAdminRoot: true, adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}}, storage:{getSessions:function(){return when.resolve({})}} }); + app = api.adminApp(); }); it('it now serves auth', function(done) { @@ -105,12 +103,12 @@ describe("api index", function() { }); before(function() { - app = express(); - api.init(app,{ + api.init({ log:{audit:function(){}}, - settings:{disableEditor:false}, + settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false}, events:{on:function(){},removeListener:function(){}} }); + app = api.adminApp(); }); it('serves the editor', function(done) { request(app) diff --git a/test/red/api/nodes_spec.js b/test/red/api/nodes_spec.js index 695d8b669..a04574449 100644 --- a/test/red/api/nodes_spec.js +++ b/test/red/api/nodes_spec.js @@ -21,8 +21,6 @@ var bodyParser = require('body-parser'); var sinon = require('sinon'); var when = require('when'); -var settings = require("../../../red/settings"); - var nodes = require("../../../red/api/nodes"); describe("nodes api", function() { @@ -335,9 +333,6 @@ describe("nodes api", function() { }); describe('delete', function() { it('returns 400 if settings are unavailable', function(done) { - var settingsAvailable = sinon.stub(settings,'available', function() { - return false; - }); initNodes({ settings:{available:function(){return false}} }); @@ -346,7 +341,6 @@ describe("nodes api", function() { .del('/nodes/123') .expect(400) .end(function(err,res) { - settingsAvailable.restore(); if (err) { throw err; } diff --git a/test/red/api/theme_spec.js b/test/red/api/theme_spec.js index 00d400965..b4b57fd22 100644 --- a/test/red/api/theme_spec.js +++ b/test/red/api/theme_spec.js @@ -22,7 +22,6 @@ var when = require('when'); var fs = require("fs"); var app = express(); -var settings = require("../../../red/settings"); var theme = require("../../../red/api/theme"); diff --git a/test/red/i18n_spec.js b/test/red/i18n_spec.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.html b/test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.html deleted file mode 100644 index eb7c8a3f9..000000000 --- a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.html +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.js b/test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.js deleted file mode 100644 index 623e299b2..000000000 --- a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.js +++ /dev/null @@ -1,5 +0,0 @@ -// A test node that exports a function -module.exports = function(RED) { - function TestNode(n) {} - RED.nodes.registerType("should-not-load-2",TestNode); -} diff --git a/test/red/nodes/resources/TestNodeModule/node_modules/EmptyModule/file.txt b/test/red/nodes/resources/TestNodeModule/node_modules/EmptyModule/file.txt deleted file mode 100644 index 0ce8dcaed..000000000 --- a/test/red/nodes/resources/TestNodeModule/node_modules/EmptyModule/file.txt +++ /dev/null @@ -1 +0,0 @@ -This file exists just to ensure the parent directory is in the repository. diff --git a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.html b/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.html deleted file mode 100644 index 17483f7ca..000000000 --- a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.html +++ /dev/null @@ -1,5 +0,0 @@ - - - - -

this should be filtered out

diff --git a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.js b/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.js deleted file mode 100644 index c79c2ceb6..000000000 --- a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule.js +++ /dev/null @@ -1,5 +0,0 @@ -// A test node that exports a function -module.exports = function(RED) { - function TestNode(n) {} - RED.nodes.registerType("test-node-mod-1",TestNode); -} diff --git a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.html b/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.html deleted file mode 100644 index a1f1b6c79..000000000 --- a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.html +++ /dev/null @@ -1,5 +0,0 @@ - - - - -

this should be filtered out

diff --git a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.js b/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.js deleted file mode 100644 index d359fb3f2..000000000 --- a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/TestNodeModule2.js +++ /dev/null @@ -1,4 +0,0 @@ -// A test node that exports a function -module.exports = function(RED) { - throw new Error("fail to load"); -} diff --git a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/icons/file.txt b/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/icons/file.txt deleted file mode 100644 index 59a29af14..000000000 --- a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/icons/file.txt +++ /dev/null @@ -1,3 +0,0 @@ -This file exists just to ensure the 'icons' directory is in the repository. -TODO: a future test needs to ensure the right icon files are loaded - this - directory can be used for that diff --git a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/package.json b/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/package.json deleted file mode 100644 index 8eba5b04b..000000000 --- a/test/red/nodes/resources/TestNodeModule/node_modules/TestNodeModule/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name" : "TestNodeModule", - "version" : "0.0.1", - "description" : "A test node module", - "node-red" : { - "nodes": { - "TestNodeMod1": "TestNodeModule.js", - "TestNodeMod2": "TestNodeModule2.js" - } - } -} diff --git a/test/red/red_spec.js b/test/red/red_spec.js index dcbf8a246..6aa939de4 100644 --- a/test/red/red_spec.js +++ b/test/red/red_spec.js @@ -19,30 +19,27 @@ var fs = require("fs"); var path = require("path"); var RED = require("../../red/red"); -var log = require("../../red/log"); -var settings = require("../../red/settings"); -var server = require("../../red/server"); +var runtime = require("../../red/runtime"); +var api = require("../../red/api"); describe("red/red", function() { describe("check build", function() { beforeEach(function() { - sinon.stub(log,"init",function() {}); - sinon.stub(settings,"init",function() {}); - sinon.stub(server,"init",function() {}); + sinon.stub(runtime,"init",function() {}); + sinon.stub(api,"init",function() {}); sinon.stub(RED,"version",function() { return "version";}); }); afterEach(function() { - log.init.restore(); - settings.init.restore(); - server.init.restore(); + runtime.init.restore(); + api.init.restore(); fs.statSync.restore(); RED.version.restore(); }); it('warns if build has not been run',function() { sinon.stub(fs,"statSync",function() { throw new Error();}); - + /*jshint immed: false */ (function() { RED.init({},{}); @@ -53,19 +50,22 @@ describe("red/red", function() { RED.init({},{}); }); }); - + describe("externals", function() { it('reports version', function() { var p = require(path.join(process.env.NODE_RED_HOME,"package.json")).version; RED.version().indexOf(p).should.eql(0); }); - it('access server externals', function() { + it.skip('access server externals', function() { // TODO: unstubable accessors - need to make this testable RED.app; RED.httpAdmin; RED.httpNode; RED.server; }); + it.skip('only initialises api component if httpAdmin enabled'); + it.skip('stubs httpAdmin if httpAdmin disabled'); + it.skip('stubs httpNode if httpNode disabled'); }); }); diff --git a/test/red/comms_spec.js b/test/red/runtime/comms_spec.js similarity index 97% rename from test/red/comms_spec.js rename to test/red/runtime/comms_spec.js index 2195f34d4..53aff1a41 100644 --- a/test/red/comms_spec.js +++ b/test/red/runtime/comms_spec.js @@ -23,14 +23,14 @@ var express = require('express'); var app = express(); var WebSocket = require('ws'); -var comms = require("../../red/comms.js"); -var Users = require("../../red/api/auth/users"); -var Tokens = require("../../red/api/auth/tokens"); +var comms = require("../../../red/runtime/comms"); +var Users = require("../../../red/api/auth/users"); +var Tokens = require("../../../red/api/auth/tokens"); var address = '127.0.0.1'; var listenPort = 0; // use ephemeral port -describe("comms", function() { +describe("runtime/comms", function() { describe("with default keepalive", function() { var server; var url; @@ -46,11 +46,11 @@ describe("comms", function() { done(); }); }); - + after(function() { comms.stop(); }); - + it('accepts connection', function(done) { var ws = new WebSocket(url); ws.on('open', function() { @@ -58,7 +58,7 @@ describe("comms", function() { done(); }); }); - + it('publishes message after subscription', function(done) { var ws = new WebSocket(url); ws.on('open', function() { @@ -71,7 +71,7 @@ describe("comms", function() { done(); }); }); - + it('publishes retained message for subscription', function(done) { comms.publish('topic2', 'bar', true); var ws = new WebSocket(url); @@ -84,7 +84,7 @@ describe("comms", function() { done(); }); }); - + it('retained message is deleted by non-retained message', function(done) { comms.publish('topic3', 'retained', true); comms.publish('topic3', 'non-retained'); @@ -99,7 +99,7 @@ describe("comms", function() { done(); }); }); - + it('malformed messages are ignored',function(done) { var ws = new WebSocket(url); ws.on('open', function() { @@ -114,11 +114,11 @@ describe("comms", function() { done(); }); }); - + // The following test currently fails due to minimum viable // implementation. More test should be written to test topic // matching once this one is passing - + if (0) { it('receives message on correct topic', function(done) { var ws = new WebSocket(url); @@ -150,11 +150,11 @@ describe("comms", function() { done(); }); }); - + after(function() { comms.stop(); }); - + it('rejects websocket connections',function(done) { var ws = new WebSocket(url); ws.on('open', function() { @@ -164,10 +164,10 @@ describe("comms", function() { ws.on('error', function() { done(); }); - + }); }); - + describe("non-default httpAdminRoot set: /adminPath", function() { var server; var url; @@ -183,11 +183,11 @@ describe("comms", function() { done(); }); }); - + after(function() { comms.stop(); }); - + it('accepts connections',function(done) { var ws = new WebSocket(url); ws.on('open', function() { @@ -197,10 +197,10 @@ describe("comms", function() { ws.on('error', function() { done(new Error("Socket connection failed")); }); - + }); }); - + describe("non-default httpAdminRoot set: /adminPath/", function() { var server; var url; @@ -216,11 +216,11 @@ describe("comms", function() { done(); }); }); - + after(function() { comms.stop(); }); - + it('accepts connections',function(done) { var ws = new WebSocket(url); ws.on('open', function() { @@ -230,10 +230,10 @@ describe("comms", function() { ws.on('error', function() { done(new Error("Socket connection failed")); }); - + }); }); - + describe("non-default httpAdminRoot set: adminPath", function() { var server; var url; @@ -249,11 +249,11 @@ describe("comms", function() { done(); }); }); - + after(function() { comms.stop(); }); - + it('accepts connections',function(done) { var ws = new WebSocket(url); ws.on('open', function() { @@ -263,10 +263,10 @@ describe("comms", function() { ws.on('error', function() { done(new Error("Socket connection failed")); }); - + }); }); - + describe("keep alives", function() { var server; var url; @@ -325,7 +325,7 @@ describe("comms", function() { }); }); }); - + describe('authentication required, no anonymous',function() { var server; var url; @@ -351,8 +351,8 @@ describe("comms", function() { return when.resolve(null); } }); - - + + server = http.createServer(function(req,res){app(req,res)}); comms.init(server, {adminAuth:{}}); server.listen(listenPort, address); @@ -369,7 +369,7 @@ describe("comms", function() { getToken.restore(); comms.stop(); }); - + it('prevents connections that do not authenticate',function(done) { var ws = new WebSocket(url); var count = 0; @@ -381,7 +381,7 @@ describe("comms", function() { done(); }); }); - + it('allows connections that do authenticate',function(done) { var ws = new WebSocket(url); var received = 0; @@ -399,7 +399,7 @@ describe("comms", function() { ws.close(); } }); - + ws.on('close', function() { try { received.should.equal(2); @@ -409,7 +409,7 @@ describe("comms", function() { } }); }); - + it('rejects connections for non-existant token',function(done) { var ws = new WebSocket(url); var received = 0; @@ -453,7 +453,7 @@ describe("comms", function() { getDefaultUser.restore(); comms.stop(); }); - + it('allows anonymous connections that do not authenticate',function(done) { var ws = new WebSocket(url); var count = 0; @@ -480,5 +480,5 @@ describe("comms", function() { }); }); - + }); diff --git a/test/red/events_spec.js b/test/red/runtime/events_spec.js similarity index 83% rename from test/red/events_spec.js rename to test/red/runtime/events_spec.js index 24759262b..b02717670 100644 --- a/test/red/events_spec.js +++ b/test/red/runtime/events_spec.js @@ -15,8 +15,9 @@ **/ var should = require("should"); -describe("red/events", function() { +describe("runtime/events", function() { it('can be required without errors', function() { - require("../../red/events"); + require("../../../red/runtime/events"); }); + it.skip('more tests needed', function(){}) }); diff --git a/test/red/runtime/i18n_spec.js b/test/red/runtime/i18n_spec.js new file mode 100644 index 000000000..600830dbc --- /dev/null +++ b/test/red/runtime/i18n_spec.js @@ -0,0 +1,22 @@ +/** + * Copyright 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +describe("runtime/i18n", function() { + it('can be required without errors', function() { + require("../../../red/runtime/i18n"); + }); + it.skip('more tests needed', function(){}) +}); diff --git a/test/red/runtime_spec.js b/test/red/runtime/index_spec.js similarity index 88% rename from test/red/runtime_spec.js rename to test/red/runtime/index_spec.js index 91d58bc89..17ad2ac14 100644 --- a/test/red/runtime_spec.js +++ b/test/red/runtime/index_spec.js @@ -16,16 +16,18 @@ var should = require("should"); var when = require("when"); var sinon = require("sinon"); +var path = require("path"); -var comms = require("../../red/comms"); -var redNodes = require("../../red/nodes"); -var api = require("../../red/api"); -var runtime = require("../../red/runtime"); -var storage = require("../../red/storage"); -var settings = require("../../red/settings"); -var log = require("../../red/log"); +var api = require("../../../red/api"); +var runtime = require("../../../red/runtime"); -describe("red/runtime", function() { +var comms = require("../../../red/runtime/comms"); +var redNodes = require("../../../red/runtime/nodes"); +var storage = require("../../../red/runtime/storage"); +var settings = require("../../../red/runtime/settings"); +var log = require("../../../red/runtime/log"); + +describe("runtime", function() { var commsMessages = []; var commsPublish; @@ -42,47 +44,39 @@ describe("red/runtime", function() { commsPublish = sinon.stub(comms,"publish", function(topic,msg,retained) { commsMessages.push({topic:topic,msg:msg,retained:retained}); }); + process.env.NODE_RED_HOME = path.resolve(path.join(__dirname,"..","..","..")) }); after(function() { commsPublish.restore(); + delete process.env.NODE_RED_HOME; }); describe("init", function() { - var commsInit; - var apiInit; beforeEach(function() { - commsInit = sinon.stub(comms,"init",function() {}); - apiInit = sinon.stub(api,"init",function() {}); + sinon.stub(log,"init",function() {}); + sinon.stub(settings,"init",function() {}); + sinon.stub(comms,"init",function() {}); }); afterEach(function() { - commsInit.restore(); - apiInit.restore(); + log.init.restore(); + settings.init.restore(); + comms.init.restore(); }) it("initialises components", function() { var dummyServer = {}; - runtime.init(dummyServer,{testSettings: true, httpAdminRoot:"/", load:function() { return when.resolve();}}); - commsInit.called.should.be.true; - apiInit.called.should.be.true; - - should.exist(runtime.app); - should.exist(runtime.nodeApp); - - runtime.server.should.equal(dummyServer); + runtime.init(dummyServer,{testSettings: true, httpAdminRoot:"/"}); + log.init.called.should.be.true; + settings.init.called.should.be.true; + comms.init.called.should.be.true; }); - it("doesn't init api if httpAdminRoot set to false",function() { - + it("returns version", function() { var dummyServer = {}; - runtime.init(dummyServer,{testSettings: true, httpAdminRoot:false, load:function() { return when.resolve();}}); - commsInit.called.should.be.true; - apiInit.called.should.be.false; + runtime.init(dummyServer,{testSettings: true, httpAdminRoot:"/"}); + /^\d+\.\d+\.\d+(-git)?$/.test(runtime.version()).should.be.true; - should.exist(runtime.app); - should.exist(runtime.nodeApp); - - runtime.server.should.equal(dummyServer); - }); + }) }); describe("start",function() { diff --git a/test/red/log_spec.js b/test/red/runtime/log_spec.js similarity index 97% rename from test/red/log_spec.js rename to test/red/runtime/log_spec.js index 08d6d4e3f..ac7bccd54 100644 --- a/test/red/log_spec.js +++ b/test/red/runtime/log_spec.js @@ -17,13 +17,9 @@ var should = require("should"); var sinon = require("sinon"); var util = require("util"); -var log = require("../../red/log"); - -describe("red/log", function() { - it('can be required without errors', function() { - require("../../red/log"); - }); +var log = require("../../../red/runtime/log"); +describe("runtime/log", function() { beforeEach(function () { var spy = sinon.stub(util, 'log', function(arg){}); var settings = {logging: { console: { level: 'metric', metrics: true } } }; @@ -48,12 +44,12 @@ describe("red/log", function() { var ret = log.debug("This is a debug"); sinon.assert.calledWithMatch(util.log,"[debug] This is a debug"); }); - + it('it can raise a info', function() { var ret = log.info("This is an info"); sinon.assert.calledWithMatch(util.log,"[info] This is an info"); }); - + it('it can raise a warn', function() { var ret = log.warn("This is a warn"); sinon.assert.calledWithMatch(util.log,"[warn] This is a warn"); @@ -95,7 +91,7 @@ describe("red/log", function() { util.log.calledOnce.should.be.true; util.log.firstCall.args[0].indexOf("[nodeType:nodeId]").should.not.equal(-1); }); - + it('ignores lower level messages and metrics', function() { var settings = {logging: { console: { level: 'warn', metrics: false } } }; log.init(settings); diff --git a/test/red/nodes/Node_spec.js b/test/red/runtime/nodes/Node_spec.js similarity index 98% rename from test/red/nodes/Node_spec.js rename to test/red/runtime/nodes/Node_spec.js index d66b52633..2cc35f9d5 100644 --- a/test/red/nodes/Node_spec.js +++ b/test/red/runtime/nodes/Node_spec.js @@ -16,10 +16,10 @@ var should = require("should"); var sinon = require('sinon'); -var RedNode = require("../../../red/nodes/Node"); -var Log = require("../../../red/log"); -var flows = require("../../../red/nodes/flows"); -var comms = require('../../../red/comms'); +var RedNode = require("../../../../red/runtime/nodes/Node"); +var Log = require("../../../../red/runtime/log"); +var flows = require("../../../../red/runtime/nodes/flows"); +var comms = require("../../../../red/runtime/comms"); describe('Node', function() { describe('#constructor',function() { diff --git a/test/red/nodes/credentials_spec.js b/test/red/runtime/nodes/credentials_spec.js similarity index 97% rename from test/red/nodes/credentials_spec.js rename to test/red/runtime/nodes/credentials_spec.js index d61d2b5cb..386940443 100644 --- a/test/red/nodes/credentials_spec.js +++ b/test/red/runtime/nodes/credentials_spec.js @@ -22,10 +22,10 @@ var util = require("util"); var express = require("express"); var request = require("supertest"); -var index = require("../../../red/nodes/index"); -var credentials = require("../../../red/nodes/credentials"); -var log = require("../../../red/log"); -var auth = require("../../../red/api/auth"); +var index = require("../../../../red/runtime/nodes/index"); +var credentials = require("../../../../red/runtime/nodes/credentials"); +var log = require("../../../../red/runtime/log"); +var auth = require("../../../../red/api/auth"); describe('Credentials', function() { diff --git a/test/red/nodes/flows/Flow_spec.js b/test/red/runtime/nodes/flows/Flow_spec.js similarity index 99% rename from test/red/nodes/flows/Flow_spec.js rename to test/red/runtime/nodes/flows/Flow_spec.js index 5fca9fea7..424ebc937 100644 --- a/test/red/nodes/flows/Flow_spec.js +++ b/test/red/runtime/nodes/flows/Flow_spec.js @@ -20,11 +20,11 @@ var sinon = require('sinon'); var clone = require('clone'); var util = require("util"); -var flowUtils = require("../../../../red/nodes/flows/util"); -var Flow = require("../../../../red/nodes/flows/Flow"); -var flows = require("../../../../red/nodes/flows"); -var Node = require("../../../../red/nodes/Node"); -var typeRegistry = require("../../../../red/nodes/registry"); +var flowUtils = require("../../../../../red/runtime/nodes/flows/util"); +var Flow = require("../../../../../red/runtime/nodes/flows/Flow"); +var flows = require("../../../../../red/runtime/nodes/flows"); +var Node = require("../../../../../red/runtime/nodes/Node"); +var typeRegistry = require("../../../../../red/runtime/nodes/registry"); describe('Flow', function() { diff --git a/test/red/nodes/flows/index_spec.js b/test/red/runtime/nodes/flows/index_spec.js similarity index 97% rename from test/red/nodes/flows/index_spec.js rename to test/red/runtime/nodes/flows/index_spec.js index 2cef048f3..57ee418da 100644 --- a/test/red/nodes/flows/index_spec.js +++ b/test/red/runtime/nodes/flows/index_spec.js @@ -18,13 +18,13 @@ var should = require("should"); var sinon = require("sinon"); var when = require("when"); var clone = require("clone"); -var flows = require("../../../../red/nodes/flows"); -var RedNode = require("../../../../red/nodes/Node"); -var RED = require("../../../../red/nodes"); -var events = require("../../../../red/events"); -var credentials = require("../../../../red/nodes/credentials"); -var typeRegistry = require("../../../../red/nodes/registry"); -var Flow = require("../../../../red/nodes/flows/Flow"); +var flows = require("../../../../../red/runtime/nodes/flows"); +var RedNode = require("../../../../../red/runtime/nodes/Node"); +var RED = require("../../../../../red/runtime/nodes"); +var events = require("../../../../../red/runtime/events"); +var credentials = require("../../../../../red/runtime/nodes/credentials"); +var typeRegistry = require("../../../../../red/runtime/nodes/registry"); +var Flow = require("../../../../../red/runtime/nodes/flows/Flow"); describe('flows/index', function() { diff --git a/test/red/nodes/flows/util_spec.js b/test/red/runtime/nodes/flows/util_spec.js similarity index 99% rename from test/red/nodes/flows/util_spec.js rename to test/red/runtime/nodes/flows/util_spec.js index 40341ce46..916a398a4 100644 --- a/test/red/nodes/flows/util_spec.js +++ b/test/red/runtime/nodes/flows/util_spec.js @@ -18,9 +18,9 @@ var should = require("should"); var sinon = require("sinon"); var when = require("when"); var clone = require("clone"); -var flowUtil = require("../../../../red/nodes/flows/util"); -var typeRegistry = require("../../../../red/nodes/registry"); -var redUtil = require("../../../../red/util"); +var flowUtil = require("../../../../../red/runtime/nodes/flows/util"); +var typeRegistry = require("../../../../../red/runtime/nodes/registry"); +var redUtil = require("../../../../../red/runtime/util"); describe('flows/util', function() { var getType; diff --git a/test/red/nodes/index_spec.js b/test/red/runtime/nodes/index_spec.js similarity index 91% rename from test/red/nodes/index_spec.js rename to test/red/runtime/nodes/index_spec.js index a6c349f14..a0437cfbc 100644 --- a/test/red/nodes/index_spec.js +++ b/test/red/runtime/nodes/index_spec.js @@ -20,16 +20,18 @@ var path = require('path'); var when = require("when"); var sinon = require('sinon'); -var index = require("../../../red/nodes/index"); -var flows = require("../../../red/nodes/flows"); -var registry = require("../../../red/nodes/registry"); +var index = require("../../../../red/runtime/nodes/index"); +var flows = require("../../../../red/runtime/nodes/flows"); +var registry = require("../../../../red/runtime/nodes/registry"); describe("red/nodes/index", function() { before(function() { sinon.stub(flows,"startFlows"); + process.env.NODE_RED_HOME = path.resolve(path.join(__dirname,"..","..","..","..")) }); after(function() { flows.startFlows.restore(); + delete process.env.NODE_RED_HOME; }); afterEach(function() { @@ -93,10 +95,10 @@ describe("red/nodes/index", function() { var http = require('http'); var express = require('express'); var app = express(); - var server = require("../../../red/server"); - var credentials = require("../../../red/nodes/credentials"); - var localfilesystem = require("../../../red/storage/localfilesystem"); - var RED = require("../../../red/red.js"); + var runtime = require("../../../../red/runtime"); + var credentials = require("../../../../red/runtime/nodes/credentials"); + var localfilesystem = require("../../../../red/runtime/storage/localfilesystem"); + var RED = require("../../../../red/red.js"); var userDir = path.join(__dirname,".testUserHome"); before(function(done) { @@ -114,7 +116,7 @@ describe("red/nodes/index", function() { }) ; RED.init(http.createServer(function(req,res){app(req,res)}), {userDir: userDir}); - server.start().then(function () { + runtime.start().then(function () { done(); }); }); @@ -123,7 +125,7 @@ describe("red/nodes/index", function() { after(function(done) { fs.remove(userDir,done); - server.stop(); + runtime.stop(); index.load.restore(); localfilesystem.getCredentials.restore(); }); @@ -142,7 +144,7 @@ describe("red/nodes/index", function() { }); describe('allows nodes to be added/removed/enabled/disabled from the registry', function() { - var registry = require("../../../red/nodes/registry"); + var registry = require("../../../../red/runtime/nodes/registry"); var randomNodeInfo = {id:"5678",types:["random"]}; beforeEach(function() { @@ -210,7 +212,7 @@ describe("red/nodes/index", function() { }); describe('allows modules to be removed from the registry', function() { - var registry = require("../../../red/nodes/registry"); + var registry = require("../../../../red/runtime/nodes/registry"); var randomNodeInfo = {id:"5678",types:["random"]}; var randomModuleInfo = { name:"random", diff --git a/test/red/nodes/registry/deprecated_spec.js b/test/red/runtime/nodes/registry/deprecated_spec.js similarity index 91% rename from test/red/nodes/registry/deprecated_spec.js rename to test/red/runtime/nodes/registry/deprecated_spec.js index 033260d9c..61aff9abb 100644 --- a/test/red/nodes/registry/deprecated_spec.js +++ b/test/red/runtime/nodes/registry/deprecated_spec.js @@ -16,7 +16,7 @@ var should = require("should"); -var deprecated = require("../../../../red/nodes/registry/deprecated.js"); +var deprecated = require("../../../../../red/runtime/nodes/registry/deprecated.js"); describe('deprecated', function() { it('should return info on a node',function() { diff --git a/test/red/nodes/registry/index_spec.js b/test/red/runtime/nodes/registry/index_spec.js similarity index 98% rename from test/red/nodes/registry/index_spec.js rename to test/red/runtime/nodes/registry/index_spec.js index 5db18b668..5bca76c00 100644 --- a/test/red/nodes/registry/index_spec.js +++ b/test/red/runtime/nodes/registry/index_spec.js @@ -19,10 +19,10 @@ var sinon = require("sinon"); var path = require("path"); var when = require("when"); -var RedNodes = require("../../../../red/nodes"); -var RedNode = require("../../../../red/nodes/Node"); -var typeRegistry = require("../../../../red/nodes/registry"); -var events = require("../../../../red/events"); +var RedNodes = require("../../../../../red/runtime/nodes"); +var RedNode = require("../../../../../red/runtime/nodes/Node"); +var typeRegistry = require("../../../../../red/runtime/nodes/registry"); +var events = require("../../../../../red/runtime/events"); afterEach(function() { typeRegistry.clear(); @@ -167,7 +167,7 @@ describe('red/nodes/registry/index', function() { resourcesDir + "NestedDirectoryNode" + path.sep + "NestedNode" + path.sep + "icons"); eventEmitSpy.secondCall.args[0].should.be.equal("node-locales-dir"); - + eventEmitSpy.thirdCall.args[0].should.be.equal("type-registered"); eventEmitSpy.thirdCall.args[1].should.be.equal("nested-node-1"); @@ -208,7 +208,7 @@ describe('red/nodes/registry/index', function() { var list = typeRegistry.getNodeList(); list.should.be.an.Array.and.have.lengthOf(1); - + /*jshint immed: false */ (function(){ typeRegistry.registerType("test-node-1",{}); @@ -219,7 +219,7 @@ describe('red/nodes/registry/index', function() { done(e); }); }); - + it('handles nodesDir as a string', function(done) { typeRegistry.init(stubSettings({ @@ -312,13 +312,13 @@ describe('red/nodes/registry/index', function() { Object.keys(moduleList).should.have.length(1); moduleList.should.have.a.property("node-red"); Object.keys(moduleList["node-red"].nodes).should.have.length(3); - + nodeList.should.be.Array.and.have.length(3); settingsSave.callCount.should.equal(1); settingsSave.firstCall.args[0].should.be.equal("nodes"); var savedList = settingsSave.firstCall.args[1]; - + moduleList['node-red'].nodes['TestNode1'].should.have.a.property("id","node-red/TestNode1"); moduleList['node-red'].nodes['TestNode1'].should.have.a.property("name","TestNode1"); moduleList['node-red'].nodes['TestNode1'].should.have.a.property("module","node-red"); @@ -336,7 +336,7 @@ describe('red/nodes/registry/index', function() { savedList['node-red'].nodes['TestNode1'].should.have.a.property("types",moduleList['node-red'].nodes['TestNode1'].types); savedList['node-red'].nodes['TestNode1'].should.not.have.a.property("config"); savedList['node-red'].nodes['TestNode1'].should.not.have.a.property("template"); - + done(); }).catch(function(e) { @@ -358,11 +358,11 @@ describe('red/nodes/registry/index', function() { list[0].should.have.property("types",["test-node-1"]); list[0].should.have.property("enabled",true); list[0].should.not.have.property("err"); - + var id = "node-red/TestNode1"; var type = "test-node-1"; - + var info = typeRegistry.getNodeInfo(id); info.should.have.property("loaded"); delete info.loaded; @@ -379,7 +379,7 @@ describe('red/nodes/registry/index', function() { }); }); - + it('returns null node info for unrecognised id', function(done) { typeRegistry.init(settings); typeRegistry.load(resourcesDir + "TestNode1",true).then(function() { @@ -483,10 +483,10 @@ describe('red/nodes/registry/index', function() { typeRegistry.addModule("TestNodeModule").then(function(modInfo) { var info = typeRegistry.getModuleInfo("TestNodeModule"); - + modInfo.should.eql(info); should.not.exist(typeRegistry.getModuleInfo("does-not-exist")); - + done(); }).catch(function(e) { done(e); @@ -551,15 +551,15 @@ describe('red/nodes/registry/index', function() { eventEmitSpy.callCount.should.equal(3); - + eventEmitSpy.firstCall.args[0].should.be.equal("node-locales-dir"); - + eventEmitSpy.secondCall.args[0].should.be.equal("node-icon-dir"); eventEmitSpy.secondCall.args[1].should.be.equal( resourcesDir + "TestNodeModule" + path.sep+ "node_modules" + path.sep + "TestNodeModule" + path.sep + "icons"); - + eventEmitSpy.thirdCall.args[0].should.be.equal("type-registered"); eventEmitSpy.thirdCall.args[1].should.be.equal("test-node-mod-1"); @@ -846,24 +846,24 @@ describe('red/nodes/registry/index', function() { typeRegistry.disableNode(list[0].id).then(function(info) { info.should.have.property("id",list[0].id); info.should.have.property("enabled",false); - + var list2 = typeRegistry.getNodeList(); list2.should.be.an.Array.and.have.lengthOf(1); list2[0].should.have.property("enabled",false); - + typeRegistry.getNodeConfigs().length.should.equal(0); - + typeRegistry.enableNode(list[0].id).then(function(info2) { info2.should.have.property("id",list[0].id); info2.should.have.property("enabled",true); - + var list3 = typeRegistry.getNodeList(); list3.should.be.an.Array.and.have.lengthOf(1); list3[0].should.have.property("enabled",true); - + var nodeConfig2 = typeRegistry.getNodeConfigs(); nodeConfig2.should.eql(nodeConfig); - + done(); }); }); @@ -891,25 +891,25 @@ describe('red/nodes/registry/index', function() { info.should.have.property("id",list[0].id); info.should.have.property("types",list[0].types); info.should.have.property("enabled",false); - + var list2 = typeRegistry.getNodeList(); list2.should.be.an.Array.and.have.lengthOf(1); list2[0].should.have.property("enabled",false); - + typeRegistry.getNodeConfigs().length.should.equal(0); - + typeRegistry.enableNode(list[0].types[0]).then(function(info2) { info2.should.have.property("id",list[0].id); info2.should.have.property("types",list[0].types); info2.should.have.property("enabled",true); - + var list3 = typeRegistry.getNodeList(); list3.should.be.an.Array.and.have.lengthOf(1); list3[0].should.have.property("enabled",true); - + var nodeConfig2 = typeRegistry.getNodeConfigs(); nodeConfig2.should.eql(nodeConfig); - + done(); }); }); @@ -939,10 +939,10 @@ describe('red/nodes/registry/index', function() { done(e); }); }); - + it("handles unavailable settings", function(done) { typeRegistry.init(settings); - + /*jshint immed: false */ (function() { typeRegistry.enableNode("123"); @@ -959,7 +959,7 @@ describe('red/nodes/registry/index', function() { (function() { typeRegistry.removeModule("123"); }).should.throw("Settings unavailable"); - + done(); }); }); diff --git a/test/red/nodes/registry/installer_spec.js b/test/red/runtime/nodes/registry/installer_spec.js similarity index 96% rename from test/red/nodes/registry/installer_spec.js rename to test/red/runtime/nodes/registry/installer_spec.js index 1e65cfa4a..ae68f8976 100644 --- a/test/red/nodes/registry/installer_spec.js +++ b/test/red/runtime/nodes/registry/installer_spec.js @@ -20,9 +20,9 @@ var when = require("when"); var path = require("path"); var child_process = require('child_process'); -var installer = require("../../../../red/nodes/registry/installer"); -var registry = require("../../../../red/nodes/registry/index"); -var typeRegistry = require("../../../../red/nodes/registry/registry"); +var installer = require("../../../../../red/runtime/nodes/registry/installer"); +var registry = require("../../../../../red/runtime/nodes/registry/index"); +var typeRegistry = require("../../../../../red/runtime/nodes/registry/registry"); describe('nodes/registry/installer', function() { diff --git a/test/red/nodes/registry/loader_spec.js b/test/red/runtime/nodes/registry/loader_spec.js similarity index 100% rename from test/red/nodes/registry/loader_spec.js rename to test/red/runtime/nodes/registry/loader_spec.js diff --git a/test/red/nodes/registry/localfilesystem_spec.js b/test/red/runtime/nodes/registry/localfilesystem_spec.js similarity index 100% rename from test/red/nodes/registry/localfilesystem_spec.js rename to test/red/runtime/nodes/registry/localfilesystem_spec.js diff --git a/test/red/nodes/registry/registry_spec.js b/test/red/runtime/nodes/registry/registry_spec.js similarity index 99% rename from test/red/nodes/registry/registry_spec.js rename to test/red/runtime/nodes/registry/registry_spec.js index 1669b54e4..0f0c019b0 100644 --- a/test/red/nodes/registry/registry_spec.js +++ b/test/red/runtime/nodes/registry/registry_spec.js @@ -18,7 +18,7 @@ var should = require("should"); var when = require("when"); var sinon = require("sinon"); -var typeRegistry = require("../../../../red/nodes/registry/registry"); +var typeRegistry = require("../../../../../red/runtime/nodes/registry/registry"); describe("red/nodes/registry/registry",function() { diff --git a/test/red/nodes/resources/DuplicateTestNode/TestNode1.html b/test/red/runtime/nodes/resources/DuplicateTestNode/TestNode1.html similarity index 100% rename from test/red/nodes/resources/DuplicateTestNode/TestNode1.html rename to test/red/runtime/nodes/resources/DuplicateTestNode/TestNode1.html diff --git a/test/red/nodes/resources/DuplicateTestNode/TestNode1.js b/test/red/runtime/nodes/resources/DuplicateTestNode/TestNode1.js similarity index 100% rename from test/red/nodes/resources/DuplicateTestNode/TestNode1.js rename to test/red/runtime/nodes/resources/DuplicateTestNode/TestNode1.js diff --git a/test/red/nodes/resources/MultipleNodes1/MultipleNodes1.html b/test/red/runtime/nodes/resources/MultipleNodes1/MultipleNodes1.html similarity index 100% rename from test/red/nodes/resources/MultipleNodes1/MultipleNodes1.html rename to test/red/runtime/nodes/resources/MultipleNodes1/MultipleNodes1.html diff --git a/test/red/nodes/resources/MultipleNodes1/MultipleNodes1.js b/test/red/runtime/nodes/resources/MultipleNodes1/MultipleNodes1.js similarity index 100% rename from test/red/nodes/resources/MultipleNodes1/MultipleNodes1.js rename to test/red/runtime/nodes/resources/MultipleNodes1/MultipleNodes1.js diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.html b/test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.html similarity index 100% rename from test/red/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.html rename to test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.html diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.js b/test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.js similarity index 100% rename from test/red/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.js rename to test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/NestedNode.js diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/icons/file.txt b/test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/icons/file.txt similarity index 100% rename from test/red/nodes/resources/NestedDirectoryNode/NestedNode/icons/file.txt rename to test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/icons/file.txt diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.html b/test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.html similarity index 100% rename from test/red/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.html rename to test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.html diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.js b/test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.js similarity index 100% rename from test/red/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.js rename to test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/lib/ShouldNotLoad.js diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.html b/test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.html similarity index 100% rename from test/red/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.html rename to test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.html diff --git a/test/red/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.js b/test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.js similarity index 100% rename from test/red/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.js rename to test/red/runtime/nodes/resources/NestedDirectoryNode/NestedNode/test/ShouldNotLoad.js diff --git a/test/red/nodes/resources/TestNode1/TestNode1.html b/test/red/runtime/nodes/resources/TestNode1/TestNode1.html similarity index 100% rename from test/red/nodes/resources/TestNode1/TestNode1.html rename to test/red/runtime/nodes/resources/TestNode1/TestNode1.html diff --git a/test/red/nodes/resources/TestNode1/TestNode1.js b/test/red/runtime/nodes/resources/TestNode1/TestNode1.js similarity index 100% rename from test/red/nodes/resources/TestNode1/TestNode1.js rename to test/red/runtime/nodes/resources/TestNode1/TestNode1.js diff --git a/test/red/nodes/resources/TestNode2/TestNode2.html b/test/red/runtime/nodes/resources/TestNode2/TestNode2.html similarity index 100% rename from test/red/nodes/resources/TestNode2/TestNode2.html rename to test/red/runtime/nodes/resources/TestNode2/TestNode2.html diff --git a/test/red/nodes/resources/TestNode2/TestNode2.js b/test/red/runtime/nodes/resources/TestNode2/TestNode2.js similarity index 100% rename from test/red/nodes/resources/TestNode2/TestNode2.js rename to test/red/runtime/nodes/resources/TestNode2/TestNode2.js diff --git a/test/red/nodes/resources/TestNode3/TestNode3.html b/test/red/runtime/nodes/resources/TestNode3/TestNode3.html similarity index 100% rename from test/red/nodes/resources/TestNode3/TestNode3.html rename to test/red/runtime/nodes/resources/TestNode3/TestNode3.html diff --git a/test/red/nodes/resources/TestNode3/TestNode3.js b/test/red/runtime/nodes/resources/TestNode3/TestNode3.js similarity index 100% rename from test/red/nodes/resources/TestNode3/TestNode3.js rename to test/red/runtime/nodes/resources/TestNode3/TestNode3.js diff --git a/test/red/settings_spec.js b/test/red/runtime/settings_spec.js similarity index 98% rename from test/red/settings_spec.js rename to test/red/runtime/settings_spec.js index bf1b05df5..933e39fa1 100644 --- a/test/red/settings_spec.js +++ b/test/red/runtime/settings_spec.js @@ -16,7 +16,7 @@ var should = require("should"); var when = require("when"); -var settings = require("../../red/settings"); +var settings = require("../../../red/runtime/settings"); describe("red/settings", function() { @@ -99,7 +99,6 @@ describe("red/settings", function() { (function() { settings.get("unknown"); }).should.throw(); - settings.load(storage).then(function() { settings.available().should.be.true; settings.get("globalA").should.equal(789); diff --git a/test/red/storage/index_spec.js b/test/red/runtime/storage/index_spec.js similarity index 95% rename from test/red/storage/index_spec.js rename to test/red/runtime/storage/index_spec.js index 2f05fd518..268c4ea57 100644 --- a/test/red/storage/index_spec.js +++ b/test/red/runtime/storage/index_spec.js @@ -15,21 +15,21 @@ **/ var when = require("when"); var should = require("should"); -var storage = require("../../../red/storage/index"); +var storage = require("../../../../red/runtime/storage/index"); describe("red/storage/index", function() { - + it('rejects the promise when settings suggest loading a bad module', function(done) { - + var wrongModule = { storageModule : "thisaintloading" }; - + storage.init(wrongModule).then( function() { var one = 1; var zero = 0; try { - zero.should.equal(one, "The initialization promise should never get resolved"); + zero.should.equal(one, "The initialization promise should never get resolved"); } catch(err) { done(err); } @@ -37,25 +37,25 @@ describe("red/storage/index", function() { done(); //successfully rejected promise }); }); - + it('non-string storage module', function(done) { var initSetsMeToTrue = false; - + var moduleWithBooleanSettingInit = { init : function() { initSetsMeToTrue = true; } }; - + var setsBooleanModule = { storageModule : moduleWithBooleanSettingInit }; - + storage.init(setsBooleanModule); initSetsMeToTrue.should.be.true; done(); }); - + it('respects storage interface', function() { var calledFlagGetFlows = false; var calledFlagGetCredentials = false; @@ -63,7 +63,7 @@ describe("red/storage/index", function() { var calledInit = false; var calledFlagGetSettings = false; var calledFlagGetSessions = false; - + var interfaceCheckerModule = { init : function (settings) { settings.should.be.an.Object; @@ -114,39 +114,39 @@ describe("red/storage/index", function() { body.should.be.true; } }; - + var moduleToLoad = { storageModule : interfaceCheckerModule }; - + storage.init(moduleToLoad); storage.getFlows(); storage.saveFlows(true); - storage.getCredentials(); + storage.getCredentials(); storage.saveCredentials(true); - storage.getSettings(); + storage.getSettings(); storage.saveSettings(true); - storage.getSessions(); + storage.getSessions(); storage.saveSessions(true); storage.getAllFlows(); storage.getFlow("name"); storage.saveFlow("name", true); storage.getLibraryEntry(true, "name"); storage.saveLibraryEntry(true, "name", true, true); - + calledInit.should.be.true; calledFlagGetFlows.should.be.true; calledFlagGetCredentials.should.be.true; calledFlagGetAllFlows.should.be.true; }); - + describe('respects deprecated flow library functions', function() { - + var savePath; var saveContent; var saveMeta; var saveType; - + var interfaceCheckerModule = { init : function (settings) { settings.should.be.an.Object; @@ -170,7 +170,7 @@ describe("red/storage/index", function() { return when.resolve(); } }; - + var moduleToLoad = { storageModule : interfaceCheckerModule }; @@ -187,7 +187,7 @@ describe("red/storage/index", function() { } }); }); - + it('getFlow',function(done) { storage.getFlow("/a/test2.json").then(function(res) { try { @@ -198,7 +198,7 @@ describe("red/storage/index", function() { } }); }); - + it ('saveFlow', function (done) { storage.saveFlow("/a/test2.json","new content").then(function(res) { try { @@ -211,10 +211,10 @@ describe("red/storage/index", function() { done(err); } }); - + }); }); - + describe('handles missing settings/sessions interface', function() { before(function() { var interfaceCheckerModule = { @@ -222,7 +222,7 @@ describe("red/storage/index", function() { }; storage.init({storageModule: interfaceCheckerModule}); }); - + it('defaults missing getSettings',function(done) { storage.getSettings().then(function(settings) { should.not.exist(settings); @@ -246,5 +246,5 @@ describe("red/storage/index", function() { }); }); }); - + }); diff --git a/test/red/storage/localfilesystem_spec.js b/test/red/runtime/storage/localfilesystem_spec.js similarity index 98% rename from test/red/storage/localfilesystem_spec.js rename to test/red/runtime/storage/localfilesystem_spec.js index d0cb1a272..c708a07b0 100644 --- a/test/red/storage/localfilesystem_spec.js +++ b/test/red/runtime/storage/localfilesystem_spec.js @@ -18,7 +18,7 @@ var should = require("should"); var fs = require('fs-extra'); var path = require('path'); -var localfilesystem = require("../../../red/storage/localfilesystem"); +var localfilesystem = require("../../../../red/runtime/storage/localfilesystem"); describe('LocalFileSystem', function() { var userDir = path.join(__dirname,".testUserHome"); @@ -41,8 +41,8 @@ describe('LocalFileSystem', function() { done(err); }); }); - - + + it('should set userDir to NRH is .config.json present',function(done) { var oldNRH = process.env.NODE_RED_HOME; process.env.NODE_RED_HOME = path.join(userDir,"NRH"); @@ -64,13 +64,13 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should set userDir to HOME/.node-red',function(done) { var oldNRH = process.env.NODE_RED_HOME; process.env.NODE_RED_HOME = path.join(userDir,"NRH"); var oldHOME = process.env.HOME; process.env.HOME = path.join(userDir,"HOME"); - + fs.mkdirSync(process.env.HOME); var settings = {}; localfilesystem.init(settings).then(function() { @@ -89,7 +89,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should handle missing flow file',function(done) { localfilesystem.init({userDir:userDir}).then(function() { var flowFile = 'flows_'+require('os').hostname()+'.json'; @@ -156,7 +156,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should format the flows file when flowFilePretty specified',function(done) { var flowFile = 'test.json'; var flowFilePath = path.join(userDir,flowFile); @@ -177,7 +177,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should backup the flows file', function(done) { var defaultFlowFile = 'flows_'+require('os').hostname()+'.json'; var defaultFlowFilePath = path.join(userDir,defaultFlowFile); @@ -196,7 +196,7 @@ describe('LocalFileSystem', function() { fs.existsSync(flowFilePath).should.be.true; var content = fs.readFileSync(flowFilePath,'utf8'); var testFlow2 = [{"type":"tab","id":"bc5672ad.2741d8","label":"Sheet 2"}]; - + localfilesystem.saveFlows(testFlow2).then(function() { fs.existsSync(flowFileBackupPath).should.be.true; fs.existsSync(defaultFlowFilePath).should.be.false; @@ -206,21 +206,21 @@ describe('LocalFileSystem', function() { var content2 = fs.readFileSync(flowFilePath,'utf8'); content2.should.not.equal(backupContent); done(); - + }).otherwise(function(err) { done(err); }); - + }).otherwise(function(err) { done(err); }); }).otherwise(function(err) { done(err); }); - - + + }); - + it('should handle missing credentials', function(done) { var flowFile = 'test.json'; var flowFilePath = path.join(userDir,flowFile); @@ -266,7 +266,7 @@ describe('LocalFileSystem', function() { }); }); - + it('should backup existing credentials', function(done) { var flowFile = 'test.json'; var flowFilePath = path.join(userDir,flowFile); @@ -276,7 +276,7 @@ describe('LocalFileSystem', function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { fs.writeFileSync(credFile,"{}","utf8"); - + fs.existsSync(credFile).should.be.true; fs.existsSync(credFileBackup).should.be.false; @@ -293,8 +293,8 @@ describe('LocalFileSystem', function() { done(err); }); }); - - + + it('should format the creds file when flowFilePretty specified',function(done) { var flowFile = 'test.json'; var flowFilePath = path.join(userDir,flowFile); @@ -323,7 +323,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should handle non-existent settings', function(done) { var settingsFile = path.join(userDir,".settings.json"); @@ -339,7 +339,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should handle corrupt settings', function(done) { var settingsFile = path.join(userDir,".config.json"); fs.writeFileSync(settingsFile,"[This is not json","utf8"); @@ -355,7 +355,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should handle settings', function(done) { var settingsFile = path.join(userDir,".config.json"); @@ -379,7 +379,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should handle non-existent sessions', function(done) { var sessionsFile = path.join(userDir,".sessions.json"); @@ -395,7 +395,7 @@ describe('LocalFileSystem', function() { done(err); }); }); - + it('should handle corrupt sessions', function(done) { var sessionsFile = path.join(userDir,".sessions.json"); fs.writeFileSync(sessionsFile,"[This is not json","utf8"); @@ -435,8 +435,8 @@ describe('LocalFileSystem', function() { done(err); }); }); - - + + it('should return an empty list of library objects',function(done) { localfilesystem.init({userDir:userDir}).then(function() { localfilesystem.getLibraryEntry('object','').then(function(flows) { @@ -513,9 +513,9 @@ describe('LocalFileSystem', function() { done(err); }); }); - + }); - + it('should return a library object',function(done) { localfilesystem.init({userDir:userDir}).then(function() { createObjectLibrary(); diff --git a/test/red/util_spec.js b/test/red/runtime/util_spec.js similarity index 98% rename from test/red/util_spec.js rename to test/red/runtime/util_spec.js index a512bcf18..09f3f5db6 100644 --- a/test/red/util_spec.js +++ b/test/red/runtime/util_spec.js @@ -14,7 +14,7 @@ * limitations under the License. **/ var should = require("should"); -var util = require("../../red/util"); +var util = require("../../../red/runtime/util"); describe("red/util", function() { describe('generateId', function() {