mocha 5.1.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +686 -984
- package/README.md +2 -1
- package/{images → assets/growl}/error.png +0 -0
- package/{images → assets/growl}/ok.png +0 -0
- package/bin/_mocha +4 -595
- package/bin/mocha +121 -61
- package/bin/options.js +6 -39
- package/browser-entry.js +21 -17
- package/lib/browser/growl.js +165 -2
- package/lib/browser/progress.js +11 -11
- package/lib/{template.html → browser/template.html} +0 -0
- package/lib/browser/tty.js +2 -2
- package/lib/cli/cli.js +68 -0
- package/lib/cli/commands.js +13 -0
- package/lib/cli/config.js +79 -0
- package/lib/cli/index.js +9 -0
- package/lib/cli/init.js +37 -0
- package/lib/cli/node-flags.js +69 -0
- package/lib/cli/one-and-dones.js +70 -0
- package/lib/cli/options.js +330 -0
- package/lib/cli/run-helpers.js +337 -0
- package/lib/cli/run-option-metadata.js +76 -0
- package/lib/cli/run.js +297 -0
- package/lib/context.js +14 -14
- package/lib/errors.js +141 -0
- package/lib/growl.js +136 -0
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +16 -13
- package/lib/interfaces/common.js +62 -18
- package/lib/interfaces/exports.js +5 -8
- package/lib/interfaces/qunit.js +10 -10
- package/lib/interfaces/tdd.js +12 -11
- package/lib/mocha.js +477 -256
- package/lib/mocharc.json +10 -0
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +95 -117
- package/lib/reporters/doc.js +23 -9
- package/lib/reporters/dot.js +19 -13
- package/lib/reporters/html.js +82 -47
- package/lib/reporters/json-stream.js +43 -23
- package/lib/reporters/json.js +32 -23
- package/lib/reporters/landing.js +16 -9
- package/lib/reporters/list.js +19 -11
- package/lib/reporters/markdown.js +18 -12
- package/lib/reporters/min.js +8 -4
- package/lib/reporters/nyan.js +42 -35
- package/lib/reporters/progress.js +12 -7
- package/lib/reporters/spec.js +23 -12
- package/lib/reporters/tap.js +250 -32
- package/lib/reporters/xunit.js +61 -35
- package/lib/runnable.js +152 -95
- package/lib/runner.js +296 -248
- package/lib/stats-collector.js +83 -0
- package/lib/suite.js +294 -75
- package/lib/test.js +16 -15
- package/lib/utils.js +419 -146
- package/mocha.js +4589 -2228
- package/package.json +137 -38
- package/lib/ms.js +0 -94
- package/lib/reporters/base.js.orig +0 -498
- package/lib/reporters/json.js.orig +0 -128
package/lib/reporters/list.js
CHANGED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
10
|
var inherits = require('../utils').inherits;
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
13
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
14
|
+
var EVENT_TEST_BEGIN = constants.EVENT_TEST_BEGIN;
|
|
15
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
16
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
17
|
+
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
|
11
18
|
var color = Base.color;
|
|
12
19
|
var cursor = Base.cursor;
|
|
13
20
|
|
|
@@ -24,46 +31,47 @@ exports = module.exports = List;
|
|
|
24
31
|
* @class
|
|
25
32
|
* @memberof Mocha.reporters
|
|
26
33
|
* @extends Mocha.reporters.Base
|
|
27
|
-
* @api public
|
|
28
34
|
* @param {Runner} runner
|
|
29
35
|
*/
|
|
30
|
-
function List
|
|
36
|
+
function List(runner) {
|
|
31
37
|
Base.call(this, runner);
|
|
32
38
|
|
|
33
39
|
var self = this;
|
|
34
40
|
var n = 0;
|
|
35
41
|
|
|
36
|
-
runner.on(
|
|
42
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
37
43
|
console.log();
|
|
38
44
|
});
|
|
39
45
|
|
|
40
|
-
runner.on(
|
|
46
|
+
runner.on(EVENT_TEST_BEGIN, function(test) {
|
|
41
47
|
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
|
42
48
|
});
|
|
43
49
|
|
|
44
|
-
runner.on(
|
|
45
|
-
var fmt = color('checkmark', ' -') +
|
|
46
|
-
color('pending', ' %s');
|
|
50
|
+
runner.on(EVENT_TEST_PENDING, function(test) {
|
|
51
|
+
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
|
47
52
|
console.log(fmt, test.fullTitle());
|
|
48
53
|
});
|
|
49
54
|
|
|
50
|
-
runner.on(
|
|
51
|
-
var fmt =
|
|
55
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
56
|
+
var fmt =
|
|
57
|
+
color('checkmark', ' ' + Base.symbols.ok) +
|
|
52
58
|
color('pass', ' %s: ') +
|
|
53
59
|
color(test.speed, '%dms');
|
|
54
60
|
cursor.CR();
|
|
55
61
|
console.log(fmt, test.fullTitle(), test.duration);
|
|
56
62
|
});
|
|
57
63
|
|
|
58
|
-
runner.on(
|
|
64
|
+
runner.on(EVENT_TEST_FAIL, function(test) {
|
|
59
65
|
cursor.CR();
|
|
60
66
|
console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
|
61
67
|
});
|
|
62
68
|
|
|
63
|
-
runner.once(
|
|
69
|
+
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
/**
|
|
67
73
|
* Inherit from `Base.prototype`.
|
|
68
74
|
*/
|
|
69
75
|
inherits(List, Base);
|
|
76
|
+
|
|
77
|
+
List.description = 'like "spec" reporter but flat';
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
10
|
var utils = require('../utils');
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
13
|
+
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
|
14
|
+
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
|
15
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* Constants
|
|
@@ -28,32 +33,31 @@ exports = module.exports = Markdown;
|
|
|
28
33
|
* @class
|
|
29
34
|
* @memberof Mocha.reporters
|
|
30
35
|
* @extends Mocha.reporters.Base
|
|
31
|
-
* @api public
|
|
32
36
|
* @param {Runner} runner
|
|
33
37
|
*/
|
|
34
|
-
function Markdown
|
|
38
|
+
function Markdown(runner) {
|
|
35
39
|
Base.call(this, runner);
|
|
36
40
|
|
|
37
41
|
var level = 0;
|
|
38
42
|
var buf = '';
|
|
39
43
|
|
|
40
|
-
function title
|
|
44
|
+
function title(str) {
|
|
41
45
|
return Array(level).join('#') + ' ' + str;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
function mapTOC
|
|
48
|
+
function mapTOC(suite, obj) {
|
|
45
49
|
var ret = obj;
|
|
46
50
|
var key = SUITE_PREFIX + suite.title;
|
|
47
51
|
|
|
48
|
-
obj = obj[key] = obj[key] || {
|
|
49
|
-
suite.suites.forEach(function
|
|
52
|
+
obj = obj[key] = obj[key] || {suite: suite};
|
|
53
|
+
suite.suites.forEach(function(suite) {
|
|
50
54
|
mapTOC(suite, obj);
|
|
51
55
|
});
|
|
52
56
|
|
|
53
57
|
return ret;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
function stringifyTOC
|
|
60
|
+
function stringifyTOC(obj, level) {
|
|
57
61
|
++level;
|
|
58
62
|
var buf = '';
|
|
59
63
|
var link;
|
|
@@ -71,25 +75,25 @@ function Markdown (runner) {
|
|
|
71
75
|
return buf;
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
function generateTOC
|
|
78
|
+
function generateTOC(suite) {
|
|
75
79
|
var obj = mapTOC(suite, {});
|
|
76
80
|
return stringifyTOC(obj, 0);
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
generateTOC(runner.suite);
|
|
80
84
|
|
|
81
|
-
runner.on(
|
|
85
|
+
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
|
82
86
|
++level;
|
|
83
87
|
var slug = utils.slug(suite.fullTitle());
|
|
84
88
|
buf += '<a name="' + slug + '"></a>' + '\n';
|
|
85
89
|
buf += title(suite.title) + '\n';
|
|
86
90
|
});
|
|
87
91
|
|
|
88
|
-
runner.on(
|
|
92
|
+
runner.on(EVENT_SUITE_END, function() {
|
|
89
93
|
--level;
|
|
90
94
|
});
|
|
91
95
|
|
|
92
|
-
runner.on(
|
|
96
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
93
97
|
var code = utils.clean(test.body);
|
|
94
98
|
buf += test.title + '.\n';
|
|
95
99
|
buf += '\n```js\n';
|
|
@@ -97,9 +101,11 @@ function Markdown (runner) {
|
|
|
97
101
|
buf += '```\n\n';
|
|
98
102
|
});
|
|
99
103
|
|
|
100
|
-
runner.once(
|
|
104
|
+
runner.once(EVENT_RUN_END, function() {
|
|
101
105
|
process.stdout.write('# TOC\n');
|
|
102
106
|
process.stdout.write(generateTOC(runner.suite));
|
|
103
107
|
process.stdout.write(buf);
|
|
104
108
|
});
|
|
105
109
|
}
|
|
110
|
+
|
|
111
|
+
Markdown.description = 'GitHub Flavored Markdown';
|
package/lib/reporters/min.js
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
10
|
var inherits = require('../utils').inherits;
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
13
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Expose `Min`.
|
|
@@ -22,23 +25,24 @@ exports = module.exports = Min;
|
|
|
22
25
|
* @class
|
|
23
26
|
* @memberof Mocha.reporters
|
|
24
27
|
* @extends Mocha.reporters.Base
|
|
25
|
-
* @api public
|
|
26
28
|
* @param {Runner} runner
|
|
27
29
|
*/
|
|
28
|
-
function Min
|
|
30
|
+
function Min(runner) {
|
|
29
31
|
Base.call(this, runner);
|
|
30
32
|
|
|
31
|
-
runner.on(
|
|
33
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
32
34
|
// clear screen
|
|
33
35
|
process.stdout.write('\u001b[2J');
|
|
34
36
|
// set cursor position
|
|
35
37
|
process.stdout.write('\u001b[1;3H');
|
|
36
38
|
});
|
|
37
39
|
|
|
38
|
-
runner.once(
|
|
40
|
+
runner.once(EVENT_RUN_END, this.epilogue.bind(this));
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
44
|
* Inherit from `Base.prototype`.
|
|
43
45
|
*/
|
|
44
46
|
inherits(Min, Base);
|
|
47
|
+
|
|
48
|
+
Min.description = 'essentially just a summary';
|
package/lib/reporters/nyan.js
CHANGED
|
@@ -7,7 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
|
+
var constants = require('../runner').constants;
|
|
10
11
|
var inherits = require('../utils').inherits;
|
|
12
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
13
|
+
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
|
14
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
15
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
16
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* Expose `Dot`.
|
|
@@ -19,19 +25,18 @@ exports = module.exports = NyanCat;
|
|
|
19
25
|
* Initialize a new `Dot` matrix test reporter.
|
|
20
26
|
*
|
|
21
27
|
* @param {Runner} runner
|
|
22
|
-
* @api public
|
|
23
28
|
* @public
|
|
24
29
|
* @class Nyan
|
|
25
30
|
* @memberof Mocha.reporters
|
|
26
31
|
* @extends Mocha.reporters.Base
|
|
27
32
|
*/
|
|
28
33
|
|
|
29
|
-
function NyanCat
|
|
34
|
+
function NyanCat(runner) {
|
|
30
35
|
Base.call(this, runner);
|
|
31
36
|
|
|
32
37
|
var self = this;
|
|
33
|
-
var width = Base.window.width * 0.75 | 0;
|
|
34
|
-
var nyanCatWidth = this.nyanCatWidth = 11;
|
|
38
|
+
var width = (Base.window.width * 0.75) | 0;
|
|
39
|
+
var nyanCatWidth = (this.nyanCatWidth = 11);
|
|
35
40
|
|
|
36
41
|
this.colorIndex = 0;
|
|
37
42
|
this.numberOfLines = 4;
|
|
@@ -39,26 +44,26 @@ function NyanCat (runner) {
|
|
|
39
44
|
this.scoreboardWidth = 5;
|
|
40
45
|
this.tick = 0;
|
|
41
46
|
this.trajectories = [[], [], [], []];
|
|
42
|
-
this.trajectoryWidthMax =
|
|
47
|
+
this.trajectoryWidthMax = width - nyanCatWidth;
|
|
43
48
|
|
|
44
|
-
runner.on(
|
|
49
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
45
50
|
Base.cursor.hide();
|
|
46
51
|
self.draw();
|
|
47
52
|
});
|
|
48
53
|
|
|
49
|
-
runner.on(
|
|
54
|
+
runner.on(EVENT_TEST_PENDING, function() {
|
|
50
55
|
self.draw();
|
|
51
56
|
});
|
|
52
57
|
|
|
53
|
-
runner.on(
|
|
58
|
+
runner.on(EVENT_TEST_PASS, function() {
|
|
54
59
|
self.draw();
|
|
55
60
|
});
|
|
56
61
|
|
|
57
|
-
runner.on(
|
|
62
|
+
runner.on(EVENT_TEST_FAIL, function() {
|
|
58
63
|
self.draw();
|
|
59
64
|
});
|
|
60
65
|
|
|
61
|
-
runner.once(
|
|
66
|
+
runner.once(EVENT_RUN_END, function() {
|
|
62
67
|
Base.cursor.show();
|
|
63
68
|
for (var i = 0; i < self.numberOfLines; i++) {
|
|
64
69
|
write('\n');
|
|
@@ -75,10 +80,10 @@ inherits(NyanCat, Base);
|
|
|
75
80
|
/**
|
|
76
81
|
* Draw the nyan cat
|
|
77
82
|
*
|
|
78
|
-
* @
|
|
83
|
+
* @private
|
|
79
84
|
*/
|
|
80
85
|
|
|
81
|
-
NyanCat.prototype.draw = function
|
|
86
|
+
NyanCat.prototype.draw = function() {
|
|
82
87
|
this.appendRainbow();
|
|
83
88
|
this.drawScoreboard();
|
|
84
89
|
this.drawRainbow();
|
|
@@ -90,13 +95,13 @@ NyanCat.prototype.draw = function () {
|
|
|
90
95
|
* Draw the "scoreboard" showing the number
|
|
91
96
|
* of passes, failures and pending tests.
|
|
92
97
|
*
|
|
93
|
-
* @
|
|
98
|
+
* @private
|
|
94
99
|
*/
|
|
95
100
|
|
|
96
|
-
NyanCat.prototype.drawScoreboard = function
|
|
101
|
+
NyanCat.prototype.drawScoreboard = function() {
|
|
97
102
|
var stats = this.stats;
|
|
98
103
|
|
|
99
|
-
function draw
|
|
104
|
+
function draw(type, n) {
|
|
100
105
|
write(' ');
|
|
101
106
|
write(Base.color(type, n));
|
|
102
107
|
write('\n');
|
|
@@ -113,10 +118,10 @@ NyanCat.prototype.drawScoreboard = function () {
|
|
|
113
118
|
/**
|
|
114
119
|
* Append the rainbow.
|
|
115
120
|
*
|
|
116
|
-
* @
|
|
121
|
+
* @private
|
|
117
122
|
*/
|
|
118
123
|
|
|
119
|
-
NyanCat.prototype.appendRainbow = function
|
|
124
|
+
NyanCat.prototype.appendRainbow = function() {
|
|
120
125
|
var segment = this.tick ? '_' : '-';
|
|
121
126
|
var rainbowified = this.rainbowify(segment);
|
|
122
127
|
|
|
@@ -132,13 +137,13 @@ NyanCat.prototype.appendRainbow = function () {
|
|
|
132
137
|
/**
|
|
133
138
|
* Draw the rainbow.
|
|
134
139
|
*
|
|
135
|
-
* @
|
|
140
|
+
* @private
|
|
136
141
|
*/
|
|
137
142
|
|
|
138
|
-
NyanCat.prototype.drawRainbow = function
|
|
143
|
+
NyanCat.prototype.drawRainbow = function() {
|
|
139
144
|
var self = this;
|
|
140
145
|
|
|
141
|
-
this.trajectories.forEach(function
|
|
146
|
+
this.trajectories.forEach(function(line) {
|
|
142
147
|
write('\u001b[' + self.scoreboardWidth + 'C');
|
|
143
148
|
write(line.join(''));
|
|
144
149
|
write('\n');
|
|
@@ -150,9 +155,9 @@ NyanCat.prototype.drawRainbow = function () {
|
|
|
150
155
|
/**
|
|
151
156
|
* Draw the nyan cat
|
|
152
157
|
*
|
|
153
|
-
* @
|
|
158
|
+
* @private
|
|
154
159
|
*/
|
|
155
|
-
NyanCat.prototype.drawNyanCat = function
|
|
160
|
+
NyanCat.prototype.drawNyanCat = function() {
|
|
156
161
|
var self = this;
|
|
157
162
|
var startWidth = this.scoreboardWidth + this.trajectories[0].length;
|
|
158
163
|
var dist = '\u001b[' + startWidth + 'C';
|
|
@@ -184,11 +189,11 @@ NyanCat.prototype.drawNyanCat = function () {
|
|
|
184
189
|
/**
|
|
185
190
|
* Draw nyan cat face.
|
|
186
191
|
*
|
|
187
|
-
* @
|
|
192
|
+
* @private
|
|
188
193
|
* @return {string}
|
|
189
194
|
*/
|
|
190
195
|
|
|
191
|
-
NyanCat.prototype.face = function
|
|
196
|
+
NyanCat.prototype.face = function() {
|
|
192
197
|
var stats = this.stats;
|
|
193
198
|
if (stats.failures) {
|
|
194
199
|
return '( x .x)';
|
|
@@ -203,37 +208,37 @@ NyanCat.prototype.face = function () {
|
|
|
203
208
|
/**
|
|
204
209
|
* Move cursor up `n`.
|
|
205
210
|
*
|
|
206
|
-
* @
|
|
211
|
+
* @private
|
|
207
212
|
* @param {number} n
|
|
208
213
|
*/
|
|
209
214
|
|
|
210
|
-
NyanCat.prototype.cursorUp = function
|
|
215
|
+
NyanCat.prototype.cursorUp = function(n) {
|
|
211
216
|
write('\u001b[' + n + 'A');
|
|
212
217
|
};
|
|
213
218
|
|
|
214
219
|
/**
|
|
215
220
|
* Move cursor down `n`.
|
|
216
221
|
*
|
|
217
|
-
* @
|
|
222
|
+
* @private
|
|
218
223
|
* @param {number} n
|
|
219
224
|
*/
|
|
220
225
|
|
|
221
|
-
NyanCat.prototype.cursorDown = function
|
|
226
|
+
NyanCat.prototype.cursorDown = function(n) {
|
|
222
227
|
write('\u001b[' + n + 'B');
|
|
223
228
|
};
|
|
224
229
|
|
|
225
230
|
/**
|
|
226
231
|
* Generate rainbow colors.
|
|
227
232
|
*
|
|
228
|
-
* @
|
|
233
|
+
* @private
|
|
229
234
|
* @return {Array}
|
|
230
235
|
*/
|
|
231
|
-
NyanCat.prototype.generateColors = function
|
|
236
|
+
NyanCat.prototype.generateColors = function() {
|
|
232
237
|
var colors = [];
|
|
233
238
|
|
|
234
|
-
for (var i = 0; i <
|
|
239
|
+
for (var i = 0; i < 6 * 7; i++) {
|
|
235
240
|
var pi3 = Math.floor(Math.PI / 3);
|
|
236
|
-
var n =
|
|
241
|
+
var n = i * (1.0 / 6);
|
|
237
242
|
var r = Math.floor(3 * Math.sin(n) + 3);
|
|
238
243
|
var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
|
|
239
244
|
var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
|
|
@@ -246,11 +251,11 @@ NyanCat.prototype.generateColors = function () {
|
|
|
246
251
|
/**
|
|
247
252
|
* Apply rainbow to the given `str`.
|
|
248
253
|
*
|
|
249
|
-
* @
|
|
254
|
+
* @private
|
|
250
255
|
* @param {string} str
|
|
251
256
|
* @return {string}
|
|
252
257
|
*/
|
|
253
|
-
NyanCat.prototype.rainbowify = function
|
|
258
|
+
NyanCat.prototype.rainbowify = function(str) {
|
|
254
259
|
if (!Base.useColors) {
|
|
255
260
|
return str;
|
|
256
261
|
}
|
|
@@ -264,6 +269,8 @@ NyanCat.prototype.rainbowify = function (str) {
|
|
|
264
269
|
*
|
|
265
270
|
* @param {string} string A message to write to stdout.
|
|
266
271
|
*/
|
|
267
|
-
function write
|
|
272
|
+
function write(string) {
|
|
268
273
|
process.stdout.write(string);
|
|
269
274
|
}
|
|
275
|
+
|
|
276
|
+
NyanCat.description = '"nyan cat"';
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
|
+
var constants = require('../runner').constants;
|
|
11
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
12
|
+
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
|
13
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
10
14
|
var inherits = require('../utils').inherits;
|
|
11
15
|
var color = Base.color;
|
|
12
16
|
var cursor = Base.cursor;
|
|
@@ -30,15 +34,14 @@ Base.colors.progress = 90;
|
|
|
30
34
|
* @class
|
|
31
35
|
* @memberof Mocha.reporters
|
|
32
36
|
* @extends Mocha.reporters.Base
|
|
33
|
-
* @api public
|
|
34
37
|
* @param {Runner} runner
|
|
35
38
|
* @param {Object} options
|
|
36
39
|
*/
|
|
37
|
-
function Progress
|
|
40
|
+
function Progress(runner, options) {
|
|
38
41
|
Base.call(this, runner);
|
|
39
42
|
|
|
40
43
|
var self = this;
|
|
41
|
-
var width = Base.window.width * 0.
|
|
44
|
+
var width = (Base.window.width * 0.5) | 0;
|
|
42
45
|
var total = runner.total;
|
|
43
46
|
var complete = 0;
|
|
44
47
|
var lastN = -1;
|
|
@@ -54,17 +57,17 @@ function Progress (runner, options) {
|
|
|
54
57
|
options.verbose = reporterOptions.verbose || false;
|
|
55
58
|
|
|
56
59
|
// tests started
|
|
57
|
-
runner.on(
|
|
60
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
58
61
|
console.log();
|
|
59
62
|
cursor.hide();
|
|
60
63
|
});
|
|
61
64
|
|
|
62
65
|
// tests complete
|
|
63
|
-
runner.on(
|
|
66
|
+
runner.on(EVENT_TEST_END, function() {
|
|
64
67
|
complete++;
|
|
65
68
|
|
|
66
69
|
var percent = complete / total;
|
|
67
|
-
var n = width * percent | 0;
|
|
70
|
+
var n = (width * percent) | 0;
|
|
68
71
|
var i = width - n;
|
|
69
72
|
|
|
70
73
|
if (n === lastN && !options.verbose) {
|
|
@@ -86,7 +89,7 @@ function Progress (runner, options) {
|
|
|
86
89
|
|
|
87
90
|
// tests are complete, output some stats
|
|
88
91
|
// and the failures if any
|
|
89
|
-
runner.once(
|
|
92
|
+
runner.once(EVENT_RUN_END, function() {
|
|
90
93
|
cursor.show();
|
|
91
94
|
console.log();
|
|
92
95
|
self.epilogue();
|
|
@@ -97,3 +100,5 @@ function Progress (runner, options) {
|
|
|
97
100
|
* Inherit from `Base.prototype`.
|
|
98
101
|
*/
|
|
99
102
|
inherits(Progress, Base);
|
|
103
|
+
|
|
104
|
+
Progress.description = 'a progress bar';
|
package/lib/reporters/spec.js
CHANGED
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
|
+
var constants = require('../runner').constants;
|
|
11
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
12
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
13
|
+
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
|
14
|
+
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
|
15
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
16
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
17
|
+
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
|
10
18
|
var inherits = require('../utils').inherits;
|
|
11
19
|
var color = Base.color;
|
|
12
20
|
|
|
@@ -23,50 +31,51 @@ exports = module.exports = Spec;
|
|
|
23
31
|
* @class
|
|
24
32
|
* @memberof Mocha.reporters
|
|
25
33
|
* @extends Mocha.reporters.Base
|
|
26
|
-
* @api public
|
|
27
34
|
* @param {Runner} runner
|
|
28
35
|
*/
|
|
29
|
-
function Spec
|
|
36
|
+
function Spec(runner) {
|
|
30
37
|
Base.call(this, runner);
|
|
31
38
|
|
|
32
39
|
var self = this;
|
|
33
40
|
var indents = 0;
|
|
34
41
|
var n = 0;
|
|
35
42
|
|
|
36
|
-
function indent
|
|
43
|
+
function indent() {
|
|
37
44
|
return Array(indents).join(' ');
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
runner.on(
|
|
47
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
41
48
|
console.log();
|
|
42
49
|
});
|
|
43
50
|
|
|
44
|
-
runner.on(
|
|
51
|
+
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
|
45
52
|
++indents;
|
|
46
53
|
console.log(color('suite', '%s%s'), indent(), suite.title);
|
|
47
54
|
});
|
|
48
55
|
|
|
49
|
-
runner.on(
|
|
56
|
+
runner.on(EVENT_SUITE_END, function() {
|
|
50
57
|
--indents;
|
|
51
58
|
if (indents === 1) {
|
|
52
59
|
console.log();
|
|
53
60
|
}
|
|
54
61
|
});
|
|
55
62
|
|
|
56
|
-
runner.on(
|
|
63
|
+
runner.on(EVENT_TEST_PENDING, function(test) {
|
|
57
64
|
var fmt = indent() + color('pending', ' - %s');
|
|
58
65
|
console.log(fmt, test.title);
|
|
59
66
|
});
|
|
60
67
|
|
|
61
|
-
runner.on(
|
|
68
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
62
69
|
var fmt;
|
|
63
70
|
if (test.speed === 'fast') {
|
|
64
|
-
fmt =
|
|
71
|
+
fmt =
|
|
72
|
+
indent() +
|
|
65
73
|
color('checkmark', ' ' + Base.symbols.ok) +
|
|
66
74
|
color('pass', ' %s');
|
|
67
75
|
console.log(fmt, test.title);
|
|
68
76
|
} else {
|
|
69
|
-
fmt =
|
|
77
|
+
fmt =
|
|
78
|
+
indent() +
|
|
70
79
|
color('checkmark', ' ' + Base.symbols.ok) +
|
|
71
80
|
color('pass', ' %s') +
|
|
72
81
|
color(test.speed, ' (%dms)');
|
|
@@ -74,14 +83,16 @@ function Spec (runner) {
|
|
|
74
83
|
}
|
|
75
84
|
});
|
|
76
85
|
|
|
77
|
-
runner.on(
|
|
86
|
+
runner.on(EVENT_TEST_FAIL, function(test) {
|
|
78
87
|
console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
|
|
79
88
|
});
|
|
80
89
|
|
|
81
|
-
runner.once(
|
|
90
|
+
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
|
82
91
|
}
|
|
83
92
|
|
|
84
93
|
/**
|
|
85
94
|
* Inherit from `Base.prototype`.
|
|
86
95
|
*/
|
|
87
96
|
inherits(Spec, Base);
|
|
97
|
+
|
|
98
|
+
Spec.description = 'hierarchical & verbose [default]';
|