|
- const expect = require('chai').expect
- var debug = require('debug');
-
- describe('Tests for app/logging module', function(){
- beforeEach(function(){
- if (!this.debug){
- var debugcb = this.sandbox.spy();
- debugcb.namespace = "";
- debugcb.enabled = true;
- debugcb.destroy = function(){};
-
- //console.log(require.cache[require.resolve('debug')]);
-
- this.debugcb = debugcb;
- this.debug = this.sandbox.stub(require.cache[require.resolve('debug')], 'exports').callsFake(function(ns){
- debugcb.namespace = ns;
- return debugcb;
- });
- }
- });
-
-
- it('Create Log instance', function(){
- let log = (require('../app/logging')).createLog("test");
- expect(this.debug.called).to.eql(true);
- });
-
- it('Log instance persists.', function(){
- expect((require('../app/logging')).length).to.eql(1);
- });
-
- it('No duplicates when same namespace used.', function(){
- let lsys = require('../app/logging');
- let log = lsys.createLog("test");
- expect(lsys.length).to.eql(1);
- });
-
- it('Clear all current logs.', function(){
- let lsys = require('../app/logging');
- lsys.clear();
- expect(lsys.length).to.eql(0);
- });
-
- describe('Testing core log methods', function(){
- after(function(){
- (require('../app/logging')).clear();
- });
-
- it('.info()', function(){
- let log = (require('../app/logging')).createLog("test");
- let msg = "Test Burger";
- log.info(msg);
-
- expect(this.debugcb.calledWith("[ INFO ]: " + msg)).to.eql(true);
- });
-
- it('.debug()', function(){
- let log = (require('../app/logging')).createLog("test");
- let msg = "Test Burger";
- log.debug(msg);
-
- expect(this.debugcb.calledWith("[ DEBUG ]: " + msg)).to.eql(true);
- });
-
- it('.warning()', function(){
- let log = (require('../app/logging')).createLog("test");
- let msg = "Test Burger";
- log.warning(msg);
-
- expect(this.debugcb.calledWith("[ WARNING ]: " + msg)).to.eql(true);
- });
-
- it('.error()', function(){
- let log = (require('../app/logging')).createLog("test");
- let msg = "Test Burger";
- log.error(msg);
-
- expect(this.debugcb.calledWith("[ ERROR ]: " + msg)).to.eql(true);
- });
-
- it('.critical()', function(){
- let log = (require('../app/logging')).createLog("test");
- let msg = "Test Burger";
- log.critical(msg);
-
- expect(this.debugcb.calledWith("[ CRITICAL ]: " + msg)).to.eql(true);
- });
- });
- });
-
-
-
|