mocha-compat 3.6.4 → 10.8.2

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 (92) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +61 -110
  3. package/bin/_mocha +10 -0
  4. package/bin/mocha.js +142 -0
  5. package/browser-entry.js +61 -22
  6. package/lib/browser/highlight-tags.js +39 -0
  7. package/lib/browser/parse-query.js +24 -0
  8. package/lib/{template.html → browser/template.html} +7 -5
  9. package/lib/cli/cli.js +89 -0
  10. package/lib/cli/collect-files.js +137 -0
  11. package/lib/cli/commands.js +14 -0
  12. package/lib/cli/config.js +100 -0
  13. package/lib/cli/index.js +3 -0
  14. package/lib/cli/init.js +36 -0
  15. package/lib/cli/lookup-files.js +150 -0
  16. package/lib/cli/node-flags.js +85 -0
  17. package/lib/cli/one-and-dones.js +69 -0
  18. package/lib/cli/options.js +284 -0
  19. package/lib/cli/run-helpers.js +304 -0
  20. package/lib/cli/run-option-metadata.js +116 -0
  21. package/lib/cli/run.js +380 -0
  22. package/lib/cli/watch-run.js +377 -0
  23. package/lib/context.js +16 -42
  24. package/lib/errors.js +563 -0
  25. package/lib/hook.js +50 -9
  26. package/lib/interfaces/bdd.js +28 -29
  27. package/lib/interfaces/common.js +56 -21
  28. package/lib/interfaces/exports.js +4 -7
  29. package/lib/interfaces/qunit.js +10 -11
  30. package/lib/interfaces/tdd.js +15 -15
  31. package/lib/mocha.js +1073 -292
  32. package/lib/mocharc.json +10 -0
  33. package/lib/nodejs/buffered-worker-pool.js +188 -0
  34. package/lib/nodejs/esm-utils.js +106 -0
  35. package/lib/nodejs/file-unloader.js +15 -0
  36. package/lib/nodejs/parallel-buffered-runner.js +433 -0
  37. package/lib/nodejs/reporters/parallel-buffered.js +165 -0
  38. package/lib/nodejs/serializer.js +414 -0
  39. package/lib/nodejs/worker.js +151 -0
  40. package/lib/pending.js +3 -3
  41. package/lib/plugin-loader.js +286 -0
  42. package/lib/reporters/base.js +305 -205
  43. package/lib/reporters/doc.js +52 -21
  44. package/lib/reporters/dot.js +31 -18
  45. package/lib/reporters/html.js +153 -81
  46. package/lib/reporters/json-stream.js +53 -24
  47. package/lib/reporters/json.js +88 -18
  48. package/lib/reporters/landing.js +38 -16
  49. package/lib/reporters/list.js +34 -19
  50. package/lib/reporters/markdown.js +28 -15
  51. package/lib/reporters/min.js +22 -8
  52. package/lib/reporters/nyan.js +62 -58
  53. package/lib/reporters/progress.js +32 -19
  54. package/lib/reporters/spec.js +41 -23
  55. package/lib/reporters/tap.js +255 -32
  56. package/lib/reporters/xunit.js +89 -39
  57. package/lib/runnable.js +233 -148
  58. package/lib/runner.js +679 -380
  59. package/lib/stats-collector.js +83 -0
  60. package/lib/suite.js +376 -112
  61. package/lib/test.js +82 -21
  62. package/lib/utils.js +364 -477
  63. package/mocha.css +183 -54
  64. package/mocha.js +19840 -15846
  65. package/mocha.js.map +1 -0
  66. package/package.json +163 -336
  67. package/{lib/to-iso-string → vendor/serialize-javascript}/LICENSE +8 -6
  68. package/vendor/serialize-javascript/README.md +10 -0
  69. package/vendor/serialize-javascript/index.js +349 -0
  70. package/bin/_mocha-compat +0 -572
  71. package/bin/mocha-compat +0 -87
  72. package/bin/options.js +0 -41
  73. package/bower.json +0 -38
  74. package/images/error.png +0 -0
  75. package/images/ok.png +0 -0
  76. package/lib/browser/.eslintrc.yaml +0 -4
  77. package/lib/browser/debug.js +0 -7
  78. package/lib/browser/events.js +0 -195
  79. package/lib/browser/progress.js +0 -119
  80. package/lib/browser/tty.js +0 -13
  81. package/lib/ms.js +0 -130
  82. package/lib/to-iso-string/index.js +0 -37
  83. package/vendor/glob/LICENSE +0 -15
  84. package/vendor/glob/README.md +0 -399
  85. package/vendor/glob/common.js +0 -244
  86. package/vendor/glob/glob.js +0 -788
  87. package/vendor/glob/package.json +0 -55
  88. package/vendor/glob/sync.js +0 -486
  89. package/vendor/inflight/LICENSE +0 -15
  90. package/vendor/inflight/README.md +0 -37
  91. package/vendor/inflight/inflight.js +0 -54
  92. package/vendor/inflight/package.json +0 -29
@@ -1,14 +1,29 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Base
4
+ */
3
5
  /**
4
6
  * Module dependencies.
5
7
  */
6
8
 
7
- var tty = require('tty');
8
9
  var diff = require('diff');
9
- var ms = require('../ms');
10
+ var milliseconds = require('ms');
10
11
  var utils = require('../utils');
11
- var supportsColor = process.browser ? null : require('supports-color');
12
+ var supportsColor = require('supports-color');
13
+ var symbols = require('log-symbols');
14
+ var constants = require('../runner').constants;
15
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
16
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
17
+
18
+ const isBrowser = utils.isBrowser();
19
+
20
+ function getBrowserWindowSize() {
21
+ if ('innerHeight' in global) {
22
+ return [global.innerHeight, global.innerWidth];
23
+ }
24
+ // In a Web Worker, the DOM Window is not available.
25
+ return [640, 480];
26
+ }
12
27
 
13
28
  /**
14
29
  * Expose `Base`.
@@ -17,29 +32,23 @@ var supportsColor = process.browser ? null : require('supports-color');
17
32
  exports = module.exports = Base;
18
33
 
19
34
  /**
20
- * Save timer references to avoid Sinon interfering.
21
- * See: https://github.com/mochajs/mocha/issues/237
35
+ * Check if both stdio streams are associated with a tty.
22
36
  */
23
37
 
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 */
38
+ var isatty = isBrowser || (process.stdout.isTTY && process.stderr.isTTY);
31
39
 
32
40
  /**
33
- * Check if both stdio streams are associated with a tty.
41
+ * Save log references to avoid tests interfering (see GH-3604).
34
42
  */
35
-
36
- var isatty = tty.isatty(1) && tty.isatty(2);
43
+ var consoleLog = console.log;
37
44
 
38
45
  /**
39
46
  * Enable coloring by default, except in the browser interface.
40
47
  */
41
48
 
42
- exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
49
+ exports.useColors =
50
+ !isBrowser &&
51
+ (supportsColor.stdout || process.env.MOCHA_COLORS !== undefined);
43
52
 
44
53
  /**
45
54
  * Inline diffs instead of +/-
@@ -47,6 +56,11 @@ exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COL
47
56
 
48
57
  exports.inlineDiffs = false;
49
58
 
59
+ /**
60
+ * Truncate diffs longer than this value to avoid slow performance
61
+ */
62
+ exports.maxDiffSize = 8192;
63
+
50
64
  /**
51
65
  * Default color map.
52
66
  */
@@ -70,7 +84,9 @@ exports.colors = {
70
84
  light: 90,
71
85
  'diff gutter': 90,
72
86
  'diff added': 32,
73
- 'diff removed': 31
87
+ 'diff removed': 31,
88
+ 'diff added inline': '30;42',
89
+ 'diff removed inline': '30;41'
74
90
  };
75
91
 
76
92
  /**
@@ -78,37 +94,30 @@ exports.colors = {
78
94
  */
79
95
 
80
96
  exports.symbols = {
81
- ok: '✓',
82
- err: '✖',
83
- dot: '․',
97
+ ok: symbols.success,
98
+ err: symbols.error,
99
+ dot: '.',
84
100
  comma: ',',
85
101
  bang: '!'
86
102
  };
87
103
 
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
104
  /**
96
105
  * Color `str` with the given `type`,
97
106
  * allowing colors to be disabled,
98
107
  * as well as user-defined color
99
108
  * schemes.
100
109
  *
110
+ * @private
101
111
  * @param {string} type
102
112
  * @param {string} str
103
113
  * @return {string}
104
- * @api private
105
114
  */
106
- var color = exports.color = function (type, str) {
115
+ var color = (exports.color = function (type, str) {
107
116
  if (!exports.useColors) {
108
117
  return String(str);
109
118
  }
110
119
  return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
111
- };
120
+ });
112
121
 
113
122
  /**
114
123
  * Expose term window size, with some defaults for when stderr is not a tty.
@@ -119,9 +128,11 @@ exports.window = {
119
128
  };
120
129
 
121
130
  if (isatty) {
122
- exports.window.width = process.stdout.getWindowSize
123
- ? process.stdout.getWindowSize(1)[0]
124
- : tty.getWindowSize()[1];
131
+ if (isBrowser) {
132
+ exports.window.width = getBrowserWindowSize()[1];
133
+ } else {
134
+ exports.window.width = process.stdout.getWindowSize(1)[0];
135
+ }
125
136
  }
126
137
 
127
138
  /**
@@ -155,117 +166,207 @@ exports.cursor = {
155
166
  }
156
167
  };
157
168
 
169
+ var showDiff = (exports.showDiff = function (err) {
170
+ return (
171
+ err &&
172
+ err.showDiff !== false &&
173
+ sameType(err.actual, err.expected) &&
174
+ err.expected !== undefined
175
+ );
176
+ });
177
+
178
+ function stringifyDiffObjs(err) {
179
+ if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
180
+ err.actual = utils.stringify(err.actual);
181
+ err.expected = utils.stringify(err.expected);
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Returns a diff between 2 strings with coloured ANSI output.
187
+ *
188
+ * @description
189
+ * The diff will be either inline or unified dependent on the value
190
+ * of `Base.inlineDiff`.
191
+ *
192
+ * @param {string} actual
193
+ * @param {string} expected
194
+ * @return {string} Diff
195
+ */
196
+
197
+ var generateDiff = (exports.generateDiff = function (actual, expected) {
198
+ try {
199
+ var maxLen = exports.maxDiffSize;
200
+ var skipped = 0;
201
+ if (maxLen > 0) {
202
+ skipped = Math.max(actual.length - maxLen, expected.length - maxLen);
203
+ actual = actual.slice(0, maxLen);
204
+ expected = expected.slice(0, maxLen);
205
+ }
206
+ let result = exports.inlineDiffs
207
+ ? inlineDiff(actual, expected)
208
+ : unifiedDiff(actual, expected);
209
+ if (skipped > 0) {
210
+ result = `${result}\n [mocha] output truncated to ${maxLen} characters, see "maxDiffSize" reporter-option\n`;
211
+ }
212
+ return result;
213
+ } catch (err) {
214
+ var msg =
215
+ '\n ' +
216
+ color('diff added', '+ expected') +
217
+ ' ' +
218
+ color('diff removed', '- actual: failed to generate Mocha diff') +
219
+ '\n';
220
+ return msg;
221
+ }
222
+ });
223
+
158
224
  /**
159
- * Output the given `failures` as a list.
225
+ * Traverses err.cause and returns all stack traces
160
226
  *
161
- * @param {Array} failures
162
- * @api public
227
+ * @private
228
+ * @param {Error} err
229
+ * @param {Set<Error>} [seen]
230
+ * @return {FullErrorStack}
163
231
  */
232
+ var getFullErrorStack = function (err, seen) {
233
+ if (seen && seen.has(err)) {
234
+ return { message: '', msg: '<circular>', stack: '' };
235
+ }
236
+
237
+ var message;
238
+
239
+ if (typeof err.inspect === 'function') {
240
+ message = err.inspect() + '';
241
+ } else if (err.message && typeof err.message.toString === 'function') {
242
+ message = err.message + '';
243
+ } else {
244
+ message = '';
245
+ }
164
246
 
247
+ var msg;
248
+ var stack = err.stack || message;
249
+ var index = message ? stack.indexOf(message) : -1;
250
+
251
+ if (index === -1) {
252
+ msg = message;
253
+ } else {
254
+ index += message.length;
255
+ msg = stack.slice(0, index);
256
+ // remove msg from stack
257
+ stack = stack.slice(index + 1);
258
+
259
+ if (err.cause) {
260
+ seen = seen || new Set();
261
+ seen.add(err);
262
+ const causeStack = getFullErrorStack(err.cause, seen)
263
+ stack += '\n Caused by: ' + causeStack.msg + (causeStack.stack ? '\n' + causeStack.stack : '');
264
+ }
265
+ }
266
+
267
+ return {
268
+ message,
269
+ msg,
270
+ stack
271
+ };
272
+ };
273
+
274
+ /**
275
+ * Outputs the given `failures` as a list.
276
+ *
277
+ * @public
278
+ * @memberof Mocha.reporters.Base
279
+ * @variation 1
280
+ * @param {Object[]} failures - Each is Test instance with corresponding
281
+ * Error property
282
+ */
165
283
  exports.list = function (failures) {
166
- console.log();
284
+ var multipleErr, multipleTest;
285
+ Base.consoleLog();
167
286
  failures.forEach(function (test, i) {
168
287
  // format
169
- var fmt = color('error title', ' %s) %s:\n') +
288
+ var fmt =
289
+ color('error title', ' %s) %s:\n') +
170
290
  color('error message', ' %s') +
171
291
  color('error stack', '\n%s\n');
172
292
 
173
293
  // msg
174
- var msg;
175
- var err = test.err;
176
- var message;
177
- if (err.message && typeof err.message.toString === 'function') {
178
- message = err.message + '';
179
- } else if (typeof err.inspect === 'function') {
180
- message = err.inspect() + '';
181
- } else {
182
- message = '';
183
- }
184
- var stack = err.stack || message;
185
- var index = message ? stack.indexOf(message) : -1;
186
- var actual = err.actual;
187
- var expected = err.expected;
188
- var escape = true;
189
-
190
- if (index === -1) {
191
- msg = message;
294
+ var err;
295
+ if (test.err && test.err.multiple) {
296
+ if (multipleTest !== test) {
297
+ multipleTest = test;
298
+ multipleErr = [test.err].concat(test.err.multiple);
299
+ }
300
+ err = multipleErr.shift();
192
301
  } else {
193
- index += message.length;
194
- msg = stack.slice(0, index);
195
- // remove msg from stack
196
- stack = stack.slice(index + 1);
302
+ err = test.err;
197
303
  }
198
304
 
305
+ var { message, msg, stack } = getFullErrorStack(err);
306
+
199
307
  // uncaught
200
308
  if (err.uncaught) {
201
309
  msg = 'Uncaught ' + msg;
202
310
  }
203
311
  // explicitly show diff
204
- if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
205
- escape = false;
206
- if (!(utils.isString(actual) && utils.isString(expected))) {
207
- err.actual = actual = utils.stringify(actual);
208
- err.expected = expected = utils.stringify(expected);
209
- }
210
-
211
- fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
312
+ if (!exports.hideDiff && showDiff(err)) {
313
+ stringifyDiffObjs(err);
314
+ fmt =
315
+ color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
212
316
  var match = message.match(/^([^:]+): expected/);
213
317
  msg = '\n ' + color('error message', match ? match[1] : msg);
214
318
 
215
- if (exports.inlineDiffs) {
216
- msg += inlineDiff(err, escape);
217
- } else {
218
- msg += unifiedDiff(err, escape);
219
- }
319
+ msg += generateDiff(err.actual, err.expected);
220
320
  }
221
321
 
222
322
  // indent stack trace
223
323
  stack = stack.replace(/^/gm, ' ');
224
324
 
225
- console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
325
+ // indented test title
326
+ var testTitle = '';
327
+ test.titlePath().forEach(function (str, index) {
328
+ if (index !== 0) {
329
+ testTitle += '\n ';
330
+ }
331
+ for (var i = 0; i < index; i++) {
332
+ testTitle += ' ';
333
+ }
334
+ testTitle += str;
335
+ });
336
+
337
+ Base.consoleLog(fmt, i + 1, testTitle, msg, stack);
226
338
  });
227
339
  };
228
340
 
229
341
  /**
230
- * Initialize a new `Base` reporter.
342
+ * Constructs a new `Base` reporter instance.
231
343
  *
232
- * All other reporters generally
233
- * inherit from this reporter, providing
234
- * stats such as test duration, number
235
- * of tests passed / failed etc.
344
+ * @description
345
+ * All other reporters generally inherit from this reporter.
236
346
  *
237
- * @param {Runner} runner
238
- * @api public
347
+ * @public
348
+ * @class
349
+ * @memberof Mocha.reporters
350
+ * @param {Runner} runner - Instance triggers reporter actions.
351
+ * @param {Object} [options] - runner options
239
352
  */
240
-
241
- function Base (runner) {
242
- var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
243
- var failures = this.failures = [];
353
+ function Base(runner, options) {
354
+ var failures = (this.failures = []);
244
355
 
245
356
  if (!runner) {
246
- return;
357
+ throw new TypeError('Missing runner argument');
247
358
  }
359
+ this.options = options || {};
248
360
  this.runner = runner;
361
+ this.stats = runner.stats; // assigned so Reporters keep a closer reference
249
362
 
250
- runner.stats = stats;
251
-
252
- runner.on('start', function () {
253
- stats.start = new Date();
254
- });
255
-
256
- runner.on('suite', function (suite) {
257
- stats.suites = stats.suites || 0;
258
- suite.root || stats.suites++;
259
- });
260
-
261
- runner.on('test end', function () {
262
- stats.tests = stats.tests || 0;
263
- stats.tests++;
264
- });
265
-
266
- runner.on('pass', function (test) {
267
- stats.passes = stats.passes || 0;
363
+ var maxDiffSizeOpt =
364
+ this.options.reporterOption && this.options.reporterOption.maxDiffSize;
365
+ if (maxDiffSizeOpt !== undefined && !isNaN(Number(maxDiffSizeOpt))) {
366
+ exports.maxDiffSize = Number(maxDiffSizeOpt);
367
+ }
268
368
 
369
+ runner.on(EVENT_TEST_PASS, function (test) {
269
370
  if (test.duration > test.slow()) {
270
371
  test.speed = 'slow';
271
372
  } else if (test.duration > test.slow() / 2) {
@@ -273,107 +374,103 @@ function Base (runner) {
273
374
  } else {
274
375
  test.speed = 'fast';
275
376
  }
276
-
277
- stats.passes++;
278
377
  });
279
378
 
280
- runner.on('fail', function (test, err) {
281
- stats.failures = stats.failures || 0;
282
- stats.failures++;
283
- test.err = err;
379
+ runner.on(EVENT_TEST_FAIL, function (test, err) {
380
+ if (showDiff(err)) {
381
+ stringifyDiffObjs(err);
382
+ }
383
+ // more than one error per test
384
+ if (test.err && err instanceof Error) {
385
+ test.err.multiple = (test.err.multiple || []).concat(err);
386
+ } else {
387
+ test.err = err;
388
+ }
284
389
  failures.push(test);
285
390
  });
286
-
287
- runner.on('end', function () {
288
- stats.end = new Date();
289
- stats.duration = new Date() - stats.start;
290
- });
291
-
292
- runner.on('pending', function () {
293
- stats.pending++;
294
- });
295
391
  }
296
392
 
297
393
  /**
298
- * Output common epilogue used by many of
299
- * the bundled reporters.
394
+ * Outputs common epilogue used by many of the bundled reporters.
300
395
  *
301
- * @api public
396
+ * @public
397
+ * @memberof Mocha.reporters
302
398
  */
303
399
  Base.prototype.epilogue = function () {
304
400
  var stats = this.stats;
305
401
  var fmt;
306
402
 
307
- console.log();
403
+ Base.consoleLog();
308
404
 
309
405
  // passes
310
- fmt = color('bright pass', ' ') +
406
+ fmt =
407
+ color('bright pass', ' ') +
311
408
  color('green', ' %d passing') +
312
409
  color('light', ' (%s)');
313
410
 
314
- console.log(fmt,
315
- stats.passes || 0,
316
- ms(stats.duration));
411
+ Base.consoleLog(fmt, stats.passes || 0, milliseconds(stats.duration));
317
412
 
318
413
  // pending
319
414
  if (stats.pending) {
320
- fmt = color('pending', ' ') +
321
- color('pending', ' %d pending');
415
+ fmt = color('pending', ' ') + color('pending', ' %d pending');
322
416
 
323
- console.log(fmt, stats.pending);
417
+ Base.consoleLog(fmt, stats.pending);
324
418
  }
325
419
 
326
420
  // failures
327
421
  if (stats.failures) {
328
422
  fmt = color('fail', ' %d failing');
329
423
 
330
- console.log(fmt, stats.failures);
424
+ Base.consoleLog(fmt, stats.failures);
331
425
 
332
426
  Base.list(this.failures);
333
- console.log();
427
+ Base.consoleLog();
334
428
  }
335
429
 
336
- console.log();
430
+ Base.consoleLog();
337
431
  };
338
432
 
339
433
  /**
340
- * Pad the given `str` to `len`.
434
+ * Pads the given `str` to `len`.
341
435
  *
342
- * @api private
436
+ * @private
343
437
  * @param {string} str
344
438
  * @param {string} len
345
439
  * @return {string}
346
440
  */
347
- function pad (str, len) {
441
+ function pad(str, len) {
348
442
  str = String(str);
349
443
  return Array(len - str.length + 1).join(' ') + str;
350
444
  }
351
445
 
352
446
  /**
353
- * Returns an inline diff between 2 strings with coloured ANSI output
447
+ * Returns inline diff between 2 strings with coloured ANSI output.
354
448
  *
355
- * @api private
356
- * @param {Error} err with actual/expected
357
- * @param {boolean} escape
449
+ * @private
450
+ * @param {String} actual
451
+ * @param {String} expected
358
452
  * @return {string} Diff
359
453
  */
360
- function inlineDiff (err, escape) {
361
- var msg = errorDiff(err, 'WordsWithSpace', escape);
454
+ function inlineDiff(actual, expected) {
455
+ var msg = errorDiff(actual, expected);
362
456
 
363
457
  // linenos
364
458
  var lines = msg.split('\n');
365
459
  if (lines.length > 4) {
366
460
  var width = String(lines.length).length;
367
- msg = lines.map(function (str, i) {
368
- return pad(++i, width) + ' |' + ' ' + str;
369
- }).join('\n');
461
+ msg = lines
462
+ .map(function (str, i) {
463
+ return pad(++i, width) + ' |' + ' ' + str;
464
+ })
465
+ .join('\n');
370
466
  }
371
467
 
372
468
  // legend
373
- msg = '\n' +
374
- color('diff removed', 'actual') +
469
+ msg =
470
+ '\n' +
471
+ color('diff removed inline', 'actual') +
375
472
  ' ' +
376
- color('diff added', 'expected') +
473
+ color('diff added inline', 'expected') +
377
474
  '\n\n' +
378
475
  msg +
379
476
  '\n';
@@ -384,19 +481,16 @@ function inlineDiff (err, escape) {
384
481
  }
385
482
 
386
483
  /**
387
- * Returns a unified diff between two strings.
484
+ * Returns unified diff between two strings with coloured ANSI output.
388
485
  *
389
- * @api private
390
- * @param {Error} err with actual/expected
391
- * @param {boolean} escape
486
+ * @private
487
+ * @param {String} actual
488
+ * @param {String} expected
392
489
  * @return {string} The diff.
393
490
  */
394
- function unifiedDiff (err, escape) {
491
+ function unifiedDiff(actual, expected) {
395
492
  var indent = ' ';
396
- function cleanUp (line) {
397
- if (escape) {
398
- line = escapeInvisibles(line);
399
- }
493
+ function cleanUp(line) {
400
494
  if (line[0] === '+') {
401
495
  return indent + colorLines('diff added', line);
402
496
  }
@@ -404,73 +498,66 @@ function unifiedDiff (err, escape) {
404
498
  return indent + colorLines('diff removed', line);
405
499
  }
406
500
  if (line.match(/@@/)) {
407
- return null;
501
+ return '--';
408
502
  }
409
503
  if (line.match(/\\ No newline/)) {
410
504
  return null;
411
505
  }
412
506
  return indent + line;
413
507
  }
414
- function notBlank (line) {
508
+ function notBlank(line) {
415
509
  return typeof line !== 'undefined' && line !== null;
416
510
  }
417
- var msg = diff.createPatch('string', err.actual, err.expected);
418
- var lines = msg.split('\n').splice(4);
419
- return '\n ' +
420
- colorLines('diff added', '+ expected') + ' ' +
511
+ var msg = diff.createPatch('string', actual, expected);
512
+ var lines = msg.split('\n').splice(5);
513
+ return (
514
+ '\n ' +
515
+ colorLines('diff added', '+ expected') +
516
+ ' ' +
421
517
  colorLines('diff removed', '- actual') +
422
518
  '\n\n' +
423
- lines.map(cleanUp).filter(notBlank).join('\n');
424
- }
425
-
426
- /**
427
- * Return a character diff for `err`.
428
- *
429
- * @api private
430
- * @param {Error} err
431
- * @param {string} type
432
- * @param {boolean} escape
433
- * @return {string}
434
- */
435
- function errorDiff (err, type, escape) {
436
- var actual = escape ? escapeInvisibles(err.actual) : err.actual;
437
- var expected = escape ? escapeInvisibles(err.expected) : err.expected;
438
- return diff['diff' + type](actual, expected).map(function (str) {
439
- if (str.added) {
440
- return colorLines('diff added', str.value);
441
- }
442
- if (str.removed) {
443
- return colorLines('diff removed', str.value);
444
- }
445
- return str.value;
446
- }).join('');
519
+ lines.map(cleanUp).filter(notBlank).join('\n')
520
+ );
447
521
  }
448
522
 
449
523
  /**
450
- * Returns a string with all invisible characters in plain text
524
+ * Returns character diff for `err`.
451
525
  *
452
- * @api private
453
- * @param {string} line
454
- * @return {string}
526
+ * @private
527
+ * @param {String} actual
528
+ * @param {String} expected
529
+ * @return {string} the diff
455
530
  */
456
- function escapeInvisibles (line) {
457
- return line.replace(/\t/g, '<tab>')
458
- .replace(/\r/g, '<CR>')
459
- .replace(/\n/g, '<LF>\n');
531
+ function errorDiff(actual, expected) {
532
+ return diff
533
+ .diffWordsWithSpace(actual, expected)
534
+ .map(function (str) {
535
+ if (str.added) {
536
+ return colorLines('diff added inline', str.value);
537
+ }
538
+ if (str.removed) {
539
+ return colorLines('diff removed inline', str.value);
540
+ }
541
+ return str.value;
542
+ })
543
+ .join('');
460
544
  }
461
545
 
462
546
  /**
463
- * Color lines for `str`, using the color `name`.
547
+ * Colors lines for `str`, using the color `name`.
464
548
  *
465
- * @api private
549
+ * @private
466
550
  * @param {string} name
467
551
  * @param {string} str
468
552
  * @return {string}
469
553
  */
470
- function colorLines (name, str) {
471
- return str.split('\n').map(function (str) {
472
- return color(name, str);
473
- }).join('\n');
554
+ function colorLines(name, str) {
555
+ return str
556
+ .split('\n')
557
+ .map(function (str) {
558
+ return color(name, str);
559
+ })
560
+ .join('\n');
474
561
  }
475
562
 
476
563
  /**
@@ -479,13 +566,26 @@ function colorLines (name, str) {
479
566
  var objToString = Object.prototype.toString;
480
567
 
481
568
  /**
482
- * Check that a / b have the same type.
569
+ * Checks that a / b have the same type.
483
570
  *
484
- * @api private
571
+ * @private
485
572
  * @param {Object} a
486
573
  * @param {Object} b
487
574
  * @return {boolean}
488
575
  */
489
- function sameType (a, b) {
576
+ function sameType(a, b) {
490
577
  return objToString.call(a) === objToString.call(b);
491
578
  }
579
+
580
+ Base.consoleLog = consoleLog;
581
+
582
+ Base.abstract = true;
583
+
584
+ /**
585
+ * An object with all stack traces recursively mounted from each err.cause
586
+ * @memberof module:lib/reporters/base
587
+ * @typedef {Object} FullErrorStack
588
+ * @property {string} message
589
+ * @property {string} msg
590
+ * @property {string} stack
591
+ */