fixed to work with node v0.1.30

refactoring
csausdev 15 years ago
parent f130b95b08
commit 64fafc3f53

@ -1,16 +1,16 @@
{ {
appenders: [ "appenders": [
{ {
category: "tests", "category": "tests",
type: "file", "type": "file",
filename: "tmp-tests.log", "filename": "tmp-tests.log",
layout: { "layout": {
type: "messagePassThrough" "type": "messagePassThrough"
} }
} }
], ],
levels: { "levels": {
"tests": "WARN" "tests": "WARN"
} }
} }

@ -1,28 +1,28 @@
{ {
appenders: [ "appenders": [
{ {
category: "tests", "category": "tests",
type: "logLevelFilter", "type": "logLevelFilter",
level: "WARN", "level": "WARN",
appender: { "appender": {
type: "file", "type": "file",
filename: "tmp-tests-warnings.log", "filename": "tmp-tests-warnings.log",
layout: { "layout": {
type: "messagePassThrough" "type": "messagePassThrough"
} }
} }
}, },
{ {
category: "tests", "category": "tests",
type: "file", "type": "file",
filename: "tmp-tests.log", "filename": "tmp-tests.log",
layout: { "layout": {
type: "messagePassThrough" "type": "messagePassThrough"
} }
} }
], ],
levels: { "levels": {
"tests": "DEBUG" "tests": "DEBUG"
} }
} }

@ -1,20 +1,9 @@
fs = require('fs'), events = require('events'); fs = require('fs'), events = require('events');
waitForWriteAndThenRead = function (filename) { waitForWriteAndThenReadFile = function (filename) {
//here's the tricky part - writes are asynchronous process.loop();
//so I'm going to make a promise, wait a bit and then return fs.readFileSync(filename);
//try to read the file. };
var content, promise = new events.Promise();
promise.addCallback(function() {
content = posix.readFileSync(filename);
});
setTimeout(function() {
promise.emitSuccess();
}, 0);
promise.wait();
return content;
}
describe 'log4js' describe 'log4js'
before_each before_each
@ -145,7 +134,7 @@ describe 'log4js'
before before
log4js.clearAppenders(); log4js.clearAppenders();
try { try {
posix.unlink('./tmp-tests.log').wait(); fs.unlinkSync('./tmp-tests.log');
} catch(e) { } catch(e) {
print('Could not delete tmp-tests.log: '+e.message); print('Could not delete tmp-tests.log: '+e.message);
} }
@ -155,8 +144,7 @@ describe 'log4js'
log4js.addAppender(log4js.fileAppender('./tmp-tests.log', log4js.messagePassThroughLayout), 'tests'); log4js.addAppender(log4js.fileAppender('./tmp-tests.log', log4js.messagePassThroughLayout), 'tests');
logger.debug('this is a test'); logger.debug('this is a test');
var content = waitForWriteAndThenRead('./tmp-tests.log'); waitForWriteAndThenReadFile('./tmp-tests.log').should.be 'this is a test\n'
content.should.be 'this is a test\n'
end end
end end
@ -185,12 +173,12 @@ describe 'log4js'
before_each before_each
log4js.clearAppenders(); log4js.clearAppenders();
try { try {
posix.unlinkSync('./tmp-tests.log'); fs.unlinkSync('./tmp-tests.log');
} catch(e) { } catch(e) {
print('Could not delete tmp-tests.log: '+e.message); print('Could not delete tmp-tests.log: '+e.message);
} }
try { try {
posix.unlinkSync('./tmp-tests-warnings.log'); fs.unlinkSync('./tmp-tests-warnings.log');
} catch (e) { } catch (e) {
print('Could not delete tmp-tests-warnings.log: '+e.message); print('Could not delete tmp-tests-warnings.log: '+e.message);
} }
@ -207,7 +195,7 @@ describe 'log4js'
logger.warn('this should fire an event'); logger.warn('this should fire an event');
event.message.should.be 'this should fire an event' event.message.should.be 'this should fire an event'
waitForWriteAndThenRead('./tmp-tests.log').should.be 'this should fire an event\n' waitForWriteAndThenReadFile('./tmp-tests.log').should.be 'this should fire an event\n'
end end
it 'should handle logLevelFilter configuration' it 'should handle logLevelFilter configuration'
@ -219,8 +207,8 @@ describe 'log4js'
logger.warn('both'); logger.warn('both');
logger.debug('main'); logger.debug('main');
waitForWriteAndThenRead('./tmp-tests.log').should.be 'main\nboth\nboth\nmain\n' waitForWriteAndThenReadFile('./tmp-tests.log').should.be 'main\nboth\nboth\nmain\n'
waitForWriteAndThenRead('./tmp-tests-warnings.log').should.be 'both\nboth\n' waitForWriteAndThenReadFile('./tmp-tests-warnings.log').should.be 'both\nboth\n'
end end
end end
end end

Loading…
Cancel
Save