more linting

This commit is contained in:
Gareth Jones 2013-05-29 08:42:09 +10:00
parent def0e8e371
commit 913c748ee0

View File

@ -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) {
that.messages.push({ level: level, message: message });
};
this.log = function(level, message, exception) { this.isLevelEnabled = function(level) {
that.messages.push({ level: level, message: message }); return level.isGreaterThanOrEqualTo(that.level);
}; };
this.isLevelEnabled = function(level) { this.level = levels.TRACE;
return level.isGreaterThanOrEqualTo(that.level);
};
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) {
assert.isObject(clm);
},
'should return a "connect logger" factory' : function(clm) { 'take a log4js logger and return a "connect logger"' : {
assert.isObject(clm); topic: function(clm) {
}, var ml = new MockLogger();
var cl = clm.connectLogger(ml);
return cl;
},
'should return a "connect logger"': function(cl) {
assert.isFunction(cl);
}
},
'log events' : {
topic: function(clm) {
var ml = new MockLogger();
var cl = clm.connectLogger(ml);
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
var res = new MockResponse(200);
cl(req, res, function() { });
res.end('chunk', 'encoding');
return ml.messages;
},
'take a log4js logger and return a "connect logger"' : { 'check message': function(messages) {
topic: function(clm) { assert.isArray(messages);
var ml = new MockLogger(); assert.equal(messages.length, 1);
var cl = clm.connectLogger(ml); assert.ok(levels.INFO.isEqualTo(messages[0].level));
return cl; assert.include(messages[0].message, 'GET');
}, assert.include(messages[0].message, 'http://url');
assert.include(messages[0].message, 'my.remote.addr');
assert.include(messages[0].message, '200');
}
},
'should return a "connect logger"': function(cl) { 'log events with level below logging level' : {
assert.isFunction(cl); topic: function(clm) {
} var ml = new MockLogger();
}, ml.level = levels.FATAL;
var cl = clm.connectLogger(ml);
'log events' : { var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
topic: function(clm) { var res = new MockResponse(200);
var ml = new MockLogger(); cl(req, res, function() { });
var cl = clm.connectLogger(ml); res.end('chunk', 'encoding');
var req = new MockRequest('my.remote.addr', 'GET', 'http://url'); return ml.messages;
var res = new MockResponse(200); },
cl(req, res, function() { });
res.end('chunk', 'encoding'); 'check message': function(messages) {
return ml.messages; assert.isArray(messages);
}, assert.isEmpty(messages);
}
'check message': function(messages) { },
assert.isArray(messages);
assert.equal(messages.length, 1);
assert.ok(levels.INFO.isEqualTo(messages[0].level));
assert.include(messages[0].message, 'GET');
assert.include(messages[0].message, 'http://url');
assert.include(messages[0].message, 'my.remote.addr');
assert.include(messages[0].message, '200');
}
},
'log events with level below logging level' : {
topic: function(clm) {
var ml = new MockLogger();
ml.level = levels.FATAL;
var cl = clm.connectLogger(ml);
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
var res = new MockResponse(200);
cl(req, res, function() { });
res.end('chunk', 'encoding');
return ml.messages;
},
'check message': function(messages) {
assert.isArray(messages);
assert.isEmpty(messages);
}
},
'log events with non-default level and custom format' : {
topic: function(clm) {
var ml = new MockLogger();
ml.level = levels.INFO;
var cl = clm.connectLogger(ml, { level: levels.INFO, format: ':method :url' } );
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
var res = new MockResponse(200);
cl(req, res, function() { });
res.end('chunk', 'encoding');
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');
}
}
'log events with non-default level and custom format' : {
topic: function(clm) {
var ml = new MockLogger();
ml.level = levels.INFO;
var cl = clm.connectLogger(ml, { level: levels.INFO, format: ':method :url' } );
var req = new MockRequest('my.remote.addr', 'GET', 'http://url');
var res = new MockResponse(200);
cl(req, res, function() { });
res.end('chunk', 'encoding');
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');
}
} }
}
}).export(module); }).export(module);