log4js-node/test/log-abspath-test.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

2013-05-27 05:48:29 +08:00
"use strict";
2012-02-08 12:55:14 +08:00
var vows = require('vows')
, assert = require('assert')
, sandbox = require('sandboxed-module');
vows.describe('log4js-abspath').addBatch({
2013-05-27 05:48:29 +08:00
'options': {
topic: function() {
var appenderOptions,
log4js = sandbox.require(
'../lib/log4js',
{ requires:
{ './appenders/fake':
{ name: "fake",
appender: function() {},
configure: function(configuration, options) {
appenderOptions = options;
return function() {};
}
}
}
2012-02-08 12:55:14 +08:00
}
2013-05-27 05:48:29 +08:00
),
config = {
"appenders": [
{
"type" : "fake",
"filename" : "cheesy-wotsits.log"
}
]
};
log4js.configure(config, {
cwd: '/absolute/path/to'
});
return appenderOptions;
2012-02-08 12:55:14 +08:00
},
2013-05-27 05:48:29 +08:00
'should be passed to appenders during configuration': function(options) {
assert.equal(options.cwd, '/absolute/path/to');
}
},
2012-02-08 12:55:14 +08:00
2013-05-27 05:48:29 +08:00
'file appender': {
topic: function() {
var fileOpened,
fileAppender = sandbox.require(
'../lib/appenders/file',
{ requires:
{ '../streams':
{ RollingFileStream:
function(file) {
fileOpened = file;
return {
on: function() {},
end: function() {}
};
}
}
}
2012-02-08 12:55:14 +08:00
}
2013-05-27 05:48:29 +08:00
);
fileAppender.configure(
{
filename: "whatever.log",
maxLogSize: 10
},
{ cwd: '/absolute/path/to' }
);
return fileOpened;
2012-02-08 12:55:14 +08:00
},
2013-05-27 05:48:29 +08:00
'should prepend options.cwd to config.filename': function(fileOpened) {
assert.equal(fileOpened, "/absolute/path/to/whatever.log");
}
},
}).export(module);