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,24 +19,21 @@ 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();
});
@ -59,13 +56,16 @@ describe("red/red", 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;

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

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

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,7 +15,7 @@
**/
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() {

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

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