fixed file appender tests

This commit is contained in:
Gareth Jones 2012-03-22 09:34:41 +11:00
parent 352653dcbe
commit c8157cef5c
2 changed files with 17 additions and 15 deletions

View File

@ -27,11 +27,11 @@
}, },
"dependencies": { "dependencies": {
"async": "0.1.15", "async": "0.1.15",
"compress-buffer": ">= 0.5.0" "compress-buffer": "0.5.1"
}, },
"devDependencies": { "devDependencies": {
"vows": ">=0.5.2", "vows": "0.6.2",
"sandboxed-module": ">= 0.1.1", "sandboxed-module": "0.1.3",
"hook.io": "0.7.7", "hook.io": "0.7.7",
"underscore": "1.2.1" "underscore": "1.2.1"
} }

View File

@ -1,5 +1,6 @@
var vows = require('vows') var vows = require('vows')
, fs = require('fs') , fs = require('fs')
, path = require('path')
, log4js = require('../lib/log4js') , log4js = require('../lib/log4js')
, assert = require('assert'); , assert = require('assert');
@ -17,7 +18,8 @@ vows.describe('log4js fileAppender').addBatch({
'with default fileAppender settings': { 'with default fileAppender settings': {
topic: function() { topic: function() {
var that = this, testFile = __dirname + '/fa-default-test.log' var that = this
, testFile = path.join(__dirname, '/fa-default-test.log')
, logger = log4js.getLogger('default-settings'); , logger = log4js.getLogger('default-settings');
remove(testFile); remove(testFile);
log4js.clearAppenders(); log4js.clearAppenders();
@ -38,7 +40,7 @@ vows.describe('log4js fileAppender').addBatch({
}, },
'with a max file size and no backups': { 'with a max file size and no backups': {
topic: function() { topic: function() {
var testFile = __dirname + '/fa-maxFileSize-test.log' var testFile = path.join(__dirname, '/fa-maxFileSize-test.log')
, logger = log4js.getLogger('max-file-size') , logger = log4js.getLogger('max-file-size')
, that = this; , that = this;
remove(testFile); remove(testFile);
@ -71,7 +73,7 @@ vows.describe('log4js fileAppender').addBatch({
}, },
'with a max file size and 2 backups': { 'with a max file size and 2 backups': {
topic: function() { topic: function() {
var testFile = __dirname + '/fa-maxFileSize-with-backups-test.log' var testFile = path.join(__dirname, '/fa-maxFileSize-with-backups-test.log')
, logger = log4js.getLogger('max-file-size-backups'); , logger = log4js.getLogger('max-file-size-backups');
remove(testFile); remove(testFile);
remove(testFile+'.1'); remove(testFile+'.1');
@ -103,26 +105,26 @@ vows.describe('log4js fileAppender').addBatch({
}, },
'and the contents of the first file': { 'and the contents of the first file': {
topic: function(logFiles) { topic: function(logFiles) {
fs.readFile(logFiles[0], "utf8", this.callback); fs.readFile(path.join(__dirname, logFiles[0]), "utf8", this.callback);
}, },
'should be the last log message': function(err, contents) { 'should be empty because the last log message triggers rolling': function(contents) {
assert.include(contents, 'This is the fourth log message.'); assert.isEmpty(contents);
} }
}, },
'and the contents of the second file': { 'and the contents of the second file': {
topic: function(logFiles) { topic: function(logFiles) {
fs.readFile(logFiles[1], "utf8", this.callback); fs.readFile(path.join(__dirname, logFiles[1]), "utf8", this.callback);
}, },
'should be the third log message': function(err, contents) { 'should be the last log message': function(contents) {
assert.include(contents, 'This is the third log message.'); assert.include(contents, 'This is the fourth log message.');
} }
}, },
'and the contents of the third file': { 'and the contents of the third file': {
topic: function(logFiles) { topic: function(logFiles) {
fs.readFile(logFiles[2], "utf8", this.callback); fs.readFile(path.join(__dirname, logFiles[2]), "utf8", this.callback);
}, },
'should be the second log message': function(err, contents) { 'should be the third log message': function(contents) {
assert.include(contents, 'This is the second log message.'); assert.include(contents, 'This is the third log message.');
} }
} }
} }