mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
More tests for red, log, info and util.
This commit is contained in:
@@ -52,6 +52,7 @@ describe("info api", function() {
|
||||
}
|
||||
res.body.should.have.property("httpNodeRoot","testHttpNodeRoot");
|
||||
res.body.should.have.property("version","testVersion");
|
||||
res.body.should.have.property("paletteCategories",["red","blue","green"]);
|
||||
res.body.should.not.have.property("foo",123);
|
||||
done();
|
||||
});
|
||||
|
@@ -14,6 +14,8 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var util = require("util");
|
||||
|
||||
describe("red/log", function() {
|
||||
it('can be required without errors', function() {
|
||||
@@ -21,19 +23,33 @@ describe("red/log", function() {
|
||||
});
|
||||
|
||||
var log = require("../../red/log");
|
||||
var sett = {logging: { console: { level: 'metric', metrics: true } } }
|
||||
log.init(sett);
|
||||
|
||||
beforeEach(function () {
|
||||
var spy = sinon.spy(util, 'log');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
util.log.restore();
|
||||
});
|
||||
|
||||
it('it can raise an error', function() {
|
||||
var m = {level:20, msg:"This is an error", type:"test", id:"12345", name:"ERROR" };
|
||||
var ret = log.error(m);
|
||||
var ret = log.error("This is an error");
|
||||
sinon.assert.calledWithMatch(util.log,"");
|
||||
});
|
||||
|
||||
it('it can raise a trace', function() {
|
||||
var m = {level:60, msg:"This is a trace", type:"test", id:"12345", name:"TRACE" };
|
||||
var ret = log.trace(m);
|
||||
var ret = log.trace("This is a trace");
|
||||
sinon.assert.calledWithMatch(util.log,"");
|
||||
});
|
||||
|
||||
it('it can raise a debug', function() {
|
||||
var m = {level:50, msg:"This is a debug", type:"test", id:"12345", name:"DEBUG" };
|
||||
var ret = log.debug(m);
|
||||
var ret = log.debug("This is a debug");
|
||||
sinon.assert.calledWithMatch(util.log,"");
|
||||
});
|
||||
|
||||
it('it checks level of metrics', function() {
|
||||
log.metric().should.equal(true);
|
||||
});
|
||||
});
|
||||
|
@@ -24,22 +24,22 @@ describe("red/red", function() {
|
||||
|
||||
it('returns an app object', function() {
|
||||
var srv = RED.app.use("/test", function() { return "app"; });
|
||||
//srv.should.be.an.instanceOf(Object);
|
||||
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);
|
||||
srv.should.be.an.instanceOf(Object);
|
||||
});
|
||||
|
||||
it('returns an httpNode object', function() {
|
||||
var srv = RED.httpNode.use("/test", function() { return "Node"; });
|
||||
//srv.should.be.an.instanceOf(Object);
|
||||
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('domain', null);
|
||||
//srv.should.be.an.instanceOf(Object).and.have.property('timeout', 120000);
|
||||
});
|
||||
|
||||
|
@@ -17,6 +17,16 @@ var should = require("should");
|
||||
var util = require("../../red/util");
|
||||
|
||||
describe("red/util", function() {
|
||||
// only test for things not tested by overall grunt
|
||||
describe('compareObjects', function() {
|
||||
it('unequal arrays are unequal', function() {
|
||||
util.compareObjects(["a"],"a").should.equal(false);
|
||||
});
|
||||
it('unequal key lengths are unequal', function() {
|
||||
util.compareObjects({"a":1},{"a":1,"b":1}).should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ensureString', function() {
|
||||
it('strings are preserved', function() {
|
||||
util.ensureString('string').should.equal('string');
|
||||
@@ -66,35 +76,34 @@ describe("red/util", function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('cloneMessage', function() {
|
||||
it('clones a simple message', function() {
|
||||
var msg = {string:"hi",array:[1,2,3],object:{a:1,subobject:{b:2}}};
|
||||
|
||||
|
||||
var cloned = util.cloneMessage(msg);
|
||||
|
||||
|
||||
cloned.should.eql(msg);
|
||||
|
||||
|
||||
cloned.should.not.equal(msg);
|
||||
cloned.array.should.not.equal(msg.string);
|
||||
cloned.object.should.not.equal(msg.object);
|
||||
cloned.object.subobject.should.not.equal(msg.object.subobject);
|
||||
|
||||
|
||||
cloned.should.not.have.property("req");
|
||||
cloned.should.not.have.property("res");
|
||||
});
|
||||
it('does not clone http req/res properties', function() {
|
||||
var msg = {req:{a:1},res:{b:2}};
|
||||
|
||||
|
||||
var cloned = util.cloneMessage(msg);
|
||||
|
||||
|
||||
cloned.should.eql(msg);
|
||||
cloned.should.not.equal(msg);
|
||||
|
||||
|
||||
cloned.req.should.equal(msg.req);
|
||||
cloned.res.should.equal(msg.res);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user