/
noodleTestConsole.js
106 lines (92 loc) · 3.21 KB
/
noodleTestConsole.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module.exports = (function(test){
var sys = require('sys');
var color = require('ansi-color').set;
var out = this;
var lastDot = false;
var log = function(indent, text, colour) {
if (lastDot) {
sys.puts('');
}
var spaces = '';
var i=0;
for(i=0; i<indent; i++) {
spaces = spaces + ' ';
}
if (text.constructor == Array) {
text.forEach(function(tex){
if (colour) {
console.log(spaces + color(tex, colour));
} else {
console.log(spaces + tex);
}
});
} else {
if (colour) {
console.log(spaces + color(text, colour));
} else {
console.log(spaces + text);
}
}
lastDot = false
};
var dot = function(initialIndent, text) {
var spaces = '';
if (!lastDot) {
var i=0;
for(i=0; i<initialIndent; i++) {
spaces = spaces + ' ';
}
lastDot = true;
}
sys.print(spaces + text);
};
var last = null;
test.on('pushContext', function(o){
var contextIndent = o.context._depth();
log(contextIndent, color(o.context._name, "yellow"));
last = null;
});
// test.on('popContext', function(o){
// log(0, '');
// });
test.on('testStarted', function(t){
var contextIndent = t._context._depth();
log(contextIndent+1, "it " + color(t._name, "yellow"));
last = 'testStarted';
});
test.on('testTimeout', function(t){
var contextIndent = t._context._depth();
log(contextIndent, 'Did you remember to call done() for test "'+t._name+'"?', 'magenta');
log(contextIndent, 'Make sure you do. We don\'t print out the stack traces until done() has been called' +"\n", 'magenta');
last = null;
});
test.on('testDone', function(t){
var contextIndent = t._context._depth();
var n = t._failures.length || t._passes.length;
var message = (t._failures.length == 0) ? color(n + ' assertion'+(n==1?'':'s')+' passed','green') : color(n + ' assertion'+(n==1?'':'s')+" failed\n",'red');
log(contextIndent+2, message);
t._failures.forEach(function(assertion){
var callString = assertion.callString();
var failureMessage = assertion.failureMessage();
log(contextIndent+2, callString + ' : ' + failureMessage, 'red+bold');
log(contextIndent+2, assertion.stack, 'white');
log(0, '');
});
last = null;
});
test.on('testFlunk', function(o){
var contextIndent = o.context._depth();
log(contextIndent+2, o.context + ': '+color('Failed','red')+': ' + o.message);
last = null;
});
test.on('assertionPassed', function(o){
var contextIndent = o.context._depth();
dot(contextIndent+2, color('+','green'));
last = 'assertionPassed';
});
test.on('assertionFailed', function(o){
var contextIndent = o.context._depth();
dot(contextIndent+2, color('x','red'));
last = 'assertionFailed';
});
});