-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
94 lines (78 loc) · 2.11 KB
/
index.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
/*
Shamelessly copied from https://github.com/mochajs/mocha/blob/master/lib/reporters/spec.js
*/
var fs = require('fs');
var sfx = require('sfx');
var Base = require('mocha/lib/reporters/base');
var inherits = require('mocha/lib/utils').inherits;
var color = Base.color;
var cursor = Base.cursor;
var trumpet = fs.readFileSync(__dirname + '/trumpet.txt', 'utf-8');
var microwave = fs.readFileSync(__dirname + '/microwave.txt', 'utf-8');
/**
* Expose `Spec` w/ a trumpet.
*/
exports = module.exports = Trumpet;
/**
* Initialize a new `Spec` test reporter.
*
* @api public
* @param {Runner} runner
*/
function Trumpet(runner) {
Base.call(this, runner);
var self = this;
var indents = 0;
var n = 0;
function indent() {
return Array(indents).join(' ');
}
runner.on('start', function() {
console.log();
});
runner.on('suite', function(suite) {
++indents;
console.log(color('suite', '%s%s'), indent(), suite.title);
});
runner.on('suite end', function() {
--indents;
if (indents === 1) {
console.log();
}
!this.stats.failures ? sfx.play(__dirname + '/success.m4a') : null;
});
runner.on('pending', function(test) {
var fmt = indent() + color('pending', ' - %s');
console.log(fmt, test.title);
});
runner.on('pass', function(test) {
var fmt;
if (test.speed === 'fast') {
fmt = indent()
+ color('checkmark', ' ' + Base.symbols.ok)
+ color('pass', ' %s');
cursor.CR();
console.log(fmt, test.title);
} else {
fmt = indent()
+ color('checkmark', ' ' + Base.symbols.ok)
+ color('pass', ' %s')
+ color(test.speed, ' (%dms)');
cursor.CR();
console.log(fmt, test.title, test.duration);
}
});
runner.on('fail', function(test) {
cursor.CR();
sfx.play(__dirname + '/sound.m4a', 20);
console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
});
runner.on('end', function() {
this.stats.failures ? console.log(trumpet) : console.log(microwave);
this.epilogue();
}.bind(self));
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Trumpet, Base);