more linting

This commit is contained in:
Gareth Jones
2013-05-27 07:41:16 +10:00
parent 2192a094b6
commit 7cb7e6df72
+82 -57
View File
@@ -1,3 +1,4 @@
"use strict";
var vows = require('vows') var vows = require('vows')
, assert = require('assert') , assert = require('assert')
, sandbox = require('sandboxed-module'); , sandbox = require('sandboxed-module');
@@ -14,8 +15,8 @@ function setupConsoleTest() {
}); });
log4js = sandbox.require( log4js = sandbox.require(
'../lib/log4js' '../lib/log4js',
, { {
globals: { globals: {
console: fakeConsole console: fakeConsole
} }
@@ -93,26 +94,25 @@ vows.describe('log4js').addBatch({
'configuration when passed as object': { 'configuration when passed as object': {
topic: function() { topic: function() {
var appenderConfig var appenderConfig,
, log4js = sandbox.require( log4js = sandbox.require(
'../lib/log4js' '../lib/log4js',
, { requires:
{ './appenders/file':
{ {
name: "file" requires: {
, appender: function() {} './appenders/file':
, configure: function(configuration) { {
name: "file",
appender: function() {},
configure: function(configuration) {
appenderConfig = configuration; appenderConfig = configuration;
return function() {}; return function() {};
} }
} }
} }
} }
) ),
, config = { config = { appenders:
"appenders": [ [ { "type" : "file",
{
"type" : "file",
"filename" : "cheesy-wotsits.log", "filename" : "cheesy-wotsits.log",
"maxLogSize" : 1024, "maxLogSize" : 1024,
"backups" : 3 "backups" : 3
@@ -129,17 +129,18 @@ vows.describe('log4js').addBatch({
'configuration when passed as filename': { 'configuration when passed as filename': {
topic: function() { topic: function() {
var appenderConfig var appenderConfig,
, configFilename configFilename,
, log4js = sandbox.require( log4js = sandbox.require(
'../lib/log4js' '../lib/log4js',
, { requires: { requires:
{ 'fs': { 'fs':
{ { statSync:
statSync: function() { function() {
return { mtime: Date.now() }; return { mtime: Date.now() };
}, },
readFileSync: function(filename) { readFileSync:
function(filename) {
configFilename = filename; configFilename = filename;
return JSON.stringify({ return JSON.stringify({
appenders: [ appenders: [
@@ -149,15 +150,15 @@ vows.describe('log4js').addBatch({
] ]
}); });
}, },
readdirSync: function() { readdirSync:
function() {
return ['file']; return ['file'];
} }
} },
, './appenders/file': './appenders/file':
{ { name: "file",
name: "file" appender: function() {},
, appender: function() {} configure: function(configuration) {
, configure: function(configuration) {
appenderConfig = configuration; appenderConfig = configuration;
return function() {}; return function() {};
} }
@@ -178,22 +179,22 @@ vows.describe('log4js').addBatch({
'with no appenders defined' : { 'with no appenders defined' : {
topic: function() { topic: function() {
var logger var logger,
, that = this that = this,
, fakeConsoleAppender = { fakeConsoleAppender = {
name: "console" name: "console",
, appender: function() { appender: function() {
return function(evt) { return function(evt) {
that.callback(null, evt); that.callback(null, evt);
} };
} },
, configure: function() { configure: function() {
return fakeConsoleAppender.appender(); return fakeConsoleAppender.appender();
} }
} },
, log4js = sandbox.require( log4js = sandbox.require(
'../lib/log4js' '../lib/log4js',
, { {
requires: { requires: {
'./appenders/console': fakeConsoleAppender './appenders/console': fakeConsoleAppender
} }
@@ -215,15 +216,22 @@ vows.describe('log4js').addBatch({
}, },
'without a category': { 'without a category': {
'should register the function as a listener for all loggers': function (log4js) { 'should register the function as a listener for all loggers': function (log4js) {
var appenderEvent, appender = function(evt) { appenderEvent = evt; }, logger = log4js.getLogger("tests"); var appenderEvent,
appender = function(evt) { appenderEvent = evt; },
logger = log4js.getLogger("tests");
log4js.addAppender(appender); log4js.addAppender(appender);
logger.debug("This is a test"); logger.debug("This is a test");
assert.equal(appenderEvent.data[0], "This is a test"); assert.equal(appenderEvent.data[0], "This is a test");
assert.equal(appenderEvent.categoryName, "tests"); assert.equal(appenderEvent.categoryName, "tests");
assert.equal(appenderEvent.level.toString(), "DEBUG"); assert.equal(appenderEvent.level.toString(), "DEBUG");
}, },
'should also register as an appender for loggers if an appender for that category is defined': function (log4js) { 'if an appender for a category is defined': {
var otherEvent, appenderEvent, cheeseLogger; 'should register for that category': function (log4js) {
var otherEvent,
appenderEvent,
cheeseLogger;
log4js.addAppender(function (evt) { appenderEvent = evt; }); log4js.addAppender(function (evt) { appenderEvent = evt; });
log4js.addAppender(function (evt) { otherEvent = evt; }, 'cheese'); log4js.addAppender(function (evt) { otherEvent = evt; }, 'cheese');
@@ -239,11 +247,15 @@ vows.describe('log4js').addBatch({
assert.isUndefined(otherEvent); assert.isUndefined(otherEvent);
assert.equal(appenderEvent.data[0], "this should not be propagated to otherEvent"); assert.equal(appenderEvent.data[0], "this should not be propagated to otherEvent");
} }
}
}, },
'with a category': { 'with a category': {
'should only register the function as a listener for that category': function(log4js) { 'should only register the function as a listener for that category': function(log4js) {
var appenderEvent, appender = function(evt) { appenderEvent = evt; }, logger = log4js.getLogger("tests"); var appenderEvent,
appender = function(evt) { appenderEvent = evt; },
logger = log4js.getLogger("tests");
log4js.addAppender(appender, 'tests'); log4js.addAppender(appender, 'tests');
logger.debug('this is a category test'); logger.debug('this is a category test');
assert.equal(appenderEvent.data[0], 'this is a category test'); assert.equal(appenderEvent.data[0], 'this is a category test');
@@ -256,7 +268,10 @@ vows.describe('log4js').addBatch({
'with multiple categories': { 'with multiple categories': {
'should register the function as a listener for all the categories': function(log4js) { 'should register the function as a listener for all the categories': function(log4js) {
var appenderEvent, appender = function(evt) { appenderEvent = evt; }, logger = log4js.getLogger('tests'); var appenderEvent,
appender = function(evt) { appenderEvent = evt; },
logger = log4js.getLogger('tests');
log4js.addAppender(appender, 'tests', 'biscuits'); log4js.addAppender(appender, 'tests', 'biscuits');
logger.debug('this is a test'); logger.debug('this is a test');
@@ -273,7 +288,9 @@ vows.describe('log4js').addBatch({
assert.isUndefined(appenderEvent); assert.isUndefined(appenderEvent);
}, },
'should register the function when the list of categories is an array': function(log4js) { 'should register the function when the list of categories is an array': function(log4js) {
var appenderEvent, appender = function(evt) { appenderEvent = evt; }; var appenderEvent,
appender = function(evt) { appenderEvent = evt; };
log4js.addAppender(appender, ['tests', 'pants']); log4js.addAppender(appender, ['tests', 'pants']);
log4js.getLogger('tests').debug('this is a test'); log4js.getLogger('tests').debug('this is a test');
@@ -296,13 +313,13 @@ vows.describe('log4js').addBatch({
topic: function() { topic: function() {
var appenderEvents = [], var appenderEvents = [],
fakeConsole = { fakeConsole = {
'name': 'console' 'name': 'console',
, 'appender': function () { 'appender': function () {
return function(evt) { return function(evt) {
appenderEvents.push(evt); appenderEvents.push(evt);
} };
} },
, 'configure': function (config) { 'configure': function (config) {
return fakeConsole.appender(); return fakeConsole.appender();
} }
}, },
@@ -431,8 +448,12 @@ vows.describe('log4js').addBatch({
modulePath = 'path/to/log4js.json', modulePath = 'path/to/log4js.json',
fakeFS = { fakeFS = {
lastMtime: Date.now(), lastMtime: Date.now(),
config: { appenders: [ { type: 'console', layout: { type: 'messagePassThrough' } } ], config: {
levels: { 'a-test' : 'INFO' } }, appenders: [
{ type: 'console', layout: { type: 'messagePassThrough' } }
],
levels: { 'a-test' : 'INFO' }
},
readdirSync: function(dir) { readdirSync: function(dir) {
return require('fs').readdirSync(dir); return require('fs').readdirSync(dir);
}, },
@@ -506,8 +527,12 @@ vows.describe('log4js').addBatch({
modulePath = require('path').normalize(__dirname + '/../lib/log4js.json'), modulePath = require('path').normalize(__dirname + '/../lib/log4js.json'),
mtime = new Date(), mtime = new Date(),
fakeFS = { fakeFS = {
config: { appenders: [ { type: 'console', layout: { type: 'messagePassThrough' } } ], config: {
levels: { 'a-test' : 'INFO' } }, appenders: [
{ type: 'console', layout: { type: 'messagePassThrough' } }
],
levels: { 'a-test' : 'INFO' }
},
readdirSync: function(dir) { readdirSync: function(dir) {
return require('fs').readdirSync(dir); return require('fs').readdirSync(dir);
}, },