log4js-node/test/tap/configuration-test.js
Gareth Jones 5283782ba0 refactor(all): basic logging to stdout works again
- removed config reloading
- removed console replacement
- added recording appender
- added config validation
- changed config format
2017-02-05 10:05:49 +11:00

57 lines
1.4 KiB
JavaScript

'use strict';
const test = require('tap').test;
const sandbox = require('sandboxed-module');
test('log4js configure', (batch) => {
batch.test('when configuration file loaded via LOG4JS_CONFIG env variable', (t) => {
process.env.LOG4JS_CONFIG = 'some/path/to/mylog4js.json';
let fileRead = 0;
const modulePath = 'some/path/to/mylog4js.json';
const pathsChecked = [];
const mtime = new Date();
const fakeFS = {
config: {
appenders: {
console: { type: 'console', layout: { type: 'messagePassThrough' } }
},
categories: { default: { appenders: ['console'], level: 'INFO' } }
},
readdirSync: function (dir) {
return require('fs').readdirSync(dir);
},
readFileSync: function (file, encoding) {
fileRead += 1;
t.type(file, 'string');
t.equal(file, modulePath);
t.equal(encoding, 'utf8');
return JSON.stringify(fakeFS.config);
},
statSync: function (path) {
pathsChecked.push(path);
if (path === modulePath) {
return { mtime: mtime };
}
throw new Error('no such file');
}
};
sandbox.require(
'../../lib/log4js',
{
requires: {
fs: fakeFS,
}
}
);
delete process.env.LOG4JS_CONFIG;
t.equal(fileRead, 1, 'should load the specified local config file');
t.end();
});
batch.end();
});