mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
fix(test): moved abspath test to tap
This commit is contained in:
parent
9f05cb35ee
commit
1d5135bcca
88
test/tap/log-abspath-test.js
Normal file
88
test/tap/log-abspath-test.js
Normal file
@ -0,0 +1,88 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('tap').test;
|
||||
const path = require('path');
|
||||
const sandbox = require('sandboxed-module');
|
||||
|
||||
test('log4js-abspath', (batch) => {
|
||||
batch.test('options', (t) => {
|
||||
let appenderOptions;
|
||||
|
||||
const log4js = sandbox.require(
|
||||
'../../lib/log4js',
|
||||
{
|
||||
singleOnly: true,
|
||||
requires: {
|
||||
'./appenders/fake': {
|
||||
name: 'fake',
|
||||
appender: function () {
|
||||
},
|
||||
configure: function (configuration, options) {
|
||||
appenderOptions = options;
|
||||
return function () {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const config = {
|
||||
appenders: [
|
||||
{
|
||||
type: 'fake',
|
||||
filename: 'cheesy-wotsits.log'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
log4js.configure(config, {
|
||||
cwd: '/absolute/path/to'
|
||||
});
|
||||
t.test('should be passed to appenders during configuration', (assert) => {
|
||||
assert.equal(appenderOptions.cwd, '/absolute/path/to');
|
||||
assert.end();
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
batch.test('file appender', (t) => {
|
||||
let fileOpened;
|
||||
|
||||
const fileAppender = sandbox.require(
|
||||
'../../lib/appenders/file',
|
||||
{
|
||||
requires: {
|
||||
streamroller: {
|
||||
RollingFileStream: function (file) {
|
||||
fileOpened = file;
|
||||
return {
|
||||
on: function () {
|
||||
},
|
||||
end: function () {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
fileAppender.configure(
|
||||
{
|
||||
filename: 'whatever.log',
|
||||
maxLogSize: 10
|
||||
},
|
||||
{ cwd: '/absolute/path/to' }
|
||||
);
|
||||
|
||||
t.test('should prepend options.cwd to config.filename', (assert) => {
|
||||
const expected = path.sep + path.join('absolute', 'path', 'to', 'whatever.log');
|
||||
assert.equal(fileOpened, expected);
|
||||
assert.end();
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
batch.end();
|
||||
});
|
||||
@ -1,88 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const vows = require('vows');
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const sandbox = require('sandboxed-module');
|
||||
|
||||
vows.describe('log4js-abspath').addBatch({
|
||||
options: {
|
||||
topic: function () {
|
||||
let appenderOptions;
|
||||
|
||||
const log4js = sandbox.require(
|
||||
'../../lib/log4js',
|
||||
{
|
||||
singleOnly: true,
|
||||
requires: {
|
||||
'./appenders/fake': {
|
||||
name: 'fake',
|
||||
appender: function () {
|
||||
},
|
||||
configure: function (configuration, options) {
|
||||
appenderOptions = options;
|
||||
return function () {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const config = {
|
||||
appenders: [
|
||||
{
|
||||
type: 'fake',
|
||||
filename: 'cheesy-wotsits.log'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
log4js.configure(config, {
|
||||
cwd: '/absolute/path/to'
|
||||
});
|
||||
return appenderOptions;
|
||||
},
|
||||
'should be passed to appenders during configuration': function (options) {
|
||||
assert.equal(options.cwd, '/absolute/path/to');
|
||||
}
|
||||
},
|
||||
|
||||
'file appender': {
|
||||
topic: function () {
|
||||
let fileOpened;
|
||||
|
||||
const fileAppender = sandbox.require(
|
||||
'../../lib/appenders/file',
|
||||
{
|
||||
requires: {
|
||||
streamroller: {
|
||||
RollingFileStream: function (file) {
|
||||
fileOpened = file;
|
||||
return {
|
||||
on: function () {
|
||||
},
|
||||
end: function () {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
fileAppender.configure(
|
||||
{
|
||||
filename: 'whatever.log',
|
||||
maxLogSize: 10
|
||||
},
|
||||
{ cwd: '/absolute/path/to' }
|
||||
);
|
||||
return fileOpened;
|
||||
},
|
||||
'should prepend options.cwd to config.filename': function (fileOpened) {
|
||||
const expected = path.sep + path.join('absolute', 'path', 'to', 'whatever.log');
|
||||
assert.equal(fileOpened, expected);
|
||||
}
|
||||
},
|
||||
}).export(module);
|
||||
Loading…
x
Reference in New Issue
Block a user