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