1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Update tests for runtime/api separation

This commit is contained in:
Nick O'Leary 2015-11-12 07:56:23 +00:00
parent f43738446e
commit 9f5e6a4b37
53 changed files with 246 additions and 284 deletions

View File

@ -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]; });

View File

@ -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)

View File

@ -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;
}

View File

@ -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");

View File

View File

@ -1,4 +0,0 @@
<script type="text/x-red" data-template-name="should-not-load-2"></script>
<script type="text/x-red" data-help-name="should-not-load-2"></script>
<script type="text/javascript">RED.nodes.registerType('should-not-load-2',{});</script>
<style></style>

View File

@ -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);
}

View File

@ -1 +0,0 @@
This file exists just to ensure the parent directory is in the repository.

View File

@ -1,5 +0,0 @@
<script type="text/x-red" data-template-name="test-node-mod-1"></script>
<script type="text/x-red" data-help-name="test-node-mod-1"></script>
<script type="text/javascript">RED.nodes.registerType('test-node-mod-1',{});</script>
<style></style>
<p>this should be filtered out</p>

View File

@ -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);
}

View File

@ -1,5 +0,0 @@
<script type="text/x-red" data-template-name="test-node-mod-2"></script>
<script type="text/x-red" data-help-name="test-node-mod-2"></script>
<script type="text/javascript">RED.nodes.registerType('test-node-mod-2',{});</script>
<style></style>
<p>this should be filtered out</p>

View File

@ -1,4 +0,0 @@
// A test node that exports a function
module.exports = function(RED) {
throw new Error("fail to load");
}

View File

@ -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

View File

@ -1,11 +0,0 @@
{
"name" : "TestNodeModule",
"version" : "0.0.1",
"description" : "A test node module",
"node-red" : {
"nodes": {
"TestNodeMod1": "TestNodeModule.js",
"TestNodeMod2": "TestNodeModule2.js"
}
}
}

View File

@ -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');
});
});

View File

@ -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() {
});
});
});

View File

@ -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(){})
});

View File

@ -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(){})
});

View File

@ -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() {

View File

@ -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);

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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;

View File

@ -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",

View File

@ -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() {

View File

@ -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();
});
});

View File

@ -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() {

View File

@ -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() {

View File

@ -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);

View File

@ -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() {
});
});
});
});

View File

@ -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();

View File

@ -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() {