more linting
This commit is contained in:
parent
def0e8e371
commit
913c748ee0
@ -1,128 +1,128 @@
|
|||||||
|
"use strict";
|
||||||
var vows = require('vows')
|
var vows = require('vows')
|
||||||
, assert = require('assert')
|
, assert = require('assert')
|
||||||
, levels = require('../lib/levels');
|
, levels = require('../lib/levels');
|
||||||
|
|
||||||
function MockLogger() {
|
function MockLogger() {
|
||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
this.messages = [];
|
this.messages = [];
|
||||||
|
|
||||||
this.log = function(level, message, exception) {
|
this.log = function(level, message, exception) {
|
||||||
that.messages.push({ level: level, message: message });
|
that.messages.push({ level: level, message: message });
|
||||||
};
|
};
|
||||||
|
|
||||||
this.isLevelEnabled = function(level) {
|
this.isLevelEnabled = function(level) {
|
||||||
return level.isGreaterThanOrEqualTo(that.level);
|
return level.isGreaterThanOrEqualTo(that.level);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.level = levels.TRACE;
|
this.level = levels.TRACE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function MockRequest(remoteAddr, method, originalUrl) {
|
function MockRequest(remoteAddr, method, originalUrl) {
|
||||||
|
|
||||||
this.socket = { remoteAddress: remoteAddr };
|
this.socket = { remoteAddress: remoteAddr };
|
||||||
this.originalUrl = originalUrl;
|
this.originalUrl = originalUrl;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.httpVersionMajor = '5';
|
this.httpVersionMajor = '5';
|
||||||
this.httpVersionMinor = '0';
|
this.httpVersionMinor = '0';
|
||||||
this.headers = {}
|
this.headers = {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function MockResponse(statusCode) {
|
function MockResponse(statusCode) {
|
||||||
|
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
|
|
||||||
this.end = function(chunk, encoding) {
|
this.end = function(chunk, encoding) {
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('log4js connect logger').addBatch({
|
vows.describe('log4js connect logger').addBatch({
|
||||||
'getConnectLoggerModule': {
|
'getConnectLoggerModule': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var clm = require('../lib/connect-logger');
|
var clm = require('../lib/connect-logger');
|
||||||
return clm;
|
return clm;
|
||||||
},
|
},
|
||||||
|
|
||||||
'should return a "connect logger" factory' : function(clm) {
|
'should return a "connect logger" factory' : function(clm) {
|
||||||
assert.isObject(clm);
|
assert.isObject(clm);
|
||||||
},
|
},
|
||||||
|
|
||||||
'take a log4js logger and return a "connect logger"' : {
|
'take a log4js logger and return a "connect logger"' : {
|
||||||
topic: function(clm) {
|
topic: function(clm) {
|
||||||
var ml = new MockLogger();
|
var ml = new MockLogger();
|
||||||
var cl = clm.connectLogger(ml);
|
var cl = clm.connectLogger(ml);
|
||||||
return cl;
|
return cl;
|
||||||
},
|
},
|
||||||
|
|
||||||
'should return a "connect logger"': function(cl) {
|
'should return a "connect logger"': function(cl) {
|
||||||
assert.isFunction(cl);
|
assert.isFunction(cl);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'log events' : {
|
'log events' : {
|
||||||
topic: function(clm) {
|
topic: function(clm) {
|
||||||
var ml = new MockLogger();
|
var ml = new MockLogger();
|
||||||
var cl = clm.connectLogger(ml);
|
var cl = clm.connectLogger(ml);
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
|
||||||
var res = new MockResponse(200);
|
var res = new MockResponse(200);
|
||||||
cl(req, res, function() { });
|
cl(req, res, function() { });
|
||||||
res.end('chunk', 'encoding');
|
res.end('chunk', 'encoding');
|
||||||
return ml.messages;
|
return ml.messages;
|
||||||
},
|
},
|
||||||
|
|
||||||
'check message': function(messages) {
|
'check message': function(messages) {
|
||||||
assert.isArray(messages);
|
assert.isArray(messages);
|
||||||
assert.equal(messages.length, 1);
|
assert.equal(messages.length, 1);
|
||||||
assert.ok(levels.INFO.isEqualTo(messages[0].level));
|
assert.ok(levels.INFO.isEqualTo(messages[0].level));
|
||||||
assert.include(messages[0].message, 'GET');
|
assert.include(messages[0].message, 'GET');
|
||||||
assert.include(messages[0].message, 'http://url');
|
assert.include(messages[0].message, 'http://url');
|
||||||
assert.include(messages[0].message, 'my.remote.addr');
|
assert.include(messages[0].message, 'my.remote.addr');
|
||||||
assert.include(messages[0].message, '200');
|
assert.include(messages[0].message, '200');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'log events with level below logging level' : {
|
'log events with level below logging level' : {
|
||||||
topic: function(clm) {
|
topic: function(clm) {
|
||||||
var ml = new MockLogger();
|
var ml = new MockLogger();
|
||||||
ml.level = levels.FATAL;
|
ml.level = levels.FATAL;
|
||||||
var cl = clm.connectLogger(ml);
|
var cl = clm.connectLogger(ml);
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
|
||||||
var res = new MockResponse(200);
|
var res = new MockResponse(200);
|
||||||
cl(req, res, function() { });
|
cl(req, res, function() { });
|
||||||
res.end('chunk', 'encoding');
|
res.end('chunk', 'encoding');
|
||||||
return ml.messages;
|
return ml.messages;
|
||||||
},
|
},
|
||||||
|
|
||||||
'check message': function(messages) {
|
'check message': function(messages) {
|
||||||
assert.isArray(messages);
|
assert.isArray(messages);
|
||||||
assert.isEmpty(messages);
|
assert.isEmpty(messages);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'log events with non-default level and custom format' : {
|
'log events with non-default level and custom format' : {
|
||||||
topic: function(clm) {
|
topic: function(clm) {
|
||||||
var ml = new MockLogger();
|
var ml = new MockLogger();
|
||||||
ml.level = levels.INFO;
|
ml.level = levels.INFO;
|
||||||
var cl = clm.connectLogger(ml, { level: levels.INFO, format: ':method :url' } );
|
var cl = clm.connectLogger(ml, { level: levels.INFO, format: ':method :url' } );
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
|
||||||
var res = new MockResponse(200);
|
var res = new MockResponse(200);
|
||||||
cl(req, res, function() { });
|
cl(req, res, function() { });
|
||||||
res.end('chunk', 'encoding');
|
res.end('chunk', 'encoding');
|
||||||
return ml.messages;
|
return ml.messages;
|
||||||
},
|
},
|
||||||
|
|
||||||
'check message': function(messages) {
|
|
||||||
assert.isArray(messages);
|
|
||||||
assert.equal(messages.length, 1);
|
|
||||||
assert.ok(levels.INFO.isEqualTo(messages[0].level));
|
|
||||||
assert.equal(messages[0].message, 'GET http://url');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
'check message': function(messages) {
|
||||||
|
assert.isArray(messages);
|
||||||
|
assert.equal(messages.length, 1);
|
||||||
|
assert.ok(levels.INFO.isEqualTo(messages[0].level));
|
||||||
|
assert.equal(messages[0].message, 'GET http://url');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}).export(module);
|
}).export(module);
|
||||||
|
Loading…
Reference in New Issue
Block a user