2014-12-02 06:55:29 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
var chai = chai || require('chai');
|
|
|
|
var sinon = sinon || require('sinon');
|
|
|
|
var should = chai.should();
|
|
|
|
var log = require('../js/util/log');
|
|
|
|
|
2014-12-02 07:15:58 -08:00
|
|
|
describe('log utils', function() {
|
2014-12-02 06:55:29 -08:00
|
|
|
afterEach(function() {
|
|
|
|
log.setLevel('info');
|
|
|
|
});
|
|
|
|
|
2014-12-03 03:23:53 -08:00
|
|
|
it('should log .warn', function() {
|
2014-12-02 07:15:58 -08:00
|
|
|
if (console.warn.restore)
|
|
|
|
console.warn.restore();
|
|
|
|
|
|
|
|
sinon.stub(console,'warn');
|
|
|
|
|
2014-12-02 06:55:29 -08:00
|
|
|
log.setLevel('debug');
|
2014-12-02 07:15:58 -08:00
|
|
|
log.warn('hola');
|
2014-12-02 06:55:29 -08:00
|
|
|
|
2014-12-02 07:15:58 -08:00
|
|
|
var arg = console.warn.getCall(0).args[0];
|
2014-12-02 13:27:48 -08:00
|
|
|
//arg.should.contain('util.log.js'); /* Firefox does not include the stack track */
|
2014-12-02 06:55:29 -08:00
|
|
|
arg.should.contain('hola');
|
2014-12-02 07:15:58 -08:00
|
|
|
console.warn.restore();
|
2014-12-02 06:55:29 -08:00
|
|
|
});
|
|
|
|
|
2014-12-03 03:23:53 -08:00
|
|
|
|
|
|
|
it('should log .fatal', function() {
|
|
|
|
if (console.log.restore)
|
|
|
|
console.log.restore();
|
|
|
|
|
|
|
|
sinon.stub(console,'log');
|
|
|
|
|
|
|
|
log.setLevel('debug');
|
|
|
|
log.fatal('hola',"que",'tal');
|
|
|
|
|
|
|
|
var arg = console.log.getCall(0).args[0];
|
|
|
|
//arg.should.contain('util.log.js'); /* Firefox does not include the stack track */
|
|
|
|
arg.should.contain('que');
|
|
|
|
console.log.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-12-02 06:55:29 -08:00
|
|
|
it('should not log debug', function() {
|
|
|
|
sinon.stub(console,'log');
|
|
|
|
log.setLevel('info');
|
|
|
|
log.debug('hola');
|
|
|
|
console.log.called.should.equal(false);
|
|
|
|
console.log.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should log debug', function() {
|
|
|
|
log.getLevels().debug.should.equal(0);
|
|
|
|
log.getLevels().fatal.should.equal(5);
|
|
|
|
});
|
2014-12-03 03:23:53 -08:00
|
|
|
|
|
|
|
|
2014-12-02 06:55:29 -08:00
|
|
|
});
|