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