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
@@ -1,498 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
- var tty = require('tty');
8
- var diff = require('diff');
9
- var ms = require('../ms');
10
- var utils = require('../utils');
11
- var supportsColor = process.browser ? null : require('supports-color');
12
-
13
- /**
14
- * Expose `Base`.
15
- */
16
-
17
- exports = module.exports = Base;
18
-
19
- /**
20
- * Save timer references to avoid Sinon interfering.
21
- * See: https://github.com/mochajs/mocha/issues/237
22
- */
23
-
24
- /* eslint-disable no-unused-vars, no-native-reassign */
25
- var Date = global.Date;
26
- var setTimeout = global.setTimeout;
27
- var setInterval = global.setInterval;
28
- var clearTimeout = global.clearTimeout;
29
- var clearInterval = global.clearInterval;
30
- /* eslint-enable no-unused-vars, no-native-reassign */
31
-
32
- /**
33
- * Check if both stdio streams are associated with a tty.
34
- */
35
-
36
- var isatty = tty.isatty(1) && tty.isatty(2);
37
-
38
- /**
39
- * Enable coloring by default, except in the browser interface.
40
- */
41
-
42
- exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
43
-
44
- /**
45
- * Inline diffs instead of +/-
46
- */
47
-
48
- exports.inlineDiffs = false;
49
-
50
- /**
51
- * Default color map.
52
- */
53
-
54
- exports.colors = {
55
- pass: 90,
56
- fail: 31,
57
- 'bright pass': 92,
58
- 'bright fail': 91,
59
- 'bright yellow': 93,
60
- pending: 36,
61
- suite: 0,
62
- 'error title': 0,
63
- 'error message': 31,
64
- 'error stack': 90,
65
- checkmark: 32,
66
- fast: 90,
67
- medium: 33,
68
- slow: 31,
69
- green: 32,
70
- light: 90,
71
- 'diff gutter': 90,
72
- 'diff added': 32,
73
- 'diff removed': 31
74
- };
75
-
76
- /**
77
- * Default symbol map.
78
- */
79
-
80
- exports.symbols = {
81
- ok: '✓',
82
- err: '✖',
83
- dot: '․',
84
- comma: ',',
85
- bang: '!'
86
- };
87
-
88
- // With node.js on Windows: use symbols available in terminal default fonts
89
- if (process.platform === 'win32') {
90
- exports.symbols.ok = '\u221A';
91
- exports.symbols.err = '\u00D7';
92
- exports.symbols.dot = '.';
93
- }
94
-
95
- /**
96
- * Color `str` with the given `type`,
97
- * allowing colors to be disabled,
98
- * as well as user-defined color
99
- * schemes.
100
- *
101
- * @param {string} type
102
- * @param {string} str
103
- * @return {string}
104
- * @api private
105
- */
106
- var color = exports.color = function (type, str) {
107
- if (!exports.useColors) {
108
- return String(str);
109
- }
110
- return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
111
- };
112
-
113
- /**
114
- * Expose term window size, with some defaults for when stderr is not a tty.
115
- */
116
-
117
- exports.window = {
118
- width: 75
119
- };
120
-
121
- if (isatty) {
122
- exports.window.width = process.stdout.getWindowSize
123
- ? process.stdout.getWindowSize(1)[0]
124
- : tty.getWindowSize()[1];
125
- }
126
-
127
- /**
128
- * Expose some basic cursor interactions that are common among reporters.
129
- */
130
-
131
- exports.cursor = {
132
- hide: function () {
133
- isatty && process.stdout.write('\u001b[?25l');
134
- },
135
-
136
- show: function () {
137
- isatty && process.stdout.write('\u001b[?25h');
138
- },
139
-
140
- deleteLine: function () {
141
- isatty && process.stdout.write('\u001b[2K');
142
- },
143
-
144
- beginningOfLine: function () {
145
- isatty && process.stdout.write('\u001b[0G');
146
- },
147
-
148
- CR: function () {
149
- if (isatty) {
150
- exports.cursor.deleteLine();
151
- exports.cursor.beginningOfLine();
152
- } else {
153
- process.stdout.write('\r');
154
- }
155
- }
156
- };
157
-
158
- function showDiff (err) {
159
- return err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined;
160
- }
161
-
162
- function stringifyDiffObjs (err) {
163
- if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
164
- err.actual = utils.stringify(err.actual);
165
- err.expected = utils.stringify(err.expected);
166
- }
167
- }
168
-
169
- /**
170
- * Output the given `failures` as a list.
171
- *
172
- * @param {Array} failures
173
- * @api public
174
- */
175
-
176
- exports.list = function (failures) {
177
- console.log();
178
- failures.forEach(function (test, i) {
179
- // format
180
- var fmt = color('error title', ' %s) %s:\n') +
181
- color('error message', ' %s') +
182
- color('error stack', '\n%s\n');
183
-
184
- // msg
185
- var msg;
186
- var err = test.err;
187
- var message;
188
- if (err.message && typeof err.message.toString === 'function') {
189
- message = err.message + '';
190
- } else if (typeof err.inspect === 'function') {
191
- message = err.inspect() + '';
192
- } else {
193
- message = '';
194
- }
195
- var stack = err.stack || message;
196
- var index = message ? stack.indexOf(message) : -1;
197
-
198
- if (index === -1) {
199
- msg = message;
200
- } else {
201
- index += message.length;
202
- msg = stack.slice(0, index);
203
- // remove msg from stack
204
- stack = stack.slice(index + 1);
205
- }
206
-
207
- // uncaught
208
- if (err.uncaught) {
209
- msg = 'Uncaught ' + msg;
210
- }
211
-
212
- // explicitly show diff
213
- <<<<<<< HEAD
214
- if (showDiff(err)) {
215
- stringifyDiffObjs(err);
216
- =======
217
- if (exports.hideDiff !== true && err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
218
- escape = false;
219
- if (!(utils.isString(actual) && utils.isString(expected))) {
220
- err.actual = actual = utils.stringify(actual);
221
- err.expected = expected = utils.stringify(expected);
222
- }
223
-
224
- >>>>>>> Add --no-diff option (fixes mochajs/mocha#2514)
225
- fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
226
- var match = message.match(/^([^:]+): expected/);
227
- msg = '\n ' + color('error message', match ? match[1] : msg);
228
-
229
- if (exports.inlineDiffs) {
230
- msg += inlineDiff(err);
231
- } else {
232
- msg += unifiedDiff(err);
233
- }
234
- }
235
-
236
- // indent stack trace
237
- stack = stack.replace(/^/gm, ' ');
238
-
239
- // indented test title
240
- var testTitle = '';
241
- test.titlePath().forEach(function (str, index) {
242
- if (index !== 0) {
243
- testTitle += '\n ';
244
- }
245
- for (var i = 0; i < index; i++) {
246
- testTitle += ' ';
247
- }
248
- testTitle += str;
249
- });
250
-
251
- console.log(fmt, (i + 1), testTitle, msg, stack);
252
- });
253
- };
254
-
255
- /**
256
- * Initialize a new `Base` reporter.
257
- *
258
- * All other reporters generally
259
- * inherit from this reporter, providing
260
- * stats such as test duration, number
261
- * of tests passed / failed etc.
262
- *
263
- * @param {Runner} runner
264
- * @api public
265
- */
266
-
267
- function Base (runner) {
268
- var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
269
- var failures = this.failures = [];
270
-
271
- if (!runner) {
272
- return;
273
- }
274
- this.runner = runner;
275
-
276
- runner.stats = stats;
277
-
278
- runner.on('start', function () {
279
- stats.start = new Date();
280
- });
281
-
282
- runner.on('suite', function (suite) {
283
- stats.suites = stats.suites || 0;
284
- suite.root || stats.suites++;
285
- });
286
-
287
- runner.on('test end', function () {
288
- stats.tests = stats.tests || 0;
289
- stats.tests++;
290
- });
291
-
292
- runner.on('pass', function (test) {
293
- stats.passes = stats.passes || 0;
294
-
295
- if (test.duration > test.slow()) {
296
- test.speed = 'slow';
297
- } else if (test.duration > test.slow() / 2) {
298
- test.speed = 'medium';
299
- } else {
300
- test.speed = 'fast';
301
- }
302
-
303
- stats.passes++;
304
- });
305
-
306
- runner.on('fail', function (test, err) {
307
- stats.failures = stats.failures || 0;
308
- stats.failures++;
309
- if (showDiff(err)) {
310
- stringifyDiffObjs(err);
311
- }
312
- test.err = err;
313
- failures.push(test);
314
- });
315
-
316
- runner.on('end', function () {
317
- stats.end = new Date();
318
- stats.duration = new Date() - stats.start;
319
- });
320
-
321
- runner.on('pending', function () {
322
- stats.pending++;
323
- });
324
- }
325
-
326
- /**
327
- * Output common epilogue used by many of
328
- * the bundled reporters.
329
- *
330
- * @api public
331
- */
332
- Base.prototype.epilogue = function () {
333
- var stats = this.stats;
334
- var fmt;
335
-
336
- console.log();
337
-
338
- // passes
339
- fmt = color('bright pass', ' ') +
340
- color('green', ' %d passing') +
341
- color('light', ' (%s)');
342
-
343
- console.log(fmt,
344
- stats.passes || 0,
345
- ms(stats.duration));
346
-
347
- // pending
348
- if (stats.pending) {
349
- fmt = color('pending', ' ') +
350
- color('pending', ' %d pending');
351
-
352
- console.log(fmt, stats.pending);
353
- }
354
-
355
- // failures
356
- if (stats.failures) {
357
- fmt = color('fail', ' %d failing');
358
-
359
- console.log(fmt, stats.failures);
360
-
361
- Base.list(this.failures);
362
- console.log();
363
- }
364
-
365
- console.log();
366
- };
367
-
368
- /**
369
- * Pad the given `str` to `len`.
370
- *
371
- * @api private
372
- * @param {string} str
373
- * @param {string} len
374
- * @return {string}
375
- */
376
- function pad (str, len) {
377
- str = String(str);
378
- return Array(len - str.length + 1).join(' ') + str;
379
- }
380
-
381
- /**
382
- * Returns an inline diff between 2 strings with coloured ANSI output
383
- *
384
- * @api private
385
- * @param {Error} err with actual/expected
386
- * @return {string} Diff
387
- */
388
- function inlineDiff (err) {
389
- var msg = errorDiff(err);
390
-
391
- // linenos
392
- var lines = msg.split('\n');
393
- if (lines.length > 4) {
394
- var width = String(lines.length).length;
395
- msg = lines.map(function (str, i) {
396
- return pad(++i, width) + ' |' + ' ' + str;
397
- }).join('\n');
398
- }
399
-
400
- // legend
401
- msg = '\n' +
402
- color('diff removed', 'actual') +
403
- ' ' +
404
- color('diff added', 'expected') +
405
- '\n\n' +
406
- msg +
407
- '\n';
408
-
409
- // indent
410
- msg = msg.replace(/^/gm, ' ');
411
- return msg;
412
- }
413
-
414
- /**
415
- * Returns a unified diff between two strings.
416
- *
417
- * @api private
418
- * @param {Error} err with actual/expected
419
- * @return {string} The diff.
420
- */
421
- function unifiedDiff (err) {
422
- var indent = ' ';
423
- function cleanUp (line) {
424
- if (line[0] === '+') {
425
- return indent + colorLines('diff added', line);
426
- }
427
- if (line[0] === '-') {
428
- return indent + colorLines('diff removed', line);
429
- }
430
- if (line.match(/@@/)) {
431
- return '--';
432
- }
433
- if (line.match(/\\ No newline/)) {
434
- return null;
435
- }
436
- return indent + line;
437
- }
438
- function notBlank (line) {
439
- return typeof line !== 'undefined' && line !== null;
440
- }
441
- var msg = diff.createPatch('string', err.actual, err.expected);
442
- var lines = msg.split('\n').splice(5);
443
- return '\n ' +
444
- colorLines('diff added', '+ expected') + ' ' +
445
- colorLines('diff removed', '- actual') +
446
- '\n\n' +
447
- lines.map(cleanUp).filter(notBlank).join('\n');
448
- }
449
-
450
- /**
451
- * Return a character diff for `err`.
452
- *
453
- * @api private
454
- * @param {Error} err
455
- * @return {string}
456
- */
457
- function errorDiff (err) {
458
- return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
459
- if (str.added) {
460
- return colorLines('diff added', str.value);
461
- }
462
- if (str.removed) {
463
- return colorLines('diff removed', str.value);
464
- }
465
- return str.value;
466
- }).join('');
467
- }
468
-
469
- /**
470
- * Color lines for `str`, using the color `name`.
471
- *
472
- * @api private
473
- * @param {string} name
474
- * @param {string} str
475
- * @return {string}
476
- */
477
- function colorLines (name, str) {
478
- return str.split('\n').map(function (str) {
479
- return color(name, str);
480
- }).join('\n');
481
- }
482
-
483
- /**
484
- * Object#toString reference.
485
- */
486
- var objToString = Object.prototype.toString;
487
-
488
- /**
489
- * Check that a / b have the same type.
490
- *
491
- * @api private
492
- * @param {Object} a
493
- * @param {Object} b
494
- * @return {boolean}
495
- */
496
- function sameType (a, b) {
497
- return objToString.call(a) === objToString.call(b);
498
- }
@@ -1,128 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
- var Base = require('./base');
8
-
9
- /**
10
- * Expose `JSON`.
11
- */
12
-
13
- exports = module.exports = JSONReporter;
14
-
15
- /**
16
- * Initialize a new `JSON` reporter.
17
- *
18
- * @api public
19
- * @param {Runner} runner
20
- * @param {options} mocha invocation options. Invoking
21
- * `mocha -R --reporter-options output-file=asdf` yields options like:
22
- * { ... reporterOptions: { "output-file": "asdf" } ... }
23
- */
24
- function JSONReporter (runner, options) {
25
- <<<<<<< HEAD
26
- =======
27
- options = options || {};
28
- var reptOptions = options.reporterOptions || {};
29
- >>>>>>> + json ouput controls: output-file, output-object
30
- Base.call(this, runner);
31
-
32
- var self = this;
33
- var tests = [];
34
- var pending = [];
35
- var failures = [];
36
- var passes = [];
37
-
38
- runner.on('test end', function (test) {
39
- tests.push(test);
40
- });
41
-
42
- runner.on('pass', function (test) {
43
- passes.push(test);
44
- });
45
-
46
- runner.on('fail', function (test) {
47
- failures.push(test);
48
- });
49
-
50
- runner.on('pending', function (test) {
51
- pending.push(test);
52
- });
53
-
54
- runner.once('end', function () {
55
- var obj = {
56
- stats: self.stats,
57
- tests: tests.map(clean),
58
- pending: pending.map(clean),
59
- failures: failures.map(clean),
60
- passes: passes.map(clean)
61
- };
62
-
63
- runner.testResults = obj;
64
- <<<<<<< HEAD
65
- if ('output-object' in options.reporterOptions) {
66
- // Pass to reporter with: reporter("json", {"output-object": myObject})
67
- Object.assign(options.reporterOptions['output-object'], obj);
68
- } else {
69
- var text = JSON.stringify(obj, null, 2);
70
- if ('output-file' in options.reporterOptions) {
71
- // Direct output with `mocha -R --reporter-options output-file=rpt.json`
72
- try {
73
- require('fs').writeFileSync(options.reporterOptions['output-file'], text);
74
- } catch (e) {
75
- console.warn('error writing to ' + options.reporterOptions.output + ':', e);
76
- =======
77
- if ('output-object' in reptOptions) {
78
- // Pass to reporter with: reporter("json", {"output-object": myObject})
79
- Object.assign(reptOptions['output-object'], obj);
80
- } else {
81
- var text = JSON.stringify(obj, null, 2);
82
- if ('output-file' in reptOptions) {
83
- // Direct output with `mocha -R --reporter-options output-file=rpt.json`
84
- try {
85
- require('fs').writeFileSync(reptOptions['output-file'], text);
86
- } catch (e) {
87
- console.warn('error writing to ' + reptOptions.output + ':', e);
88
- >>>>>>> + json ouput controls: output-file, output-object
89
- }
90
- } else {
91
- process.stdout.write(text);
92
- }
93
- }
94
- });
95
- }
96
-
97
- /**
98
- * Return a plain-object representation of `test`
99
- * free of cyclic properties etc.
100
- *
101
- * @api private
102
- * @param {Object} test
103
- * @return {Object}
104
- */
105
- function clean (test) {
106
- return {
107
- title: test.title,
108
- fullTitle: test.fullTitle(),
109
- duration: test.duration,
110
- currentRetry: test.currentRetry(),
111
- err: errorJSON(test.err || {})
112
- };
113
- }
114
-
115
- /**
116
- * Transform `error` into a JSON object.
117
- *
118
- * @api private
119
- * @param {Error} err
120
- * @return {Object}
121
- */
122
- function errorJSON (err) {
123
- var res = {};
124
- Object.getOwnPropertyNames(err).forEach(function (key) {
125
- res[key] = err[key];
126
- }, err);
127
- return res;
128
- }