fix(test): moved abspath test to tap

This commit is contained in:
Gareth Jones 2017-01-02 19:09:45 +11:00
parent 9f05cb35ee
commit 1d5135bcca
2 changed files with 88 additions and 88 deletions

View 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();
});

View File

@ -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);