8000 moved basicLayout tests to vows · lalitkapoor/log4js-node@80305ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 80305ca

Browse files
author
csausdev
committed
moved basicLayout tests to vows
1 parent 7d4fdce commit 80305ca

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

spec/spec.logging.js

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,39 +104,8 @@ describe 'log4js'
104104
end
105105
end
106106

107-
describe 'basicLayout'
108-
it 'should take a logevent and output a formatted string'
109-
logger.debug('this is a test');
110-
var output = log4js.basicLayout(event);
111-
output.should.match /\[.*?\] \[DEBUG\] tests - this is a test/
112-
end
113-
114-
it 'should output a stacktrace, message if the event has an error attached'
115-
var error = new Error("Some made-up error");
116-
var stack = error.stack.split(/\n/);
117-
118-
logger.debug('this is a test', error);
119-
120-
var output = log4js.basicLayout(event);
121-
var lines = output.split(/\n/);
122-
lines.length.should.be stack.length+1
123-
lines[0].should.match /\[.*?\] \[DEBUG\] tests - this is a test/
124-
lines[1].should.match /\[.*?\] \[DEBUG\] tests - Error: Some made-up error/
125-
for (var i = 1; i < stack.length; i++) {
126-
lines[i+1].should.eql stack[i]
127-
}
128-
end
129-
130-
it 'should output a name and message if the event has something that pretends to be an error'
131-
logger.debug('this is a test', { name: 'Cheese', message: 'Gorgonzola smells.' });
132-
var output = log4js.basicLayout(event);
133-
var lines = output.split(/\n/);
134-
lines.length.should.be 2
135-
lines[0].should.match /\[.*?\] \[DEBUG\] tests - this is a test/
136-
lines[1].should.match /\[.*?\] \[DEBUG\] tests - Cheese: Gorgonzola smells./
137-
end
138-
end
139107

108+
140109

141110

142111

test/logging.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,55 @@ vows.describe('log4js').addBatch({
327327
}
328328
},
329329

330+
'basicLayout': {
331+
topic: function() {
332+
var layout = require('../lib/log4js')().basicLayout,
333+
event = {
334+
message: 'this is a test',
335+
startTime: new Date(2010, 11, 5, 14, 18, 30, 45),
336+
categoryName: "tests",
337+
level: {
338+
colour: "green",
339+
toString: function() { return "DEBUG"; }
340+
}
341+
};
342+
return [layout, event];
343+
},
344+
'should take a logevent and output a formatted string': function(args) {
345+
var layout = args[0], event = args[1];
346+
assert.equal(layout(event), "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test");
347+
},
348+
'should output a stacktrace, message if the event has an error attached': function(args) {
349+
var layout = args[0], event = args[1], output, lines,
350+
error = new Error("Some made-up error"),
351+
stack = error.stack.split(/\n/);
352+
353+
event.exception = error;
354+
output = layout(event);
355+
lines = output.split(/\n/);
356+
357+
assert.length(lines, stack.length+1);
358+
assert.equal(lines[0], "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test");
359+
assert.equal(lines[1], "[2010-12-05 14:18:30.045] [DEBUG] tests - Error: Some made-up error");
360+
for (var i = 1; i < stack.length; i++) {
361+
assert.equal(lines[i+1], stack[i]);
362+
}
363+
},
364+
'should output a name and message if the event has something that pretends to be an error': function(args) {
365+
var layout = args[0], event = args[1], output, lines;
366+
event.exception = {
367+
name: 'Cheese',
368+
message: 'Gorgonzola smells.'
369+
};
370+
output = layout(event);
371+
lines = output.split(/\n/);
372+
373+
assert.length(lines, 2);
374+
assert.equal(lines[0], "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test");
375+
assert.equal(lines[1], "[2010 5A24 -12-05 14:18:30.045] [DEBUG] tests - Cheese: Gorgonzola smells.");
376+
}
377+
},
378+
330379
'logLevelFilter': {
331380
topic: function() {
332381
var log4js = require('../lib/log4js')(), logEvents = [], logger;

0 commit comments

Comments
 (0)
0