-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebkit.js
131 lines (105 loc) · 2.86 KB
/
webkit.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Styles.
*/
var styles = {
bold: 'font-weight:bold;',
normal: 'font-weight:normal;',
success: 'color:green;',
pending: 'color:blue;',
fail: 'color:red;',
suite: 'font-weight:bold;',
slow: 'color:white; background:red; border-radius:5px; padding:0 4px;',
medium: 'color:white; background:orange; border-radius:5px; padding:0 4px;'
};
/**
* Module dependencies.
*/
var Base = require('./base');
/**
* Expose `WebKit`.
*/
exports = module.exports = WebKit;
/**
* Initialize a new `WebKit` test reporter.
*
* @param {Runner} runner
* @api public
*/
function WebKit(runner) {
Base.call(this, runner);
var self = this
, stats = this.stats
, failures = 0;
runner.on('start', function(){
console.time('duration');
});
runner.on('suite', function(suite){
if (suite.root) return;
console.group('%c'+suite.title, styles.suite);
});
runner.on('suite end', function(suite){
if (suite.root) return;
console.groupEnd();
});
runner.on('pending', function(test){
console.log('%c- '+test.title, styles.pending);
});
runner.on('pass', function(test){
if ('fast' == test.speed) {
console.log('%c'+Base.symbols.ok+' '+test.title, styles.success);
}
else if ('medium' == test.speed) {
console.log('%c'+Base.symbols.ok+' '+test.title+' %c'+test.duration,
styles.success, styles.medium);
}
else {
console.log('%c'+Base.symbols.ok+' '+test.title+' %c'+test.duration,
styles.success, styles.slow);
}
});
runner.on('fail', function(test, err){
console.error(++failures+') '+test.title+'%O', err);
});
runner.on('end', function() {
var stats = this.stats;
// duration
console.timeEnd('duration');
// passes
console.log('%c'+(stats.passes||0)+' passing', styles.success);
// pending
if (stats.pending) {
console.log('%c'+stats.pending+' pending', styles.pending);
}
// failures
if (stats.failures) {
console.log('%c'+stats.failures+' failing', 'color:red;');
errors.call(this, this.failures);
}
}.bind(this));
function errors(failures){
failures.forEach(function(test, i){
// msg
var err = test.err
, message = err.message || ''
, stack = err.stack || message
, index = stack.indexOf(message) + message.length
, msg = stack.slice(0, index)
, actual = err.actual
, expected = err.expected
, escape = true;
// uncaught
if (err.uncaught) {
msg = 'Uncaught ' + msg;
}
// indent stack trace without msg
stack = stack.slice(index ? index + 1 : index)
.replace(/^/gm, ' ');
console.error((i + 1)+') '+test.fullTitle()+'\n%c'+msg+'\n%c'+stack,
styles.bold, styles.normal);
});
}
}
/**
* Inherit from `Base.prototype`.
*/
WebKit.prototype.__proto__ = Base.prototype;