mocha 5.1.0 → 6.0.0-1
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 +653 -981
- 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 +84 -58
- package/bin/options.js +6 -39
- package/browser-entry.js +21 -17
- package/lib/browser/growl.js +164 -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 +48 -0
- package/lib/cli/one-and-dones.js +70 -0
- package/lib/cli/options.js +299 -0
- package/lib/cli/run-helpers.js +328 -0
- package/lib/cli/run-option-metadata.js +72 -0
- package/lib/cli/run.js +293 -0
- package/lib/context.js +14 -14
- package/lib/errors.js +139 -0
- package/lib/growl.js +135 -0
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +14 -13
- package/lib/interfaces/common.js +59 -16
- package/lib/interfaces/exports.js +4 -7
- package/lib/interfaces/qunit.js +8 -10
- package/lib/interfaces/tdd.js +10 -11
- package/lib/mocha.js +442 -255
- package/lib/mocharc.json +10 -0
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +92 -117
- package/lib/reporters/doc.js +18 -9
- package/lib/reporters/dot.js +13 -13
- package/lib/reporters/html.js +76 -47
- package/lib/reporters/json-stream.js +38 -23
- package/lib/reporters/json.js +26 -23
- package/lib/reporters/landing.js +9 -8
- package/lib/reporters/list.js +11 -10
- package/lib/reporters/markdown.js +13 -12
- package/lib/reporters/min.js +4 -3
- package/lib/reporters/nyan.js +36 -35
- package/lib/reporters/progress.js +8 -7
- package/lib/reporters/spec.js +14 -11
- package/lib/reporters/tap.js +243 -32
- package/lib/reporters/xunit.js +52 -33
- package/lib/runnable.js +103 -90
- package/lib/runner.js +156 -107
- package/lib/stats-collector.js +81 -0
- package/lib/suite.js +57 -51
- package/lib/test.js +13 -13
- package/lib/utils.js +192 -103
- package/mocha.js +3836 -2046
- package/package.json +122 -38
- package/bin/.eslintrc.yml +0 -3
- package/lib/browser/.eslintrc.yml +0 -4
- 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/html.js
CHANGED
|
@@ -18,13 +18,7 @@ var escape = utils.escape;
|
|
|
18
18
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
/* eslint-disable no-unused-vars, no-native-reassign */
|
|
22
21
|
var Date = global.Date;
|
|
23
|
-
var setTimeout = global.setTimeout;
|
|
24
|
-
var setInterval = global.setInterval;
|
|
25
|
-
var clearTimeout = global.clearTimeout;
|
|
26
|
-
var clearInterval = global.clearInterval;
|
|
27
|
-
/* eslint-enable no-unused-vars, no-native-reassign */
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
24
|
* Expose `HTML`.
|
|
@@ -36,7 +30,8 @@ exports = module.exports = HTML;
|
|
|
36
30
|
* Stats template.
|
|
37
31
|
*/
|
|
38
32
|
|
|
39
|
-
var statsTemplate =
|
|
33
|
+
var statsTemplate =
|
|
34
|
+
'<ul id="mocha-stats">' +
|
|
40
35
|
'<li class="progress"><canvas width="40" height="40"></canvas></li>' +
|
|
41
36
|
'<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
|
|
42
37
|
'<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
|
|
@@ -52,10 +47,9 @@ var playIcon = '‣';
|
|
|
52
47
|
* @class
|
|
53
48
|
* @memberof Mocha.reporters
|
|
54
49
|
* @extends Mocha.reporters.Base
|
|
55
|
-
* @api public
|
|
56
50
|
* @param {Runner} runner
|
|
57
51
|
*/
|
|
58
|
-
function HTML
|
|
52
|
+
function HTML(runner) {
|
|
59
53
|
Base.call(this, runner);
|
|
60
54
|
|
|
61
55
|
var self = this;
|
|
@@ -90,10 +84,10 @@ function HTML (runner) {
|
|
|
90
84
|
}
|
|
91
85
|
|
|
92
86
|
// pass toggle
|
|
93
|
-
on(passesLink, 'click', function
|
|
87
|
+
on(passesLink, 'click', function(evt) {
|
|
94
88
|
evt.preventDefault();
|
|
95
89
|
unhide();
|
|
96
|
-
var name =
|
|
90
|
+
var name = /pass/.test(report.className) ? '' : ' pass';
|
|
97
91
|
report.className = report.className.replace(/fail|pass/g, '') + name;
|
|
98
92
|
if (report.className.trim()) {
|
|
99
93
|
hideSuitesWithout('test pass');
|
|
@@ -101,10 +95,10 @@ function HTML (runner) {
|
|
|
101
95
|
});
|
|
102
96
|
|
|
103
97
|
// failure toggle
|
|
104
|
-
on(failuresLink, 'click', function
|
|
98
|
+
on(failuresLink, 'click', function(evt) {
|
|
105
99
|
evt.preventDefault();
|
|
106
100
|
unhide();
|
|
107
|
-
var name =
|
|
101
|
+
var name = /fail/.test(report.className) ? '' : ' fail';
|
|
108
102
|
report.className = report.className.replace(/fail|pass/g, '') + name;
|
|
109
103
|
if (report.className.trim()) {
|
|
110
104
|
hideSuitesWithout('test fail');
|
|
@@ -118,14 +112,18 @@ function HTML (runner) {
|
|
|
118
112
|
progress.size(40);
|
|
119
113
|
}
|
|
120
114
|
|
|
121
|
-
runner.on('suite', function
|
|
115
|
+
runner.on('suite', function(suite) {
|
|
122
116
|
if (suite.root) {
|
|
123
117
|
return;
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
// suite
|
|
127
121
|
var url = self.suiteURL(suite);
|
|
128
|
-
var el = fragment(
|
|
122
|
+
var el = fragment(
|
|
123
|
+
'<li class="suite"><h1><a href="%s">%s</a></h1></li>',
|
|
124
|
+
url,
|
|
125
|
+
escape(suite.title)
|
|
126
|
+
);
|
|
129
127
|
|
|
130
128
|
// container
|
|
131
129
|
stack[0].appendChild(el);
|
|
@@ -133,7 +131,7 @@ function HTML (runner) {
|
|
|
133
131
|
el.appendChild(stack[0]);
|
|
134
132
|
});
|
|
135
133
|
|
|
136
|
-
runner.on('suite end', function
|
|
134
|
+
runner.on('suite end', function(suite) {
|
|
137
135
|
if (suite.root) {
|
|
138
136
|
updateStats();
|
|
139
137
|
return;
|
|
@@ -141,19 +139,27 @@ function HTML (runner) {
|
|
|
141
139
|
stack.shift();
|
|
142
140
|
});
|
|
143
141
|
|
|
144
|
-
runner.on('pass', function
|
|
142
|
+
runner.on('pass', function(test) {
|
|
145
143
|
var url = self.testURL(test);
|
|
146
|
-
var markup =
|
|
147
|
-
'<
|
|
144
|
+
var markup =
|
|
145
|
+
'<li class="test pass %e"><h2>%e<span class="duration">%ems</span> ' +
|
|
146
|
+
'<a href="%s" class="replay">' +
|
|
147
|
+
playIcon +
|
|
148
|
+
'</a></h2></li>';
|
|
148
149
|
var el = fragment(markup, test.speed, test.title, test.duration, url);
|
|
149
150
|
self.addCodeToggle(el, test.body);
|
|
150
151
|
appendToStack(el);
|
|
151
152
|
updateStats();
|
|
152
153
|
});
|
|
153
154
|
|
|
154
|
-
runner.on('fail', function
|
|
155
|
-
var el = fragment(
|
|
156
|
-
test
|
|
155
|
+
runner.on('fail', function(test) {
|
|
156
|
+
var el = fragment(
|
|
157
|
+
'<li class="test fail"><h2>%e <a href="%e" class="replay">' +
|
|
158
|
+
playIcon +
|
|
159
|
+
'</a></h2></li>',
|
|
160
|
+
test.title,
|
|
161
|
+
self.testURL(test)
|
|
162
|
+
);
|
|
157
163
|
var stackString; // Note: Includes leading newline
|
|
158
164
|
var message = test.err.toString();
|
|
159
165
|
|
|
@@ -168,7 +174,9 @@ function HTML (runner) {
|
|
|
168
174
|
if (indexOfMessage === -1) {
|
|
169
175
|
stackString = test.err.stack;
|
|
170
176
|
} else {
|
|
171
|
-
stackString = test.err.stack.substr(
|
|
177
|
+
stackString = test.err.stack.substr(
|
|
178
|
+
test.err.message.length + indexOfMessage
|
|
179
|
+
);
|
|
172
180
|
}
|
|
173
181
|
} else if (test.err.sourceURL && test.err.line !== undefined) {
|
|
174
182
|
// Safari doesn't give you a stack. Let's at least provide a source line.
|
|
@@ -178,12 +186,21 @@ function HTML (runner) {
|
|
|
178
186
|
stackString = stackString || '';
|
|
179
187
|
|
|
180
188
|
if (test.err.htmlMessage && stackString) {
|
|
181
|
-
el.appendChild(
|
|
182
|
-
|
|
189
|
+
el.appendChild(
|
|
190
|
+
fragment(
|
|
191
|
+
'<div class="html-error">%s\n<pre class="error">%e</pre></div>',
|
|
192
|
+
test.err.htmlMessage,
|
|
193
|
+
stackString
|
|
194
|
+
)
|
|
195
|
+
);
|
|
183
196
|
} else if (test.err.htmlMessage) {
|
|
184
|
-
el.appendChild(
|
|
197
|
+
el.appendChild(
|
|
198
|
+
fragment('<div class="html-error">%s</div>', test.err.htmlMessage)
|
|
199
|
+
);
|
|
185
200
|
} else {
|
|
186
|
-
el.appendChild(
|
|
201
|
+
el.appendChild(
|
|
202
|
+
fragment('<pre class="error">%e%e</pre>', message, stackString)
|
|
203
|
+
);
|
|
187
204
|
}
|
|
188
205
|
|
|
189
206
|
self.addCodeToggle(el, test.body);
|
|
@@ -191,22 +208,25 @@ function HTML (runner) {
|
|
|
191
208
|
updateStats();
|
|
192
209
|
});
|
|
193
210
|
|
|
194
|
-
runner.on('pending', function
|
|
195
|
-
var el = fragment(
|
|
211
|
+
runner.on('pending', function(test) {
|
|
212
|
+
var el = fragment(
|
|
213
|
+
'<li class="test pass pending"><h2>%e</h2></li>',
|
|
214
|
+
test.title
|
|
215
|
+
);
|
|
196
216
|
appendToStack(el);
|
|
197
217
|
updateStats();
|
|
198
218
|
});
|
|
199
219
|
|
|
200
|
-
function appendToStack
|
|
220
|
+
function appendToStack(el) {
|
|
201
221
|
// Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
|
|
202
222
|
if (stack[0]) {
|
|
203
223
|
stack[0].appendChild(el);
|
|
204
224
|
}
|
|
205
225
|
}
|
|
206
226
|
|
|
207
|
-
function updateStats
|
|
227
|
+
function updateStats() {
|
|
208
228
|
// TODO: add to stats
|
|
209
|
-
var percent = stats.tests / runner.total * 100 | 0;
|
|
229
|
+
var percent = ((stats.tests / runner.total) * 100) | 0;
|
|
210
230
|
if (progress) {
|
|
211
231
|
progress.update(percent).draw(ctx);
|
|
212
232
|
}
|
|
@@ -225,7 +245,7 @@ function HTML (runner) {
|
|
|
225
245
|
* @param {string} s
|
|
226
246
|
* @return {string} A new URL.
|
|
227
247
|
*/
|
|
228
|
-
function makeUrl
|
|
248
|
+
function makeUrl(s) {
|
|
229
249
|
var search = window.location.search;
|
|
230
250
|
|
|
231
251
|
// Remove previous grep query parameter if present
|
|
@@ -233,7 +253,12 @@ function makeUrl (s) {
|
|
|
233
253
|
search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
|
|
234
254
|
}
|
|
235
255
|
|
|
236
|
-
return
|
|
256
|
+
return (
|
|
257
|
+
window.location.pathname +
|
|
258
|
+
(search ? search + '&' : '?') +
|
|
259
|
+
'grep=' +
|
|
260
|
+
encodeURIComponent(escapeRe(s))
|
|
261
|
+
);
|
|
237
262
|
}
|
|
238
263
|
|
|
239
264
|
/**
|
|
@@ -241,7 +266,7 @@ function makeUrl (s) {
|
|
|
241
266
|
*
|
|
242
267
|
* @param {Object} [suite]
|
|
243
268
|
*/
|
|
244
|
-
HTML.prototype.suiteURL = function
|
|
269
|
+
HTML.prototype.suiteURL = function(suite) {
|
|
245
270
|
return makeUrl(suite.fullTitle());
|
|
246
271
|
};
|
|
247
272
|
|
|
@@ -250,7 +275,7 @@ HTML.prototype.suiteURL = function (suite) {
|
|
|
250
275
|
*
|
|
251
276
|
* @param {Object} [test]
|
|
252
277
|
*/
|
|
253
|
-
HTML.prototype.testURL = function
|
|
278
|
+
HTML.prototype.testURL = function(test) {
|
|
254
279
|
return makeUrl(test.fullTitle());
|
|
255
280
|
};
|
|
256
281
|
|
|
@@ -260,10 +285,10 @@ HTML.prototype.testURL = function (test) {
|
|
|
260
285
|
* @param {HTMLLIElement} el
|
|
261
286
|
* @param {string} contents
|
|
262
287
|
*/
|
|
263
|
-
HTML.prototype.addCodeToggle = function
|
|
288
|
+
HTML.prototype.addCodeToggle = function(el, contents) {
|
|
264
289
|
var h2 = el.getElementsByTagName('h2')[0];
|
|
265
290
|
|
|
266
|
-
on(h2, 'click', function
|
|
291
|
+
on(h2, 'click', function() {
|
|
267
292
|
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
|
|
268
293
|
});
|
|
269
294
|
|
|
@@ -277,7 +302,7 @@ HTML.prototype.addCodeToggle = function (el, contents) {
|
|
|
277
302
|
*
|
|
278
303
|
* @param {string} msg
|
|
279
304
|
*/
|
|
280
|
-
function error
|
|
305
|
+
function error(msg) {
|
|
281
306
|
document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
|
|
282
307
|
}
|
|
283
308
|
|
|
@@ -286,15 +311,17 @@ function error (msg) {
|
|
|
286
311
|
*
|
|
287
312
|
* @param {string} html
|
|
288
313
|
*/
|
|
289
|
-
function fragment
|
|
314
|
+
function fragment(html) {
|
|
290
315
|
var args = arguments;
|
|
291
316
|
var div = document.createElement('div');
|
|
292
317
|
var i = 1;
|
|
293
318
|
|
|
294
|
-
div.innerHTML = html.replace(/%([se])/g, function
|
|
319
|
+
div.innerHTML = html.replace(/%([se])/g, function(_, type) {
|
|
295
320
|
switch (type) {
|
|
296
|
-
case 's':
|
|
297
|
-
|
|
321
|
+
case 's':
|
|
322
|
+
return String(args[i++]);
|
|
323
|
+
case 'e':
|
|
324
|
+
return escape(args[i++]);
|
|
298
325
|
// no default
|
|
299
326
|
}
|
|
300
327
|
});
|
|
@@ -308,7 +335,7 @@ function fragment (html) {
|
|
|
308
335
|
*
|
|
309
336
|
* @param {text} classname
|
|
310
337
|
*/
|
|
311
|
-
function hideSuitesWithout
|
|
338
|
+
function hideSuitesWithout(classname) {
|
|
312
339
|
var suites = document.getElementsByClassName('suite');
|
|
313
340
|
for (var i = 0; i < suites.length; i++) {
|
|
314
341
|
var els = suites[i].getElementsByClassName(classname);
|
|
@@ -321,7 +348,7 @@ function hideSuitesWithout (classname) {
|
|
|
321
348
|
/**
|
|
322
349
|
* Unhide .hidden suites.
|
|
323
350
|
*/
|
|
324
|
-
function unhide
|
|
351
|
+
function unhide() {
|
|
325
352
|
var els = document.getElementsByClassName('suite hidden');
|
|
326
353
|
for (var i = 0; i < els.length; ++i) {
|
|
327
354
|
els[i].className = els[i].className.replace('suite hidden', 'suite');
|
|
@@ -334,7 +361,7 @@ function unhide () {
|
|
|
334
361
|
* @param {HTMLElement} el
|
|
335
362
|
* @param {string} contents
|
|
336
363
|
*/
|
|
337
|
-
function text
|
|
364
|
+
function text(el, contents) {
|
|
338
365
|
if (el.textContent) {
|
|
339
366
|
el.textContent = contents;
|
|
340
367
|
} else {
|
|
@@ -345,10 +372,12 @@ function text (el, contents) {
|
|
|
345
372
|
/**
|
|
346
373
|
* Listen on `event` with callback `fn`.
|
|
347
374
|
*/
|
|
348
|
-
function on
|
|
375
|
+
function on(el, event, fn) {
|
|
349
376
|
if (el.addEventListener) {
|
|
350
377
|
el.addEventListener(event, fn, false);
|
|
351
378
|
} else {
|
|
352
379
|
el.attachEvent('on' + event, fn);
|
|
353
380
|
}
|
|
354
381
|
}
|
|
382
|
+
|
|
383
|
+
HTML.browserOnly = true;
|
|
@@ -9,57 +9,70 @@
|
|
|
9
9
|
var Base = require('./base');
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Expose `
|
|
12
|
+
* Expose `JSONStream`.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
exports = module.exports =
|
|
15
|
+
exports = module.exports = JSONStream;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Constructs a new `JSONStream` reporter instance.
|
|
19
19
|
*
|
|
20
20
|
* @public
|
|
21
|
-
* @
|
|
22
|
-
* @class JSONStream
|
|
23
|
-
* @memberof Mocha.reporters
|
|
21
|
+
* @class
|
|
24
22
|
* @extends Mocha.reporters.Base
|
|
25
|
-
* @
|
|
26
|
-
* @param {Runner} runner
|
|
23
|
+
* @memberof Mocha.reporters
|
|
24
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
27
25
|
*/
|
|
28
|
-
function
|
|
26
|
+
function JSONStream(runner) {
|
|
29
27
|
Base.call(this, runner);
|
|
30
28
|
|
|
31
29
|
var self = this;
|
|
32
30
|
var total = runner.total;
|
|
33
31
|
|
|
34
|
-
runner.
|
|
35
|
-
|
|
32
|
+
runner.once('start', function() {
|
|
33
|
+
writeEvent(['start', {total: total}]);
|
|
36
34
|
});
|
|
37
35
|
|
|
38
|
-
runner.on('pass', function
|
|
39
|
-
|
|
36
|
+
runner.on('pass', function(test) {
|
|
37
|
+
writeEvent(['pass', clean(test)]);
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
runner.on('fail', function
|
|
40
|
+
runner.on('fail', function(test, err) {
|
|
43
41
|
test = clean(test);
|
|
44
42
|
test.err = err.message;
|
|
45
43
|
test.stack = err.stack || null;
|
|
46
|
-
|
|
44
|
+
writeEvent(['fail', test]);
|
|
47
45
|
});
|
|
48
46
|
|
|
49
|
-
runner.once('end', function
|
|
50
|
-
|
|
47
|
+
runner.once('end', function() {
|
|
48
|
+
writeEvent(['end', self.stats]);
|
|
51
49
|
});
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
53
|
+
* Mocha event to be written to the output stream.
|
|
54
|
+
* @typedef {Array} JSONStream~MochaEvent
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Writes Mocha event to reporter output stream.
|
|
57
59
|
*
|
|
58
|
-
* @
|
|
59
|
-
* @param {
|
|
60
|
-
* @return {Object}
|
|
60
|
+
* @private
|
|
61
|
+
* @param {JSONStream~MochaEvent} event - Mocha event to be output.
|
|
61
62
|
*/
|
|
62
|
-
function
|
|
63
|
+
function writeEvent(event) {
|
|
64
|
+
process.stdout.write(JSON.stringify(event) + '\n');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns an object literal representation of `test`
|
|
69
|
+
* free of cyclic properties, etc.
|
|
70
|
+
*
|
|
71
|
+
* @private
|
|
72
|
+
* @param {Test} test - Instance used as data source.
|
|
73
|
+
* @return {Object} object containing pared-down test instance data
|
|
74
|
+
*/
|
|
75
|
+
function clean(test) {
|
|
63
76
|
return {
|
|
64
77
|
title: test.title,
|
|
65
78
|
fullTitle: test.fullTitle(),
|
|
@@ -67,3 +80,5 @@ function clean (test) {
|
|
|
67
80
|
currentRetry: test.currentRetry()
|
|
68
81
|
};
|
|
69
82
|
}
|
|
83
|
+
|
|
84
|
+
JSONStream.description = 'newline delimited JSON events';
|
package/lib/reporters/json.js
CHANGED
|
@@ -21,10 +21,9 @@ exports = module.exports = JSONReporter;
|
|
|
21
21
|
* @class JSON
|
|
22
22
|
* @memberof Mocha.reporters
|
|
23
23
|
* @extends Mocha.reporters.Base
|
|
24
|
-
* @api public
|
|
25
24
|
* @param {Runner} runner
|
|
26
25
|
*/
|
|
27
|
-
function JSONReporter
|
|
26
|
+
function JSONReporter(runner) {
|
|
28
27
|
Base.call(this, runner);
|
|
29
28
|
|
|
30
29
|
var self = this;
|
|
@@ -33,23 +32,23 @@ function JSONReporter (runner) {
|
|
|
33
32
|
var failures = [];
|
|
34
33
|
var passes = [];
|
|
35
34
|
|
|
36
|
-
runner.on('test end', function
|
|
35
|
+
runner.on('test end', function(test) {
|
|
37
36
|
tests.push(test);
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
runner.on('pass', function
|
|
39
|
+
runner.on('pass', function(test) {
|
|
41
40
|
passes.push(test);
|
|
42
41
|
});
|
|
43
42
|
|
|
44
|
-
runner.on('fail', function
|
|
43
|
+
runner.on('fail', function(test) {
|
|
45
44
|
failures.push(test);
|
|
46
45
|
});
|
|
47
46
|
|
|
48
|
-
runner.on('pending', function
|
|
47
|
+
runner.on('pending', function(test) {
|
|
49
48
|
pending.push(test);
|
|
50
49
|
});
|
|
51
50
|
|
|
52
|
-
runner.once('end', function
|
|
51
|
+
runner.once('end', function() {
|
|
53
52
|
var obj = {
|
|
54
53
|
stats: self.stats,
|
|
55
54
|
tests: tests.map(clean),
|
|
@@ -68,11 +67,11 @@ function JSONReporter (runner) {
|
|
|
68
67
|
* Return a plain-object representation of `test`
|
|
69
68
|
* free of cyclic properties etc.
|
|
70
69
|
*
|
|
71
|
-
* @
|
|
70
|
+
* @private
|
|
72
71
|
* @param {Object} test
|
|
73
72
|
* @return {Object}
|
|
74
73
|
*/
|
|
75
|
-
function clean
|
|
74
|
+
function clean(test) {
|
|
76
75
|
var err = test.err || {};
|
|
77
76
|
if (err instanceof Error) {
|
|
78
77
|
err = errorJSON(err);
|
|
@@ -90,36 +89,40 @@ function clean (test) {
|
|
|
90
89
|
/**
|
|
91
90
|
* Replaces any circular references inside `obj` with '[object Object]'
|
|
92
91
|
*
|
|
93
|
-
* @
|
|
92
|
+
* @private
|
|
94
93
|
* @param {Object} obj
|
|
95
94
|
* @return {Object}
|
|
96
95
|
*/
|
|
97
|
-
function cleanCycles
|
|
96
|
+
function cleanCycles(obj) {
|
|
98
97
|
var cache = [];
|
|
99
|
-
return JSON.parse(
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
return JSON.parse(
|
|
99
|
+
JSON.stringify(obj, function(key, value) {
|
|
100
|
+
if (typeof value === 'object' && value !== null) {
|
|
101
|
+
if (cache.indexOf(value) !== -1) {
|
|
102
|
+
// Instead of going in a circle, we'll print [object Object]
|
|
103
|
+
return '' + value;
|
|
104
|
+
}
|
|
105
|
+
cache.push(value);
|
|
104
106
|
}
|
|
105
|
-
cache.push(value);
|
|
106
|
-
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
return value;
|
|
109
|
+
})
|
|
110
|
+
);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
/**
|
|
113
114
|
* Transform an Error object into a JSON object.
|
|
114
115
|
*
|
|
115
|
-
* @
|
|
116
|
+
* @private
|
|
116
117
|
* @param {Error} err
|
|
117
118
|
* @return {Object}
|
|
118
119
|
*/
|
|
119
|
-
function errorJSON
|
|
120
|
+
function errorJSON(err) {
|
|
120
121
|
var res = {};
|
|
121
|
-
Object.getOwnPropertyNames(err).forEach(function
|
|
122
|
+
Object.getOwnPropertyNames(err).forEach(function(key) {
|
|
122
123
|
res[key] = err[key];
|
|
123
124
|
}, err);
|
|
124
125
|
return res;
|
|
125
126
|
}
|
|
127
|
+
|
|
128
|
+
JSONReporter.description = 'single JSON object';
|
package/lib/reporters/landing.js
CHANGED
|
@@ -42,33 +42,32 @@ Base.colors.runway = 90;
|
|
|
42
42
|
* @class
|
|
43
43
|
* @memberof Mocha.reporters
|
|
44
44
|
* @extends Mocha.reporters.Base
|
|
45
|
-
* @api public
|
|
46
45
|
* @param {Runner} runner
|
|
47
46
|
*/
|
|
48
|
-
function Landing
|
|
47
|
+
function Landing(runner) {
|
|
49
48
|
Base.call(this, runner);
|
|
50
49
|
|
|
51
50
|
var self = this;
|
|
52
|
-
var width = Base.window.width * 0.75 | 0;
|
|
51
|
+
var width = (Base.window.width * 0.75) | 0;
|
|
53
52
|
var total = runner.total;
|
|
54
53
|
var stream = process.stdout;
|
|
55
54
|
var plane = color('plane', '✈');
|
|
56
55
|
var crashed = -1;
|
|
57
56
|
var n = 0;
|
|
58
57
|
|
|
59
|
-
function runway
|
|
58
|
+
function runway() {
|
|
60
59
|
var buf = Array(width).join('-');
|
|
61
60
|
return ' ' + color('runway', buf);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
runner.on('start', function
|
|
63
|
+
runner.on('start', function() {
|
|
65
64
|
stream.write('\n\n\n ');
|
|
66
65
|
cursor.hide();
|
|
67
66
|
});
|
|
68
67
|
|
|
69
|
-
runner.on('test end', function
|
|
68
|
+
runner.on('test end', function(test) {
|
|
70
69
|
// check if the plane crashed
|
|
71
|
-
var col = crashed === -1 ? width * ++n / total | 0 : crashed;
|
|
70
|
+
var col = crashed === -1 ? ((width * ++n) / total) | 0 : crashed;
|
|
72
71
|
|
|
73
72
|
// show the crash
|
|
74
73
|
if (test.state === 'failed') {
|
|
@@ -87,7 +86,7 @@ function Landing (runner) {
|
|
|
87
86
|
stream.write('\u001b[0m');
|
|
88
87
|
});
|
|
89
88
|
|
|
90
|
-
runner.once('end', function
|
|
89
|
+
runner.once('end', function() {
|
|
91
90
|
cursor.show();
|
|
92
91
|
console.log();
|
|
93
92
|
self.epilogue();
|
|
@@ -98,3 +97,5 @@ function Landing (runner) {
|
|
|
98
97
|
* Inherit from `Base.prototype`.
|
|
99
98
|
*/
|
|
100
99
|
inherits(Landing, Base);
|
|
100
|
+
|
|
101
|
+
Landing.description = 'Unicode landing strip';
|
package/lib/reporters/list.js
CHANGED
|
@@ -24,38 +24,37 @@ exports = module.exports = List;
|
|
|
24
24
|
* @class
|
|
25
25
|
* @memberof Mocha.reporters
|
|
26
26
|
* @extends Mocha.reporters.Base
|
|
27
|
-
* @api public
|
|
28
27
|
* @param {Runner} runner
|
|
29
28
|
*/
|
|
30
|
-
function List
|
|
29
|
+
function List(runner) {
|
|
31
30
|
Base.call(this, runner);
|
|
32
31
|
|
|
33
32
|
var self = this;
|
|
34
33
|
var n = 0;
|
|
35
34
|
|
|
36
|
-
runner.on('start', function
|
|
35
|
+
runner.on('start', function() {
|
|
37
36
|
console.log();
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
runner.on('test', function
|
|
39
|
+
runner.on('test', function(test) {
|
|
41
40
|
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
|
42
41
|
});
|
|
43
42
|
|
|
44
|
-
runner.on('pending', function
|
|
45
|
-
var fmt = color('checkmark', ' -') +
|
|
46
|
-
color('pending', ' %s');
|
|
43
|
+
runner.on('pending', function(test) {
|
|
44
|
+
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
|
47
45
|
console.log(fmt, test.fullTitle());
|
|
48
46
|
});
|
|
49
47
|
|
|
50
|
-
runner.on('pass', function
|
|
51
|
-
var fmt =
|
|
48
|
+
runner.on('pass', function(test) {
|
|
49
|
+
var fmt =
|
|
50
|
+
color('checkmark', ' ' + Base.symbols.ok) +
|
|
52
51
|
color('pass', ' %s: ') +
|
|
53
52
|
color(test.speed, '%dms');
|
|
54
53
|
cursor.CR();
|
|
55
54
|
console.log(fmt, test.fullTitle(), test.duration);
|
|
56
55
|
});
|
|
57
56
|
|
|
58
|
-
runner.on('fail', function
|
|
57
|
+
runner.on('fail', function(test) {
|
|
59
58
|
cursor.CR();
|
|
60
59
|
console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
|
61
60
|
});
|
|
@@ -67,3 +66,5 @@ function List (runner) {
|
|
|
67
66
|
* Inherit from `Base.prototype`.
|
|
68
67
|
*/
|
|
69
68
|
inherits(List, Base);
|
|
69
|
+
|
|
70
|
+
List.description = 'like "spec" reporter but flat';
|