Adding an Object node to the sandbox of a function node

Permit the user of the sandbox to log using the Function Node.
Test provided and working.

Fix Display warning message in the debug log
Before they were displayed as error instead of warning
This commit is contained in:
Antoine Aflalo
2015-02-28 13:45:23 +02:00
parent 10b092a9a7
commit 0ed9f6cc4f
4 changed files with 96 additions and 3 deletions

View File

@@ -23,7 +23,7 @@ describe('function node', function() {
before(function(done) {
helper.startServer(done);
});
afterEach(function() {
helper.unload();
});
@@ -153,5 +153,73 @@ describe('function node', function() {
}
});
});
describe('Logger', function () {
it('should log an Info Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.log('test');"}];
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true;
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().INFO);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'function');
msg.should.have.property('msg', 'test');
done();
} catch (err) {
done(err);
}
});
});
it('should log a Warning Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.warn('test');"}];
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true;
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().WARN);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'function');
msg.should.have.property('msg', 'test');
done();
} catch (err) {
done(err);
}
});
});
it('should log an Error Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.error('test');"}];
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
try {
helper.log().called.should.be.true;
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "function";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().ERROR);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'function');
msg.should.have.property('msg', 'test');
done();
} catch (err) {
done(err);
}
});
});
});
});