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.
- package/CHANGELOG.md +686 -984
- package/README.md +2 -1
- package/{images → assets/growl}/error.png +0 -0
- package/{images → assets/growl}/ok.png +0 -0
- package/bin/_mocha +4 -595
- package/bin/mocha +121 -61
- package/bin/options.js +6 -39
- package/browser-entry.js +21 -17
- package/lib/browser/growl.js +165 -2
- package/lib/browser/progress.js +11 -11
- package/lib/{template.html → browser/template.html} +0 -0
- package/lib/browser/tty.js +2 -2
- package/lib/cli/cli.js +68 -0
- package/lib/cli/commands.js +13 -0
- package/lib/cli/config.js +79 -0
- package/lib/cli/index.js +9 -0
- package/lib/cli/init.js +37 -0
- package/lib/cli/node-flags.js +69 -0
- package/lib/cli/one-and-dones.js +70 -0
- package/lib/cli/options.js +330 -0
- package/lib/cli/run-helpers.js +337 -0
- package/lib/cli/run-option-metadata.js +76 -0
- package/lib/cli/run.js +297 -0
- package/lib/context.js +14 -14
- package/lib/errors.js +141 -0
- package/lib/growl.js +136 -0
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +16 -13
- package/lib/interfaces/common.js +62 -18
- package/lib/interfaces/exports.js +5 -8
- package/lib/interfaces/qunit.js +10 -10
- package/lib/interfaces/tdd.js +12 -11
- package/lib/mocha.js +477 -256
- package/lib/mocharc.json +10 -0
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +95 -117
- package/lib/reporters/doc.js +23 -9
- package/lib/reporters/dot.js +19 -13
- package/lib/reporters/html.js +82 -47
- package/lib/reporters/json-stream.js +43 -23
- package/lib/reporters/json.js +32 -23
- package/lib/reporters/landing.js +16 -9
- package/lib/reporters/list.js +19 -11
- package/lib/reporters/markdown.js +18 -12
- package/lib/reporters/min.js +8 -4
- package/lib/reporters/nyan.js +42 -35
- package/lib/reporters/progress.js +12 -7
- package/lib/reporters/spec.js +23 -12
- package/lib/reporters/tap.js +250 -32
- package/lib/reporters/xunit.js +61 -35
- package/lib/runnable.js +152 -95
- package/lib/runner.js +296 -248
- package/lib/stats-collector.js +83 -0
- package/lib/suite.js +294 -75
- package/lib/test.js +16 -15
- package/lib/utils.js +419 -146
- package/mocha.js +4589 -2228
- package/package.json +137 -38
- package/lib/ms.js +0 -94
- package/lib/reporters/base.js.orig +0 -498
- package/lib/reporters/json.js.orig +0 -128
package/lib/mocharc.json
ADDED
package/lib/pending.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Expose `Pending`.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
3
|
module.exports = Pending;
|
|
8
4
|
|
|
9
5
|
/**
|
|
@@ -11,6 +7,6 @@ module.exports = Pending;
|
|
|
11
7
|
*
|
|
12
8
|
* @param {string} message
|
|
13
9
|
*/
|
|
14
|
-
function Pending
|
|
10
|
+
function Pending(message) {
|
|
15
11
|
this.message = message;
|
|
16
12
|
}
|
package/lib/reporters/base.js
CHANGED
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
var tty = require('tty');
|
|
10
10
|
var diff = require('diff');
|
|
11
|
-
var
|
|
11
|
+
var milliseconds = require('ms');
|
|
12
12
|
var utils = require('../utils');
|
|
13
13
|
var supportsColor = process.browser ? null : require('supports-color');
|
|
14
|
+
var constants = require('../runner').constants;
|
|
15
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
16
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Expose `Base`.
|
|
@@ -18,19 +21,6 @@ var supportsColor = process.browser ? null : require('supports-color');
|
|
|
18
21
|
|
|
19
22
|
exports = module.exports = Base;
|
|
20
23
|
|
|
21
|
-
/**
|
|
22
|
-
* Save timer references to avoid Sinon interfering.
|
|
23
|
-
* See: https://github.com/mochajs/mocha/issues/237
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* eslint-disable no-unused-vars, no-native-reassign */
|
|
27
|
-
var Date = global.Date;
|
|
28
|
-
var setTimeout = global.setTimeout;
|
|
29
|
-
var setInterval = global.setInterval;
|
|
30
|
-
var clearTimeout = global.clearTimeout;
|
|
31
|
-
var clearInterval = global.clearInterval;
|
|
32
|
-
/* eslint-enable no-unused-vars, no-native-reassign */
|
|
33
|
-
|
|
34
24
|
/**
|
|
35
25
|
* Check if both stdio streams are associated with a tty.
|
|
36
26
|
*/
|
|
@@ -41,7 +31,9 @@ var isatty = tty.isatty(1) && tty.isatty(2);
|
|
|
41
31
|
* Enable coloring by default, except in the browser interface.
|
|
42
32
|
*/
|
|
43
33
|
|
|
44
|
-
exports.useColors =
|
|
34
|
+
exports.useColors =
|
|
35
|
+
!process.browser &&
|
|
36
|
+
(supportsColor.stdout || process.env.MOCHA_COLORS !== undefined);
|
|
45
37
|
|
|
46
38
|
/**
|
|
47
39
|
* Inline diffs instead of +/-
|
|
@@ -103,14 +95,14 @@ if (process.platform === 'win32') {
|
|
|
103
95
|
* @param {string} type
|
|
104
96
|
* @param {string} str
|
|
105
97
|
* @return {string}
|
|
106
|
-
* @
|
|
98
|
+
* @private
|
|
107
99
|
*/
|
|
108
|
-
var color = exports.color = function
|
|
100
|
+
var color = (exports.color = function(type, str) {
|
|
109
101
|
if (!exports.useColors) {
|
|
110
102
|
return String(str);
|
|
111
103
|
}
|
|
112
104
|
return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
|
|
113
|
-
};
|
|
105
|
+
});
|
|
114
106
|
|
|
115
107
|
/**
|
|
116
108
|
* Expose term window size, with some defaults for when stderr is not a tty.
|
|
@@ -131,23 +123,23 @@ if (isatty) {
|
|
|
131
123
|
*/
|
|
132
124
|
|
|
133
125
|
exports.cursor = {
|
|
134
|
-
hide: function
|
|
126
|
+
hide: function() {
|
|
135
127
|
isatty && process.stdout.write('\u001b[?25l');
|
|
136
128
|
},
|
|
137
129
|
|
|
138
|
-
show: function
|
|
130
|
+
show: function() {
|
|
139
131
|
isatty && process.stdout.write('\u001b[?25h');
|
|
140
132
|
},
|
|
141
133
|
|
|
142
|
-
deleteLine: function
|
|
134
|
+
deleteLine: function() {
|
|
143
135
|
isatty && process.stdout.write('\u001b[2K');
|
|
144
136
|
},
|
|
145
137
|
|
|
146
|
-
beginningOfLine: function
|
|
138
|
+
beginningOfLine: function() {
|
|
147
139
|
isatty && process.stdout.write('\u001b[0G');
|
|
148
140
|
},
|
|
149
141
|
|
|
150
|
-
CR: function
|
|
142
|
+
CR: function() {
|
|
151
143
|
if (isatty) {
|
|
152
144
|
exports.cursor.deleteLine();
|
|
153
145
|
exports.cursor.beginningOfLine();
|
|
@@ -157,11 +149,16 @@ exports.cursor = {
|
|
|
157
149
|
}
|
|
158
150
|
};
|
|
159
151
|
|
|
160
|
-
function showDiff
|
|
161
|
-
return
|
|
152
|
+
function showDiff(err) {
|
|
153
|
+
return (
|
|
154
|
+
err &&
|
|
155
|
+
err.showDiff !== false &&
|
|
156
|
+
sameType(err.actual, err.expected) &&
|
|
157
|
+
err.expected !== undefined
|
|
158
|
+
);
|
|
162
159
|
}
|
|
163
160
|
|
|
164
|
-
function stringifyDiffObjs
|
|
161
|
+
function stringifyDiffObjs(err) {
|
|
165
162
|
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
|
|
166
163
|
err.actual = utils.stringify(err.actual);
|
|
167
164
|
err.expected = utils.stringify(err.expected);
|
|
@@ -178,11 +175,11 @@ function stringifyDiffObjs (err) {
|
|
|
178
175
|
* @param {string} expected
|
|
179
176
|
* @return {string} Diff
|
|
180
177
|
*/
|
|
181
|
-
var generateDiff = exports.generateDiff = function
|
|
178
|
+
var generateDiff = (exports.generateDiff = function(actual, expected) {
|
|
182
179
|
return exports.inlineDiffs
|
|
183
180
|
? inlineDiff(actual, expected)
|
|
184
181
|
: unifiedDiff(actual, expected);
|
|
185
|
-
};
|
|
182
|
+
});
|
|
186
183
|
|
|
187
184
|
/**
|
|
188
185
|
* Output the given `failures` as a list.
|
|
@@ -191,14 +188,14 @@ var generateDiff = exports.generateDiff = function (actual, expected) {
|
|
|
191
188
|
* @memberof Mocha.reporters.Base
|
|
192
189
|
* @variation 1
|
|
193
190
|
* @param {Array} failures
|
|
194
|
-
* @api public
|
|
195
191
|
*/
|
|
196
192
|
|
|
197
|
-
exports.list = function
|
|
193
|
+
exports.list = function(failures) {
|
|
198
194
|
console.log();
|
|
199
|
-
failures.forEach(function
|
|
195
|
+
failures.forEach(function(test, i) {
|
|
200
196
|
// format
|
|
201
|
-
var fmt =
|
|
197
|
+
var fmt =
|
|
198
|
+
color('error title', ' %s) %s:\n') +
|
|
202
199
|
color('error message', ' %s') +
|
|
203
200
|
color('error stack', '\n%s\n');
|
|
204
201
|
|
|
@@ -232,7 +229,8 @@ exports.list = function (failures) {
|
|
|
232
229
|
// explicitly show diff
|
|
233
230
|
if (!exports.hideDiff && showDiff(err)) {
|
|
234
231
|
stringifyDiffObjs(err);
|
|
235
|
-
fmt =
|
|
232
|
+
fmt =
|
|
233
|
+
color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
|
|
236
234
|
var match = message.match(/^([^:]+): expected/);
|
|
237
235
|
msg = '\n ' + color('error message', match ? match[1] : msg);
|
|
238
236
|
|
|
@@ -244,7 +242,7 @@ exports.list = function (failures) {
|
|
|
244
242
|
|
|
245
243
|
// indented test title
|
|
246
244
|
var testTitle = '';
|
|
247
|
-
test.titlePath().forEach(function
|
|
245
|
+
test.titlePath().forEach(function(str, index) {
|
|
248
246
|
if (index !== 0) {
|
|
249
247
|
testTitle += '\n ';
|
|
250
248
|
}
|
|
@@ -254,7 +252,7 @@ exports.list = function (failures) {
|
|
|
254
252
|
testTitle += str;
|
|
255
253
|
});
|
|
256
254
|
|
|
257
|
-
console.log(fmt,
|
|
255
|
+
console.log(fmt, i + 1, testTitle, msg, stack);
|
|
258
256
|
});
|
|
259
257
|
};
|
|
260
258
|
|
|
@@ -262,45 +260,24 @@ exports.list = function (failures) {
|
|
|
262
260
|
* Initialize a new `Base` reporter.
|
|
263
261
|
*
|
|
264
262
|
* All other reporters generally
|
|
265
|
-
* inherit from this reporter
|
|
266
|
-
* stats such as test duration, number
|
|
267
|
-
* of tests passed / failed etc.
|
|
263
|
+
* inherit from this reporter.
|
|
268
264
|
*
|
|
269
265
|
* @memberof Mocha.reporters
|
|
270
266
|
* @public
|
|
271
267
|
* @class
|
|
272
268
|
* @param {Runner} runner
|
|
273
|
-
* @api public
|
|
274
269
|
*/
|
|
275
270
|
|
|
276
|
-
function Base
|
|
277
|
-
var
|
|
278
|
-
var failures = this.failures = [];
|
|
271
|
+
function Base(runner) {
|
|
272
|
+
var failures = (this.failures = []);
|
|
279
273
|
|
|
280
274
|
if (!runner) {
|
|
281
|
-
|
|
275
|
+
throw new TypeError('Missing runner argument');
|
|
282
276
|
}
|
|
277
|
+
this.stats = runner.stats; // assigned so Reporters keep a closer reference
|
|
283
278
|
this.runner = runner;
|
|
284
279
|
|
|
285
|
-
runner.
|
|
286
|
-
|
|
287
|
-
runner.on('start', function () {
|
|
288
|
-
stats.start = new Date();
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
runner.on('suite', function (suite) {
|
|
292
|
-
stats.suites = stats.suites || 0;
|
|
293
|
-
suite.root || stats.suites++;
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
runner.on('test end', function () {
|
|
297
|
-
stats.tests = stats.tests || 0;
|
|
298
|
-
stats.tests++;
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
runner.on('pass', function (test) {
|
|
302
|
-
stats.passes = stats.passes || 0;
|
|
303
|
-
|
|
280
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
304
281
|
if (test.duration > test.slow()) {
|
|
305
282
|
test.speed = 'slow';
|
|
306
283
|
} else if (test.duration > test.slow() / 2) {
|
|
@@ -308,28 +285,15 @@ function Base (runner) {
|
|
|
308
285
|
} else {
|
|
309
286
|
test.speed = 'fast';
|
|
310
287
|
}
|
|
311
|
-
|
|
312
|
-
stats.passes++;
|
|
313
288
|
});
|
|
314
289
|
|
|
315
|
-
runner.on(
|
|
316
|
-
stats.failures = stats.failures || 0;
|
|
317
|
-
stats.failures++;
|
|
290
|
+
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
|
318
291
|
if (showDiff(err)) {
|
|
319
292
|
stringifyDiffObjs(err);
|
|
320
293
|
}
|
|
321
294
|
test.err = err;
|
|
322
295
|
failures.push(test);
|
|
323
296
|
});
|
|
324
|
-
|
|
325
|
-
runner.once('end', function () {
|
|
326
|
-
stats.end = new Date();
|
|
327
|
-
stats.duration = stats.end - stats.start;
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
runner.on('pending', function () {
|
|
331
|
-
stats.pending++;
|
|
332
|
-
});
|
|
333
297
|
}
|
|
334
298
|
|
|
335
299
|
/**
|
|
@@ -338,27 +302,24 @@ function Base (runner) {
|
|
|
338
302
|
*
|
|
339
303
|
* @memberof Mocha.reporters.Base
|
|
340
304
|
* @public
|
|
341
|
-
* @api public
|
|
342
305
|
*/
|
|
343
|
-
Base.prototype.epilogue = function
|
|
306
|
+
Base.prototype.epilogue = function() {
|
|
344
307
|
var stats = this.stats;
|
|
345
308
|
var fmt;
|
|
346
309
|
|
|
347
310
|
console.log();
|
|
348
311
|
|
|
349
312
|
// passes
|
|
350
|
-
fmt =
|
|
313
|
+
fmt =
|
|
314
|
+
color('bright pass', ' ') +
|
|
351
315
|
color('green', ' %d passing') +
|
|
352
316
|
color('light', ' (%s)');
|
|
353
317
|
|
|
354
|
-
console.log(fmt,
|
|
355
|
-
stats.passes || 0,
|
|
356
|
-
ms(stats.duration));
|
|
318
|
+
console.log(fmt, stats.passes || 0, milliseconds(stats.duration));
|
|
357
319
|
|
|
358
320
|
// pending
|
|
359
321
|
if (stats.pending) {
|
|
360
|
-
fmt = color('pending', ' ') +
|
|
361
|
-
color('pending', ' %d pending');
|
|
322
|
+
fmt = color('pending', ' ') + color('pending', ' %d pending');
|
|
362
323
|
|
|
363
324
|
console.log(fmt, stats.pending);
|
|
364
325
|
}
|
|
@@ -379,12 +340,12 @@ Base.prototype.epilogue = function () {
|
|
|
379
340
|
/**
|
|
380
341
|
* Pad the given `str` to `len`.
|
|
381
342
|
*
|
|
382
|
-
* @
|
|
343
|
+
* @private
|
|
383
344
|
* @param {string} str
|
|
384
345
|
* @param {string} len
|
|
385
346
|
* @return {string}
|
|
386
347
|
*/
|
|
387
|
-
function pad
|
|
348
|
+
function pad(str, len) {
|
|
388
349
|
str = String(str);
|
|
389
350
|
return Array(len - str.length + 1).join(' ') + str;
|
|
390
351
|
}
|
|
@@ -392,25 +353,28 @@ function pad (str, len) {
|
|
|
392
353
|
/**
|
|
393
354
|
* Returns an inline diff between 2 strings with coloured ANSI output.
|
|
394
355
|
*
|
|
395
|
-
* @
|
|
356
|
+
* @private
|
|
396
357
|
* @param {String} actual
|
|
397
358
|
* @param {String} expected
|
|
398
359
|
* @return {string} Diff
|
|
399
360
|
*/
|
|
400
|
-
function inlineDiff
|
|
361
|
+
function inlineDiff(actual, expected) {
|
|
401
362
|
var msg = errorDiff(actual, expected);
|
|
402
363
|
|
|
403
364
|
// linenos
|
|
404
365
|
var lines = msg.split('\n');
|
|
405
366
|
if (lines.length > 4) {
|
|
406
367
|
var width = String(lines.length).length;
|
|
407
|
-
msg = lines
|
|
408
|
-
|
|
409
|
-
|
|
368
|
+
msg = lines
|
|
369
|
+
.map(function(str, i) {
|
|
370
|
+
return pad(++i, width) + ' |' + ' ' + str;
|
|
371
|
+
})
|
|
372
|
+
.join('\n');
|
|
410
373
|
}
|
|
411
374
|
|
|
412
375
|
// legend
|
|
413
|
-
msg =
|
|
376
|
+
msg =
|
|
377
|
+
'\n' +
|
|
414
378
|
color('diff removed', 'actual') +
|
|
415
379
|
' ' +
|
|
416
380
|
color('diff added', 'expected') +
|
|
@@ -426,14 +390,14 @@ function inlineDiff (actual, expected) {
|
|
|
426
390
|
/**
|
|
427
391
|
* Returns a unified diff between two strings with coloured ANSI output.
|
|
428
392
|
*
|
|
429
|
-
* @
|
|
393
|
+
* @private
|
|
430
394
|
* @param {String} actual
|
|
431
395
|
* @param {String} expected
|
|
432
396
|
* @return {string} The diff.
|
|
433
397
|
*/
|
|
434
|
-
function unifiedDiff
|
|
398
|
+
function unifiedDiff(actual, expected) {
|
|
435
399
|
var indent = ' ';
|
|
436
|
-
function cleanUp
|
|
400
|
+
function cleanUp(line) {
|
|
437
401
|
if (line[0] === '+') {
|
|
438
402
|
return indent + colorLines('diff added', line);
|
|
439
403
|
}
|
|
@@ -448,50 +412,62 @@ function unifiedDiff (actual, expected) {
|
|
|
448
412
|
}
|
|
449
413
|
return indent + line;
|
|
450
414
|
}
|
|
451
|
-
function notBlank
|
|
415
|
+
function notBlank(line) {
|
|
452
416
|
return typeof line !== 'undefined' && line !== null;
|
|
453
417
|
}
|
|
454
418
|
var msg = diff.createPatch('string', actual, expected);
|
|
455
419
|
var lines = msg.split('\n').splice(5);
|
|
456
|
-
return
|
|
457
|
-
|
|
420
|
+
return (
|
|
421
|
+
'\n ' +
|
|
422
|
+
colorLines('diff added', '+ expected') +
|
|
423
|
+
' ' +
|
|
458
424
|
colorLines('diff removed', '- actual') +
|
|
459
425
|
'\n\n' +
|
|
460
|
-
lines
|
|
426
|
+
lines
|
|
427
|
+
.map(cleanUp)
|
|
428
|
+
.filter(notBlank)
|
|
429
|
+
.join('\n')
|
|
430
|
+
);
|
|
461
431
|
}
|
|
462
432
|
|
|
463
433
|
/**
|
|
464
434
|
* Return a character diff for `err`.
|
|
465
435
|
*
|
|
466
|
-
* @
|
|
436
|
+
* @private
|
|
467
437
|
* @param {String} actual
|
|
468
438
|
* @param {String} expected
|
|
469
439
|
* @return {string} the diff
|
|
470
440
|
*/
|
|
471
|
-
function errorDiff
|
|
472
|
-
return diff
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
441
|
+
function errorDiff(actual, expected) {
|
|
442
|
+
return diff
|
|
443
|
+
.diffWordsWithSpace(actual, expected)
|
|
444
|
+
.map(function(str) {
|
|
445
|
+
if (str.added) {
|
|
446
|
+
return colorLines('diff added', str.value);
|
|
447
|
+
}
|
|
448
|
+
if (str.removed) {
|
|
449
|
+
return colorLines('diff removed', str.value);
|
|
450
|
+
}
|
|
451
|
+
return str.value;
|
|
452
|
+
})
|
|
453
|
+
.join('');
|
|
481
454
|
}
|
|
482
455
|
|
|
483
456
|
/**
|
|
484
457
|
* Color lines for `str`, using the color `name`.
|
|
485
458
|
*
|
|
486
|
-
* @
|
|
459
|
+
* @private
|
|
487
460
|
* @param {string} name
|
|
488
461
|
* @param {string} str
|
|
489
462
|
* @return {string}
|
|
490
463
|
*/
|
|
491
|
-
function colorLines
|
|
492
|
-
return str
|
|
493
|
-
|
|
494
|
-
|
|
464
|
+
function colorLines(name, str) {
|
|
465
|
+
return str
|
|
466
|
+
.split('\n')
|
|
467
|
+
.map(function(str) {
|
|
468
|
+
return color(name, str);
|
|
469
|
+
})
|
|
470
|
+
.join('\n');
|
|
495
471
|
}
|
|
496
472
|
|
|
497
473
|
/**
|
|
@@ -502,11 +478,13 @@ var objToString = Object.prototype.toString;
|
|
|
502
478
|
/**
|
|
503
479
|
* Check that a / b have the same type.
|
|
504
480
|
*
|
|
505
|
-
* @
|
|
481
|
+
* @private
|
|
506
482
|
* @param {Object} a
|
|
507
483
|
* @param {Object} b
|
|
508
484
|
* @return {boolean}
|
|
509
485
|
*/
|
|
510
|
-
function sameType
|
|
486
|
+
function sameType(a, b) {
|
|
511
487
|
return objToString.call(a) === objToString.call(b);
|
|
512
488
|
}
|
|
489
|
+
|
|
490
|
+
Base.abstract = true;
|
package/lib/reporters/doc.js
CHANGED
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
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;
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* Expose `Doc`.
|
|
@@ -23,18 +28,17 @@ exports = module.exports = Doc;
|
|
|
23
28
|
* @extends {Base}
|
|
24
29
|
* @public
|
|
25
30
|
* @param {Runner} runner
|
|
26
|
-
* @api public
|
|
27
31
|
*/
|
|
28
|
-
function Doc
|
|
32
|
+
function Doc(runner) {
|
|
29
33
|
Base.call(this, runner);
|
|
30
34
|
|
|
31
35
|
var indents = 2;
|
|
32
36
|
|
|
33
|
-
function indent
|
|
37
|
+
function indent() {
|
|
34
38
|
return Array(indents).join(' ');
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
runner.on(
|
|
41
|
+
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
|
38
42
|
if (suite.root) {
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
@@ -45,7 +49,7 @@ function Doc (runner) {
|
|
|
45
49
|
console.log('%s<dl>', indent());
|
|
46
50
|
});
|
|
47
51
|
|
|
48
|
-
runner.on(
|
|
52
|
+
runner.on(EVENT_SUITE_END, function(suite) {
|
|
49
53
|
if (suite.root) {
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
@@ -55,16 +59,26 @@ function Doc (runner) {
|
|
|
55
59
|
--indents;
|
|
56
60
|
});
|
|
57
61
|
|
|
58
|
-
runner.on(
|
|
62
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
59
63
|
console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
|
|
60
64
|
var code = utils.escape(utils.clean(test.body));
|
|
61
65
|
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
|
|
62
66
|
});
|
|
63
67
|
|
|
64
|
-
runner.on(
|
|
65
|
-
console.log(
|
|
68
|
+
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
|
69
|
+
console.log(
|
|
70
|
+
'%s <dt class="error">%s</dt>',
|
|
71
|
+
indent(),
|
|
72
|
+
utils.escape(test.title)
|
|
73
|
+
);
|
|
66
74
|
var code = utils.escape(utils.clean(test.body));
|
|
67
|
-
console.log(
|
|
75
|
+
console.log(
|
|
76
|
+
'%s <dd class="error"><pre><code>%s</code></pre></dd>',
|
|
77
|
+
indent(),
|
|
78
|
+
code
|
|
79
|
+
);
|
|
68
80
|
console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
|
|
69
81
|
});
|
|
70
82
|
}
|
|
83
|
+
|
|
84
|
+
Doc.description = 'HTML documentation';
|
package/lib/reporters/dot.js
CHANGED
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
var Base = require('./base');
|
|
10
10
|
var inherits = require('../utils').inherits;
|
|
11
|
-
var
|
|
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;
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
19
|
* Expose `Dot`.
|
|
@@ -23,46 +28,45 @@ exports = module.exports = Dot;
|
|
|
23
28
|
* @memberof Mocha.reporters
|
|
24
29
|
* @extends Mocha.reporters.Base
|
|
25
30
|
* @public
|
|
26
|
-
* @api public
|
|
27
31
|
* @param {Runner} runner
|
|
28
32
|
*/
|
|
29
|
-
function Dot
|
|
33
|
+
function Dot(runner) {
|
|
30
34
|
Base.call(this, runner);
|
|
31
35
|
|
|
32
36
|
var self = this;
|
|
33
|
-
var width = Base.window.width * 0.75 | 0;
|
|
37
|
+
var width = (Base.window.width * 0.75) | 0;
|
|
34
38
|
var n = -1;
|
|
35
39
|
|
|
36
|
-
runner.on(
|
|
40
|
+
runner.on(EVENT_RUN_BEGIN, function() {
|
|
37
41
|
process.stdout.write('\n');
|
|
38
42
|
});
|
|
39
43
|
|
|
40
|
-
runner.on(
|
|
44
|
+
runner.on(EVENT_TEST_PENDING, function() {
|
|
41
45
|
if (++n % width === 0) {
|
|
42
46
|
process.stdout.write('\n ');
|
|
43
47
|
}
|
|
44
|
-
process.stdout.write(color('pending', Base.symbols.comma));
|
|
48
|
+
process.stdout.write(Base.color('pending', Base.symbols.comma));
|
|
45
49
|
});
|
|
46
50
|
|
|
47
|
-
runner.on(
|
|
51
|
+
runner.on(EVENT_TEST_PASS, function(test) {
|
|
48
52
|
if (++n % width === 0) {
|
|
49
53
|
process.stdout.write('\n ');
|
|
50
54
|
}
|
|
51
55
|
if (test.speed === 'slow') {
|
|
52
|
-
process.stdout.write(color('bright yellow', Base.symbols.dot));
|
|
56
|
+
process.stdout.write(Base.color('bright yellow', Base.symbols.dot));
|
|
53
57
|
} else {
|
|
54
|
-
process.stdout.write(color(test.speed, Base.symbols.dot));
|
|
58
|
+
process.stdout.write(Base.color(test.speed, Base.symbols.dot));
|
|
55
59
|
}
|
|
56
60
|
});
|
|
57
61
|
|
|
58
|
-
runner.on(
|
|
62
|
+
runner.on(EVENT_TEST_FAIL, function() {
|
|
59
63
|
if (++n % width === 0) {
|
|
60
64
|
process.stdout.write('\n ');
|
|
61
65
|
}
|
|
62
|
-
process.stdout.write(color('fail', Base.symbols.bang));
|
|
66
|
+
process.stdout.write(Base.color('fail', Base.symbols.bang));
|
|
63
67
|
});
|
|
64
68
|
|
|
65
|
-
runner.once(
|
|
69
|
+
runner.once(EVENT_RUN_END, function() {
|
|
66
70
|
console.log();
|
|
67
71
|
self.epilogue();
|
|
68
72
|
});
|
|
@@ -72,3 +76,5 @@ function Dot (runner) {
|
|
|
72
76
|
* Inherit from `Base.prototype`.
|
|
73
77
|
*/
|
|
74
78
|
inherits(Dot, Base);
|
|
79
|
+
|
|
80
|
+
Dot.description = 'dot matrix representation';
|