8000 Add unit tests - layouts-test.js · rboss/log4js-node@f948b5f · GitHub
[go: up one dir, main page]

Skip to content

Commit f948b5f

Browse files
committed
Add unit tests - layouts-test.js
1 parent 54e420e commit f948b5f

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

test/layouts-test.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,50 @@ vows.describe('log4js layouts').addBatch({
7676
, toString: function() { return "ERROR"; }
7777
}
7878
}), "{ thing: 1 }");
79+
},
80+
'should print the stacks of a passed error objects': function(layout) {
81+
assert.isArray(layout({
82+
data: [ new Error() ]
83+
, startTime: new Date(2010, 11, 5, 14, 18, 30, 45)
84+
, categoryName: "cheese"
85+
, level: {
86+
colour: "green"
87+
, toString: function() { return "ERROR"; }
88+
}
89+
}).match(/Error\s+at Object\.<anonymous>\s+\((.*)test[\\\/]layouts-test\.js\:\d+\:\d+\)\s+at runTest/)
90+
, 'regexp did not return a match');
91+
},
92+
'with passed augmented errors':
93+
{ topic:
94+
function(layout){
95+
var e = new Error("My Unique Error Message");
96+
e.augmented = "My Unique attribute value"
97+
e.augObj = { at1: "at2" }
98+
return layout({
99+
data: [ e ]
100+
, startTime: new Date(2010, 11, 5, 14, 18, 30, 45)
101+
, categoryName: "cheese"
102+
, level: {
103+
colour: "green"
104+
, toString: function() { return "ERROR"; }
105+
}
106+
});
107+
},
108+
'should print error the contained error message': function(layoutOutput) {
109+
var m = layoutOutput.match(/\{ \[Error: My Unique Error Message\]/);
110+
assert.isArray(m);
111+
},
112+
'should print error augmented string attributes': function(layoutOutput) {
113+
var m = layoutOutput.match(/augmented:\s'My Unique attribute value'/);
114+
assert.isArray(m);
115+
},
116+
'should print error augmented object attributes': function(layoutOutput) {
117+
var m = layoutOutput.match(/augObj:\s\{ at1: 'at2' \}/);
118+
assert.isArray(m);
119+
}
79120
}
80121

122+
81123
},
82124

83125
'basicLayout': {
@@ -106,10 +148,11 @@ vows.describe('log4js layouts').addBatch({
106148
output = layout(event);
107149
lines = output.split(/\n/);
108150

109-
assert.equal(lines.length, stack.length);
110-
assert.equal(lines[0], "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error");
151+
assert.equal(lines.length - 1, stack.length);
152+
assert.equal(lines[0], "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]");
153+
111154
for (var i = 1; i < stack.length; i++) {
112-
assert.equal(lines[i+1], stack[i+1]);
155+
assert.equal(lines[i+2], stack[i+1]);
113156
}
114157
},
115158
'should output any extra data in the log event as util.inspect strings': function(args) {

0 commit comments

Comments
 (0)
0