mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Remove known unused files
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
describe("node-red/red", function() {
|
||||
it.skip("NEEDS TESTS WRITING",function() {});
|
||||
});
|
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
var should = require("should");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
describe("@node-red/util/events", function() {
|
||||
it('can be required without errors', function() {
|
||||
NR_TEST_UTILS.require("@node-red/util/lib/events");
|
||||
});
|
||||
it.skip('more tests needed', function(){})
|
||||
});
|
@@ -1,140 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var EventEmitter = require("events").EventEmitter;
|
||||
|
||||
|
||||
var child_process = require('child_process');
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var events = NR_TEST_UTILS.require("@node-red/util/lib/events");
|
||||
var exec = NR_TEST_UTILS.require("@node-red/util/lib/exec");
|
||||
|
||||
describe("runtime/exec", function() {
|
||||
var logEvents;
|
||||
var mockProcess;
|
||||
const eventLogHandler = function(ev) {
|
||||
logEvents.push(ev);
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
|
||||
logEvents = [];
|
||||
events.on("event-log", eventLogHandler);
|
||||
|
||||
mockProcess = new EventEmitter();
|
||||
mockProcess.stdout = new EventEmitter();
|
||||
mockProcess.stderr = new EventEmitter();
|
||||
sinon.stub(child_process,'spawn').callsFake(function(command,args,options) {
|
||||
mockProcess._args = {command,args,options};
|
||||
return mockProcess;
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
events.removeListener("event-log", eventLogHandler);
|
||||
if (child_process.spawn.restore) {
|
||||
child_process.spawn.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("runs command and resolves on success - no emit", function(done) {
|
||||
var command = "cmd";
|
||||
var args = [1,2,3];
|
||||
var opts = { a: true };
|
||||
exec.run(command,args,opts).then(function(result) {
|
||||
command.should.eql(mockProcess._args.command);
|
||||
args.should.eql(mockProcess._args.args);
|
||||
opts.should.eql(mockProcess._args.options);
|
||||
logEvents.length.should.eql(0);
|
||||
result.code.should.eql(0);
|
||||
result.stdout.should.eql("123");
|
||||
result.stderr.should.eql("abc");
|
||||
done();
|
||||
}).catch(done);
|
||||
|
||||
mockProcess.stdout.emit('data',"1");
|
||||
mockProcess.stderr.emit('data',"a");
|
||||
mockProcess.stderr.emit('data',"b");
|
||||
mockProcess.stdout.emit('data',"2");
|
||||
mockProcess.stdout.emit('data',"3");
|
||||
mockProcess.stderr.emit('data',"c");
|
||||
mockProcess.emit('close',0);
|
||||
});
|
||||
|
||||
it("runs command and resolves on success - emit", function(done) {
|
||||
var command = "cmd";
|
||||
var args = [1,2,3];
|
||||
var opts = { a: true };
|
||||
exec.run(command,args,opts,true).then(function(result) {
|
||||
logEvents.length.should.eql(8);
|
||||
done();
|
||||
}).catch(done);
|
||||
|
||||
mockProcess.stdout.emit('data',"1");
|
||||
mockProcess.stderr.emit('data',"a");
|
||||
mockProcess.stderr.emit('data',"b");
|
||||
mockProcess.stdout.emit('data',"2");
|
||||
mockProcess.stdout.emit('data',"3");
|
||||
mockProcess.stderr.emit('data',"c");
|
||||
mockProcess.emit('close',0);
|
||||
})
|
||||
|
||||
it("runs command and rejects on error - close", function(done) {
|
||||
var command = "cmd";
|
||||
var args = [1,2,3];
|
||||
var opts = { a: true };
|
||||
exec.run(command,args,opts).then(function() {
|
||||
done("Command should have rejected");
|
||||
}).catch(function(result) {
|
||||
result
|
||||
result.code.should.eql(123);
|
||||
result.stdout.should.eql("123");
|
||||
result.stderr.should.eql("abc");
|
||||
done();
|
||||
}).catch(done);
|
||||
|
||||
mockProcess.stdout.emit('data',"1");
|
||||
mockProcess.stderr.emit('data',"a");
|
||||
mockProcess.stderr.emit('data',"b");
|
||||
mockProcess.stdout.emit('data',"2");
|
||||
mockProcess.stdout.emit('data',"3");
|
||||
mockProcess.stderr.emit('data',"c");
|
||||
mockProcess.emit('close',123);
|
||||
})
|
||||
|
||||
it("runs command and rejects on error - error", function(done) {
|
||||
var command = "cmd";
|
||||
var args = [1,2,3];
|
||||
var opts = { a: true };
|
||||
exec.run(command,args,opts).then(function() {
|
||||
done("Command should have rejected");
|
||||
}).catch(function(result) {
|
||||
result
|
||||
result.code.should.eql(456);
|
||||
result.stdout.should.eql("");
|
||||
result.stderr.should.eql("test-error");
|
||||
done();
|
||||
}).catch(done);
|
||||
|
||||
mockProcess.emit('error',"test-error");
|
||||
mockProcess.emit('close',456);
|
||||
})
|
||||
|
||||
});
|
@@ -1,338 +0,0 @@
|
||||
const should = require("should");
|
||||
const NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
const hooks = NR_TEST_UTILS.require("@node-red/util/lib/hooks");
|
||||
|
||||
describe("util/hooks", function() {
|
||||
afterEach(function() {
|
||||
hooks.clear();
|
||||
})
|
||||
it("allows a hook to be registered", function(done) {
|
||||
let calledWith = null;
|
||||
hooks.has("onSend").should.be.false();
|
||||
hooks.add("onSend", function(payload) { calledWith = payload } )
|
||||
hooks.has("onSend").should.be.true();
|
||||
let data = { a: 1 };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
calledWith.should.equal(data);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
it("rejects invalid hook id", function(done) {
|
||||
try {
|
||||
hooks.add("foo", function(payload) {})
|
||||
done(new Error("Invalid hook accepted"))
|
||||
} catch(err) {
|
||||
done();
|
||||
}
|
||||
})
|
||||
it("calls hooks in the order they were registered", function(done) {
|
||||
hooks.add("onSend", function(payload) { payload.order.push("A") } )
|
||||
hooks.add("onSend", function(payload) { payload.order.push("B") } )
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A","B"])
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
|
||||
it("does not allow multiple hooks with same id.label", function() {
|
||||
hooks.has("onSend.one").should.be.false();
|
||||
hooks.has("onSend").should.be.false();
|
||||
hooks.add("onSend.one", function(payload) { payload.order.push("A") } );
|
||||
hooks.has("onSend.one").should.be.true();
|
||||
hooks.has("onSend").should.be.true();
|
||||
(function() {
|
||||
hooks.add("onSend.one", function(payload) { payload.order.push("B") } )
|
||||
}).should.throw();
|
||||
})
|
||||
|
||||
it("removes labelled hook", function(done) {
|
||||
hooks.has("onSend.A").should.be.false();
|
||||
hooks.has("onSend.B").should.be.false();
|
||||
hooks.has("onSend").should.be.false();
|
||||
|
||||
hooks.add("onSend.A", function(payload) { payload.order.push("A") } )
|
||||
|
||||
hooks.has("onSend.A").should.be.true();
|
||||
hooks.has("onSend.B").should.be.false();
|
||||
hooks.has("onSend").should.be.true();
|
||||
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
hooks.has("onSend.A").should.be.true();
|
||||
hooks.has("onSend.B").should.be.true();
|
||||
hooks.has("onSend").should.be.true();
|
||||
|
||||
hooks.remove("onSend.A");
|
||||
|
||||
hooks.has("onSend.A").should.be.false();
|
||||
hooks.has("onSend.B").should.be.true();
|
||||
hooks.has("onSend").should.be.true();
|
||||
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
try {
|
||||
data.order.should.eql(["B"])
|
||||
|
||||
hooks.remove("onSend.B");
|
||||
|
||||
hooks.has("onSend.A").should.be.false();
|
||||
hooks.has("onSend.B").should.be.false();
|
||||
hooks.has("onSend").should.be.false();
|
||||
|
||||
done(err);
|
||||
} catch(err2) {
|
||||
done(err2);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("cannot remove unlabelled hook", function() {
|
||||
hooks.add("onSend", function(payload) { payload.order.push("A") } );
|
||||
(function() {
|
||||
hooks.remove("onSend")
|
||||
}).should.throw();
|
||||
})
|
||||
it("removes all hooks with same label", function(done) {
|
||||
hooks.add("onSend.A", function(payload) { payload.order.push("A") } )
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
hooks.add("preRoute.A", function(payload) { payload.order.push("C") } )
|
||||
hooks.add("preRoute.B", function(payload) { payload.order.push("D") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A","B"])
|
||||
hooks.trigger("preRoute", data, err => {
|
||||
data.order.should.eql(["A","B","C","D"])
|
||||
|
||||
data.order = [];
|
||||
|
||||
hooks.remove("*.A");
|
||||
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["B"])
|
||||
hooks.trigger("preRoute", data, err => {
|
||||
data.order.should.eql(["B","D"])
|
||||
})
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
it("allows a hook to remove itself whilst being called", function(done) {
|
||||
let data = { order: [] }
|
||||
hooks.add("onSend.A", function(payload) { payload.order.push("A") } )
|
||||
hooks.add("onSend.B", function(payload) {
|
||||
hooks.remove("*.B");
|
||||
})
|
||||
hooks.add("onSend.C", function(payload) { payload.order.push("C") } )
|
||||
hooks.add("onSend.D", function(payload) { payload.order.push("D") } )
|
||||
|
||||
hooks.trigger("onSend", data, err => {
|
||||
try {
|
||||
should.not.exist(err);
|
||||
data.order.should.eql(["A","C","D"])
|
||||
done();
|
||||
} catch(e) {
|
||||
done(e);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it("allows a hook to remove itself and others whilst being called", function(done) {
|
||||
let data = { order: [] }
|
||||
hooks.add("onSend.A", function(payload) { payload.order.push("A") } )
|
||||
hooks.add("onSend.B", function(payload) {
|
||||
hooks.remove("*.B");
|
||||
hooks.remove("*.C");
|
||||
})
|
||||
hooks.add("onSend.C", function(payload) { payload.order.push("C") } )
|
||||
hooks.add("onSend.D", function(payload) { payload.order.push("D") } )
|
||||
|
||||
hooks.trigger("onSend", data, err => {
|
||||
try {
|
||||
should.not.exist(err);
|
||||
data.order.should.eql(["A","D"])
|
||||
done();
|
||||
} catch(e) {
|
||||
done(e);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it("halts execution on return false", function(done) {
|
||||
hooks.add("onSend.A", function(payload) { payload.order.push("A"); return false } )
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A"])
|
||||
err.should.be.false();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it("halts execution on thrown error", function(done) {
|
||||
hooks.add("onSend.A", function(payload) { payload.order.push("A"); throw new Error("error") } )
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A"])
|
||||
should.exist(err);
|
||||
err.should.not.be.false()
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
it("handler can use callback function", function(done) {
|
||||
hooks.add("onSend.A", function(payload, done) {
|
||||
setTimeout(function() {
|
||||
payload.order.push("A")
|
||||
done()
|
||||
},30)
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A","B"])
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
|
||||
it("handler can use callback function - halt execution", function(done) {
|
||||
hooks.add("onSend.A", function(payload, done) {
|
||||
setTimeout(function() {
|
||||
payload.order.push("A")
|
||||
done(false)
|
||||
},30)
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A"])
|
||||
err.should.be.false()
|
||||
done();
|
||||
})
|
||||
})
|
||||
it("handler can use callback function - halt on error", function(done) {
|
||||
hooks.add("onSend.A", function(payload, done) {
|
||||
setTimeout(function() {
|
||||
done(new Error("test error"))
|
||||
},30)
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql([])
|
||||
should.exist(err);
|
||||
err.should.not.be.false()
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
it("handler be an async function", function(done) {
|
||||
hooks.add("onSend.A", async function(payload) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(function() {
|
||||
payload.order.push("A")
|
||||
resolve()
|
||||
},30)
|
||||
});
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A","B"])
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
|
||||
it("handler be an async function - halt execution", function(done) {
|
||||
hooks.add("onSend.A", async function(payload) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(function() {
|
||||
payload.order.push("A")
|
||||
resolve(false)
|
||||
},30)
|
||||
});
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql(["A"])
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
it("handler be an async function - halt on error", function(done) {
|
||||
hooks.add("onSend.A", async function(payload) {
|
||||
return new Promise((resolve,reject) => {
|
||||
setTimeout(function() {
|
||||
reject(new Error("test error"))
|
||||
},30)
|
||||
});
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data,err => {
|
||||
data.order.should.eql([])
|
||||
should.exist(err);
|
||||
err.should.not.be.false()
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it("handler can use callback function - promise API", function(done) {
|
||||
hooks.add("onSend.A", function(payload, done) {
|
||||
setTimeout(function() {
|
||||
payload.order.push("A")
|
||||
done()
|
||||
},30)
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data).then(() => {
|
||||
data.order.should.eql(["A","B"])
|
||||
done()
|
||||
}).catch(done)
|
||||
})
|
||||
|
||||
it("handler can halt execution - promise API", function(done) {
|
||||
hooks.add("onSend.A", function(payload, done) {
|
||||
setTimeout(function() {
|
||||
payload.order.push("A")
|
||||
done(false)
|
||||
},30)
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data).then(() => {
|
||||
data.order.should.eql(["A"])
|
||||
done()
|
||||
}).catch(done)
|
||||
})
|
||||
|
||||
it("handler can halt execution on error - promise API", function(done) {
|
||||
hooks.add("onSend.A", function(payload, done) {
|
||||
throw new Error("error");
|
||||
})
|
||||
hooks.add("onSend.B", function(payload) { payload.order.push("B") } )
|
||||
|
||||
let data = { order:[] };
|
||||
hooks.trigger("onSend",data).then(() => {
|
||||
done("hooks.trigger resolved unexpectedly")
|
||||
}).catch(err => {
|
||||
done();
|
||||
})
|
||||
})
|
||||
});
|
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
|
||||
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var i18n = NR_TEST_UTILS.require("@node-red/util").i18n;
|
||||
|
||||
|
||||
describe("@node-red/util/i18n", function() {
|
||||
it.skip('more tests needed', function(){})
|
||||
});
|
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* 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("@node-red/util", function() {
|
||||
it.skip('more tests needed', function(){})
|
||||
});
|
@@ -1,252 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var util = require("util");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var log = NR_TEST_UTILS.require("@node-red/util").log;
|
||||
|
||||
|
||||
describe("@node-red/util/log", function() {
|
||||
beforeEach(function () {
|
||||
var spy = sinon.stub(util, 'log').callsFake(function(arg){});
|
||||
var settings = {logging: { console: { level: 'metric', metrics: true } } };
|
||||
log.init(settings);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
util.log.restore();
|
||||
});
|
||||
|
||||
it('it can raise an error', function() {
|
||||
var ret = log.error("This is an error");
|
||||
sinon.assert.calledWithMatch(util.log,"[error] This is an error");
|
||||
});
|
||||
|
||||
it('it can raise a trace', function() {
|
||||
var ret = log.trace("This is a trace");
|
||||
sinon.assert.calledWithMatch(util.log,"[trace] This is a trace");
|
||||
});
|
||||
|
||||
it('it can raise a debug', 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");
|
||||
});
|
||||
|
||||
it('it can raise a metric', function() {
|
||||
var metrics = {};
|
||||
metrics.level = log.METRIC;
|
||||
metrics.nodeid = "testid";
|
||||
metrics.event = "node.test.testevent";
|
||||
metrics.msgid = "12345";
|
||||
metrics.value = "the metric payload";
|
||||
var ret = log.log(metrics);
|
||||
util.log.calledOnce.should.be.true();
|
||||
util.log.firstCall.args[0].indexOf("[metric] ").should.equal(0);
|
||||
var body = JSON.parse(util.log.firstCall.args[0].substring(9));
|
||||
body.should.have.a.property("nodeid","testid");
|
||||
body.should.have.a.property("event","node.test.testevent");
|
||||
body.should.have.a.property("msgid","12345");
|
||||
body.should.have.a.property("value","the metric payload");
|
||||
body.should.have.a.property("timestamp");
|
||||
body.should.have.a.property("level",log.METRIC);
|
||||
});
|
||||
|
||||
it('it checks metrics are enabled', function() {
|
||||
log.metric().should.equal(true);
|
||||
var sett = {logging: { console: { level: 'info', metrics: false } } };
|
||||
log.init(sett);
|
||||
log.metric().should.equal(false);
|
||||
});
|
||||
|
||||
it('it logs node type and name if provided',function() {
|
||||
log.log({level:log.INFO,type:"nodeType",msg:"test",name:"nodeName",id:"nodeId"});
|
||||
util.log.calledOnce.should.be.true();
|
||||
util.log.firstCall.args[0].indexOf("[nodeType:nodeName]").should.not.equal(-1);
|
||||
});
|
||||
it('it logs node type and id if no name provided',function() {
|
||||
log.log({level:log.INFO,type:"nodeType",msg:"test",id:"nodeId"});
|
||||
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);
|
||||
log.error("This is an error");
|
||||
log.warn("This is a warn");
|
||||
log.info("This is an info");
|
||||
log.debug("This is a debug");
|
||||
log.trace("This is a trace");
|
||||
log.log({level:log.METRIC,msg:"testMetric"});
|
||||
sinon.assert.calledWithMatch(util.log,"[error] This is an error");
|
||||
sinon.assert.calledWithMatch(util.log,"[warn] This is a warn");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[info] This is an info");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[debug] This is a debug");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[trace] This is a trace");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[metric] ");
|
||||
});
|
||||
it('ignores lower level messages but accepts metrics', function() {
|
||||
var settings = {logging: { console: { level: 'log', metrics: true } } };
|
||||
log.init(settings);
|
||||
log.error("This is an error");
|
||||
log.warn("This is a warn");
|
||||
log.info("This is an info");
|
||||
log.debug("This is a debug");
|
||||
log.trace("This is a trace");
|
||||
log.log({level:log.METRIC,msg:"testMetric"});
|
||||
sinon.assert.calledWithMatch(util.log,"[error] This is an error");
|
||||
sinon.assert.calledWithMatch(util.log,"[warn] This is a warn");
|
||||
sinon.assert.calledWithMatch(util.log,"[info] This is an info");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[debug] This is a debug");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[trace] This is a trace");
|
||||
sinon.assert.calledWithMatch(util.log,"[metric] ");
|
||||
});
|
||||
|
||||
it('default settings set to INFO and metrics off', function() {
|
||||
log.init({logging:{}});
|
||||
log.error("This is an error");
|
||||
log.warn("This is a warn");
|
||||
log.info("This is an info");
|
||||
log.debug("This is a debug");
|
||||
log.trace("This is a trace");
|
||||
log.log({level:log.METRIC,msg:"testMetric"});
|
||||
sinon.assert.calledWithMatch(util.log,"[error] This is an error");
|
||||
sinon.assert.calledWithMatch(util.log,"[warn] This is a warn");
|
||||
sinon.assert.calledWithMatch(util.log,"[info] This is an info");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[debug] This is a debug");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[trace] This is a trace");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[metric] ");
|
||||
});
|
||||
it('no logger used if custom logger handler does not exist', function() {
|
||||
var settings = {logging: { customLogger: { level: 'trace', metrics: true } } };
|
||||
log.init(settings);
|
||||
log.error("This is an error");
|
||||
log.warn("This is a warn");
|
||||
log.info("This is an info");
|
||||
log.debug("This is a debug");
|
||||
log.trace("This is a trace");
|
||||
log.log({level:log.METRIC,msg:"testMetric"});
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[error] This is an error");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[warn] This is a warn");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[info] This is an info");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[debug] This is a debug");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[trace] This is a trace");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[metric] ");
|
||||
});
|
||||
|
||||
it('add a custom log handler directly', function() {
|
||||
var settings = {};
|
||||
log.init(settings);
|
||||
|
||||
var logEvents = [];
|
||||
var loggerOne = {
|
||||
emit: function(event,msg) {
|
||||
logEvents.push({logger:1,msg:msg});
|
||||
}
|
||||
};
|
||||
var loggerTwo = {
|
||||
emit: function(event,msg) {
|
||||
logEvents.push({logger:2,msg:msg});
|
||||
}
|
||||
};
|
||||
log.addHandler(loggerOne);
|
||||
log.addHandler(loggerTwo);
|
||||
|
||||
log.error("This is an error");
|
||||
log.warn("This is a warn");
|
||||
log.info("This is an info");
|
||||
log.debug("This is a debug");
|
||||
log.trace("This is a trace");
|
||||
log.log({level:log.METRIC,msg:"testMetric"});
|
||||
|
||||
logEvents.filter(function(evt) { return evt.logger === 1}).should.have.lengthOf(6);
|
||||
logEvents.filter(function(evt) { return evt.logger === 2}).should.have.lengthOf(6);
|
||||
});
|
||||
|
||||
it('remove a custom log handler directly', function() {
|
||||
var settings = {};
|
||||
log.init(settings);
|
||||
|
||||
var logEvents = [];
|
||||
var loggerOne = {
|
||||
emit: function(event,msg) {
|
||||
logEvents.push({logger:1,msg:msg});
|
||||
}
|
||||
};
|
||||
var loggerTwo = {
|
||||
emit: function(event,msg) {
|
||||
logEvents.push({logger:2,msg:msg});
|
||||
}
|
||||
};
|
||||
log.addHandler(loggerOne);
|
||||
log.addHandler(loggerTwo);
|
||||
|
||||
log.info("This is an info");
|
||||
logEvents.filter(function(evt) { return evt.logger === 1}).should.have.lengthOf(1);
|
||||
logEvents.filter(function(evt) { return evt.logger === 2}).should.have.lengthOf(1);
|
||||
|
||||
|
||||
log.removeHandler(loggerTwo);
|
||||
log.info("This is an info");
|
||||
logEvents.filter(function(evt) { return evt.logger === 1}).should.have.lengthOf(2);
|
||||
logEvents.filter(function(evt) { return evt.logger === 2}).should.have.lengthOf(1);
|
||||
|
||||
log.removeHandler(loggerOne);
|
||||
log.info("This is an info");
|
||||
logEvents.filter(function(evt) { return evt.logger === 1}).should.have.lengthOf(2);
|
||||
logEvents.filter(function(evt) { return evt.logger === 2}).should.have.lengthOf(1);
|
||||
|
||||
|
||||
});
|
||||
it('it can log without exception', function() {
|
||||
var msg = {
|
||||
msg: {
|
||||
mystrangeobj:"hello",
|
||||
},
|
||||
};
|
||||
msg.msg.toString = function(){
|
||||
throw new Error('Exception in toString - should have been caught');
|
||||
}
|
||||
msg.msg.constructor = { name: "strangeobj" };
|
||||
var ret = log.info(msg.msg);
|
||||
});
|
||||
it('it can log an object but use .message', function() {
|
||||
var msg = {
|
||||
msg: {
|
||||
message: "my special message",
|
||||
mystrangeobj:"hello",
|
||||
},
|
||||
};
|
||||
var ret = log.info(msg.msg);
|
||||
sinon.assert.calledWithMatch(util.log,"my special message");
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user