improved coverage of hookio appender

This commit is contained in:
Gareth Jones 2013-07-08 08:46:11 +10:00
parent a86bed975c
commit be5fa838be

View File

@ -3,8 +3,9 @@ var vows = require('vows')
, assert = require('assert') , assert = require('assert')
, sandbox = require('sandboxed-module'); , sandbox = require('sandboxed-module');
function fancyResultingHookioAppender(opts) { function fancyResultingHookioAppender(hookNotReady) {
var result = { ons: {}, emissions: {}, logged: [], configs: [] }; var emitHook = !hookNotReady
, result = { ons: {}, emissions: {}, logged: [], configs: [] };
var fakeLog4Js = { var fakeLog4Js = {
appenderMakers: {} appenderMakers: {}
@ -24,7 +25,7 @@ function fancyResultingHookioAppender(opts) {
}; };
fakeHookIo.Hook.prototype.on = function (eventName, functionToExec) { fakeHookIo.Hook.prototype.on = function (eventName, functionToExec) {
result.ons[eventName] = { functionToExec: functionToExec }; result.ons[eventName] = { functionToExec: functionToExec };
if (eventName === 'hook::ready') { if (emitHook && eventName === 'hook::ready') {
functionToExec(); functionToExec();
} }
}; };
@ -130,5 +131,46 @@ vows.describe('log4js hookioAppender').addBatch({
assert.isUndefined(result.ons['*::ohno::log']); assert.isUndefined(result.ons['*::ohno::log']);
} }
} }
},
'when hook not ready': {
topic: function() {
var fancy = fancyResultingHookioAppender(true)
, logger = fancy.theModule.configure({
name: 'ohno',
mode: 'worker'
});
logger({
level: { levelStr: 'INFO' },
data: "something",
startTime: '2011-10-27T03:45:12.031Z'
});
return fancy;
},
'should buffer the log events': function(fancy) {
assert.isUndefined(fancy.theResult.emissions['ohno::log']);
},
},
'when hook ready': {
topic: function() {
var fancy = fancyResultingHookioAppender(true)
, logger = fancy.theModule.configure({
name: 'ohno',
mode: 'worker'
});
logger({
level: { levelStr: 'INFO' },
data: "something",
startTime: '2011-10-27T03:45:12.031Z'
});
fancy.theResult.ons['hook::ready'].functionToExec();
return fancy;
},
'should emit the buffered events': function(fancy) {
assert.equal(fancy.theResult.emissions['ohno::log'].length, 1);
}
} }
}).exportTo(module); }).exportTo(module);