mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Move away from __defineGetter syntax, in red and server
Bump test coverage forwards a bit
This commit is contained in:
parent
3cbc1bbb1b
commit
234abd82a2
26
red/red.js
26
red/red.js
@ -24,15 +24,12 @@ var fs = require("fs");
|
|||||||
var settings = require("./settings");
|
var settings = require("./settings");
|
||||||
var credentials = require("./nodes/credentials");
|
var credentials = require("./nodes/credentials");
|
||||||
var auth = require("./api/auth");
|
var auth = require("./api/auth");
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
var events = require("events");
|
||||||
|
|
||||||
process.env.NODE_RED_HOME = process.env.NODE_RED_HOME || path.resolve(__dirname+"/..");
|
process.env.NODE_RED_HOME = process.env.NODE_RED_HOME || path.resolve(__dirname+"/..");
|
||||||
|
|
||||||
var events = require("events");
|
|
||||||
|
|
||||||
var RED = {
|
var RED = {
|
||||||
|
|
||||||
init: function(httpServer,userSettings) {
|
init: function(httpServer,userSettings) {
|
||||||
userSettings.version = this.version();
|
userSettings.version = this.version();
|
||||||
log.init(userSettings);
|
log.init(userSettings);
|
||||||
@ -40,7 +37,6 @@ var RED = {
|
|||||||
server.init(httpServer,settings);
|
server.init(httpServer,settings);
|
||||||
return server.app;
|
return server.app;
|
||||||
},
|
},
|
||||||
|
|
||||||
start: server.start,
|
start: server.start,
|
||||||
stop: server.stop,
|
stop: server.stop,
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
@ -55,18 +51,16 @@ var RED = {
|
|||||||
needsPermission: auth.needsPermission
|
needsPermission: auth.needsPermission
|
||||||
},
|
},
|
||||||
version: function () {
|
version: function () {
|
||||||
var p = require(path.join(process.env.NODE_RED_HOME,"package.json"));
|
var p = require(path.join(process.env.NODE_RED_HOME,"package.json")).version;
|
||||||
|
/* istanbul ignore else */
|
||||||
if (fs.existsSync(path.join(process.env.NODE_RED_HOME,".git"))) {
|
if (fs.existsSync(path.join(process.env.NODE_RED_HOME,".git"))) {
|
||||||
return p.version+".git";
|
p += ".git";
|
||||||
} else {
|
|
||||||
return p.version;
|
|
||||||
}
|
}
|
||||||
}
|
return p;
|
||||||
|
},
|
||||||
|
get app() { console.log("Deprecated use of RED.app - use RED.httpAdmin instead"); return server.app },
|
||||||
|
get httpAdmin() { return server.app },
|
||||||
|
get httpNode() { return server.nodeApp },
|
||||||
|
get server() { return server.server }
|
||||||
};
|
};
|
||||||
|
|
||||||
RED.__defineGetter__("app", function() { console.log("Deprecated use of RED.app - use RED.httpAdmin instead"); return server.app });
|
|
||||||
RED.__defineGetter__("httpAdmin", function() { return server.app });
|
|
||||||
RED.__defineGetter__("httpNode", function() { return server.nodeApp });
|
|
||||||
RED.__defineGetter__("server", function() { return server.server });
|
|
||||||
|
|
||||||
module.exports = RED;
|
module.exports = RED;
|
||||||
|
@ -197,10 +197,10 @@ function uninstallModule(module) {
|
|||||||
if (!fs.existsSync(moduleDir)) {
|
if (!fs.existsSync(moduleDir)) {
|
||||||
return reject(new Error("Unabled to uninstall "+module+"."));
|
return reject(new Error("Unabled to uninstall "+module+"."));
|
||||||
}
|
}
|
||||||
|
|
||||||
var list = redNodes.removeModule(module);
|
var list = redNodes.removeModule(module);
|
||||||
log.info("Removing module: "+module);
|
log.info("Removing module: "+module);
|
||||||
var child = child_process.exec('npm remove '+module,
|
var child = child_process.exec('npm remove '+module,
|
||||||
{
|
{
|
||||||
cwd: installDir
|
cwd: installDir
|
||||||
},
|
},
|
||||||
@ -223,27 +223,25 @@ function uninstallModule(module) {
|
|||||||
|
|
||||||
function reportMetrics() {
|
function reportMetrics() {
|
||||||
var memUsage = process.memoryUsage();
|
var memUsage = process.memoryUsage();
|
||||||
|
|
||||||
// only need to init these once per report
|
// only need to init these once per report
|
||||||
var metrics = {};
|
var metrics = {};
|
||||||
metrics.level = log.METRIC;
|
metrics.level = log.METRIC;
|
||||||
|
|
||||||
//report it
|
//report it
|
||||||
metrics.event = "runtime.memory.rss"
|
metrics.event = "runtime.memory.rss"
|
||||||
metrics.value = memUsage.rss;
|
metrics.value = memUsage.rss;
|
||||||
log.log(metrics);
|
log.log(metrics);
|
||||||
|
|
||||||
metrics.event = "runtime.memory.heapTotal"
|
metrics.event = "runtime.memory.heapTotal"
|
||||||
metrics.value = memUsage.heapTotal;
|
metrics.value = memUsage.heapTotal;
|
||||||
log.log(metrics);
|
log.log(metrics);
|
||||||
|
|
||||||
metrics.event = "runtime.memory.heapUsed"
|
metrics.event = "runtime.memory.heapUsed"
|
||||||
metrics.value = memUsage.heapUsed;
|
metrics.value = memUsage.heapUsed;
|
||||||
log.log(metrics);
|
log.log(metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function stop() {
|
function stop() {
|
||||||
if (runtimeMetricInterval) {
|
if (runtimeMetricInterval) {
|
||||||
clearInterval(runtimeMetricInterval);
|
clearInterval(runtimeMetricInterval);
|
||||||
@ -261,9 +259,9 @@ module.exports = {
|
|||||||
reportAddedModules: reportAddedModules,
|
reportAddedModules: reportAddedModules,
|
||||||
reportRemovedModules: reportRemovedModules,
|
reportRemovedModules: reportRemovedModules,
|
||||||
installModule: installModule,
|
installModule: installModule,
|
||||||
uninstallModule: uninstallModule
|
uninstallModule: uninstallModule,
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.__defineGetter__("app", function() { return app });
|
get app() { return app },
|
||||||
module.exports.__defineGetter__("nodeApp", function() { return nodeApp });
|
get nodeApp() { return nodeApp },
|
||||||
module.exports.__defineGetter__("server", function() { return server });
|
get server() { return server }
|
||||||
|
}
|
||||||
|
@ -17,6 +17,30 @@ var should = require("should");
|
|||||||
|
|
||||||
describe("red/red", function() {
|
describe("red/red", function() {
|
||||||
it('can be required without errors', function() {
|
it('can be required without errors', function() {
|
||||||
require("../../red/red");
|
var RED = require("../../red/red");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var RED = require("../../red/red");
|
||||||
|
|
||||||
|
it('returns an app object', function() {
|
||||||
|
var srv = RED.app.use("/test", function() { return "app"; });
|
||||||
|
srv.should.be.an.instanceOf(Object);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an httpAdmin object', function() {
|
||||||
|
var srv = RED.httpAdmin.use("/test", function() { return "Admin"; });
|
||||||
|
srv.should.be.an.instanceOf(Object);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reuturns an httpNode object', function() {
|
||||||
|
var srv = RED.httpNode.use("/test", function() { return "Node"; });
|
||||||
|
srv.should.be.an.instanceOf(Object);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it returns a server object', function() {
|
||||||
|
var srv = RED.server;
|
||||||
|
srv.should.be.an.instanceOf(Object).and.have.property('domain', null);
|
||||||
|
srv.should.be.an.instanceOf(Object).and.have.property('timeout', 120000);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user