mocha 2.2.5 → 2.3.3
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/HISTORY.md +1034 -0
- package/bin/.eslintrc +3 -0
- package/bin/_mocha +12 -15
- package/bin/mocha +3 -10
- package/bin/options.js +6 -5
- package/lib/browser/debug.js +3 -3
- package/lib/browser/events.js +42 -26
- package/lib/browser/progress.js +37 -45
- package/lib/browser/tty.js +4 -5
- package/lib/context.js +26 -32
- package/lib/hook.js +5 -7
- package/lib/interfaces/bdd.js +21 -26
- package/lib/interfaces/common.js +33 -15
- package/lib/interfaces/exports.js +7 -7
- package/lib/interfaces/qunit.js +16 -17
- package/lib/interfaces/tdd.js +24 -28
- package/lib/mocha.js +140 -99
- package/lib/ms.js +43 -24
- package/lib/pending.js +2 -3
- package/lib/reporters/base.js +159 -138
- package/lib/reporters/doc.js +13 -13
- package/lib/reporters/dot.js +23 -19
- package/lib/reporters/html-cov.js +25 -19
- package/lib/reporters/html.js +130 -91
- package/lib/reporters/index.js +19 -17
- package/lib/reporters/json-cov.js +39 -41
- package/lib/reporters/json-stream.js +14 -17
- package/lib/reporters/json.js +16 -19
- package/lib/reporters/landing.js +20 -24
- package/lib/reporters/list.js +14 -16
- package/lib/reporters/markdown.js +17 -20
- package/lib/reporters/min.js +4 -5
- package/lib/reporters/nyan.js +49 -48
- package/lib/reporters/progress.js +20 -23
- package/lib/reporters/spec.js +23 -22
- package/lib/reporters/tap.js +15 -19
- package/lib/reporters/xunit.js +83 -63
- package/lib/runnable.js +134 -94
- package/lib/runner.js +291 -167
- package/lib/suite.js +105 -95
- package/lib/template.html +1 -1
- package/lib/test.js +3 -4
- package/lib/utils.js +227 -199
- package/mocha.css +35 -0
- package/mocha.js +8324 -2471
- package/package.json +250 -10
- package/lib/browser/escape-string-regexp.js +0 -11
- package/lib/browser/fs.js +0 -0
- package/lib/browser/glob.js +0 -0
- package/lib/browser/path.js +0 -0
package/lib/reporters/base.js
CHANGED
|
@@ -2,41 +2,42 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var tty = require('tty')
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
var tty = require('tty');
|
|
6
|
+
var diff = require('diff');
|
|
7
|
+
var ms = require('../ms');
|
|
8
|
+
var utils = require('../utils');
|
|
9
|
+
var supportsColor = process.browser ? null : require('supports-color');
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Expose `Base`.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
, setTimeout = global.setTimeout
|
|
17
|
-
, setInterval = global.setInterval
|
|
18
|
-
, clearTimeout = global.clearTimeout
|
|
19
|
-
, clearInterval = global.clearInterval;
|
|
15
|
+
exports = module.exports = Base;
|
|
20
16
|
|
|
21
17
|
/**
|
|
22
|
-
*
|
|
18
|
+
* Save timer references to avoid Sinon interfering.
|
|
19
|
+
* See: https://github.com/mochajs/mocha/issues/237
|
|
23
20
|
*/
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
/* eslint-disable no-unused-vars, no-native-reassign */
|
|
23
|
+
var Date = global.Date;
|
|
24
|
+
var setTimeout = global.setTimeout;
|
|
25
|
+
var setInterval = global.setInterval;
|
|
26
|
+
var clearTimeout = global.clearTimeout;
|
|
27
|
+
var clearInterval = global.clearInterval;
|
|
28
|
+
/* eslint-enable no-unused-vars, no-native-reassign */
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
31
|
+
* Check if both stdio streams are associated with a tty.
|
|
29
32
|
*/
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
var isatty = tty.isatty(1) && tty.isatty(2);
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* Enable coloring by default, except in the browser interface.
|
|
35
38
|
*/
|
|
36
39
|
|
|
37
|
-
exports.useColors = process.env
|
|
38
|
-
? (supportsColor || (process.env.MOCHA_COLORS !== undefined))
|
|
39
|
-
: false;
|
|
40
|
+
exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* Inline diffs instead of +/-
|
|
@@ -49,25 +50,25 @@ exports.inlineDiffs = false;
|
|
|
49
50
|
*/
|
|
50
51
|
|
|
51
52
|
exports.colors = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
pass: 90,
|
|
54
|
+
fail: 31,
|
|
55
|
+
'bright pass': 92,
|
|
56
|
+
'bright fail': 91,
|
|
57
|
+
'bright yellow': 93,
|
|
58
|
+
pending: 36,
|
|
59
|
+
suite: 0,
|
|
60
|
+
'error title': 0,
|
|
61
|
+
'error message': 31,
|
|
62
|
+
'error stack': 90,
|
|
63
|
+
checkmark: 32,
|
|
64
|
+
fast: 90,
|
|
65
|
+
medium: 33,
|
|
66
|
+
slow: 31,
|
|
67
|
+
green: 32,
|
|
68
|
+
light: 90,
|
|
69
|
+
'diff gutter': 90,
|
|
70
|
+
'diff added': 32,
|
|
71
|
+
'diff removed': 31
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
/**
|
|
@@ -81,7 +82,7 @@ exports.symbols = {
|
|
|
81
82
|
};
|
|
82
83
|
|
|
83
84
|
// With node.js on Windows: use symbols available in terminal default fonts
|
|
84
|
-
if ('win32'
|
|
85
|
+
if (process.platform === 'win32') {
|
|
85
86
|
exports.symbols.ok = '\u221A';
|
|
86
87
|
exports.symbols.err = '\u00D7';
|
|
87
88
|
exports.symbols.dot = '.';
|
|
@@ -93,53 +94,54 @@ if ('win32' == process.platform) {
|
|
|
93
94
|
* as well as user-defined color
|
|
94
95
|
* schemes.
|
|
95
96
|
*
|
|
96
|
-
* @param {
|
|
97
|
-
* @param {
|
|
98
|
-
* @return {
|
|
97
|
+
* @param {string} type
|
|
98
|
+
* @param {string} str
|
|
99
|
+
* @return {string}
|
|
99
100
|
* @api private
|
|
100
101
|
*/
|
|
101
|
-
|
|
102
102
|
var color = exports.color = function(type, str) {
|
|
103
|
-
if (!exports.useColors)
|
|
103
|
+
if (!exports.useColors) {
|
|
104
|
+
return String(str);
|
|
105
|
+
}
|
|
104
106
|
return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
|
|
105
107
|
};
|
|
106
108
|
|
|
107
109
|
/**
|
|
108
|
-
* Expose term window size, with some
|
|
109
|
-
* defaults for when stderr is not a tty.
|
|
110
|
+
* Expose term window size, with some defaults for when stderr is not a tty.
|
|
110
111
|
*/
|
|
111
112
|
|
|
112
113
|
exports.window = {
|
|
113
|
-
width:
|
|
114
|
-
? process.stdout.getWindowSize
|
|
115
|
-
? process.stdout.getWindowSize(1)[0]
|
|
116
|
-
: tty.getWindowSize()[1]
|
|
117
|
-
: 75
|
|
114
|
+
width: 75
|
|
118
115
|
};
|
|
119
116
|
|
|
117
|
+
if (isatty) {
|
|
118
|
+
exports.window.width = process.stdout.getWindowSize
|
|
119
|
+
? process.stdout.getWindowSize(1)[0]
|
|
120
|
+
: tty.getWindowSize()[1];
|
|
121
|
+
}
|
|
122
|
+
|
|
120
123
|
/**
|
|
121
|
-
* Expose some basic cursor interactions
|
|
122
|
-
* that are common among reporters.
|
|
124
|
+
* Expose some basic cursor interactions that are common among reporters.
|
|
123
125
|
*/
|
|
124
126
|
|
|
125
127
|
exports.cursor = {
|
|
126
|
-
hide: function(){
|
|
128
|
+
hide: function() {
|
|
127
129
|
isatty && process.stdout.write('\u001b[?25l');
|
|
128
130
|
},
|
|
129
131
|
|
|
130
|
-
show: function(){
|
|
132
|
+
show: function() {
|
|
131
133
|
isatty && process.stdout.write('\u001b[?25h');
|
|
132
134
|
},
|
|
133
135
|
|
|
134
|
-
deleteLine: function(){
|
|
136
|
+
deleteLine: function() {
|
|
135
137
|
isatty && process.stdout.write('\u001b[2K');
|
|
136
138
|
},
|
|
137
139
|
|
|
138
|
-
beginningOfLine: function(){
|
|
140
|
+
beginningOfLine: function() {
|
|
139
141
|
isatty && process.stdout.write('\u001b[0G');
|
|
140
142
|
},
|
|
141
143
|
|
|
142
|
-
CR: function(){
|
|
144
|
+
CR: function() {
|
|
143
145
|
if (isatty) {
|
|
144
146
|
exports.cursor.deleteLine();
|
|
145
147
|
exports.cursor.beginningOfLine();
|
|
@@ -156,22 +158,31 @@ exports.cursor = {
|
|
|
156
158
|
* @api public
|
|
157
159
|
*/
|
|
158
160
|
|
|
159
|
-
exports.list = function(failures){
|
|
161
|
+
exports.list = function(failures) {
|
|
160
162
|
console.log();
|
|
161
|
-
failures.forEach(function(test, i){
|
|
163
|
+
failures.forEach(function(test, i) {
|
|
162
164
|
// format
|
|
163
165
|
var fmt = color('error title', ' %s) %s:\n')
|
|
164
166
|
+ color('error message', ' %s')
|
|
165
167
|
+ color('error stack', '\n%s\n');
|
|
166
168
|
|
|
167
169
|
// msg
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
var msg;
|
|
171
|
+
var err = test.err;
|
|
172
|
+
var message;
|
|
173
|
+
if (err.message) {
|
|
174
|
+
message = err.message;
|
|
175
|
+
} else if (typeof err.inspect === 'function') {
|
|
176
|
+
message = err.inspect() + '';
|
|
177
|
+
} else {
|
|
178
|
+
message = '';
|
|
179
|
+
}
|
|
180
|
+
var stack = err.stack || message;
|
|
181
|
+
var index = stack.indexOf(message);
|
|
182
|
+
var actual = err.actual;
|
|
183
|
+
var expected = err.expected;
|
|
184
|
+
var escape = true;
|
|
185
|
+
|
|
175
186
|
if (index === -1) {
|
|
176
187
|
msg = message;
|
|
177
188
|
} else {
|
|
@@ -186,9 +197,7 @@ exports.list = function(failures){
|
|
|
186
197
|
msg = 'Uncaught ' + msg;
|
|
187
198
|
}
|
|
188
199
|
// explicitly show diff
|
|
189
|
-
if (err.showDiff !== false && sameType(actual, expected)
|
|
190
|
-
&& expected !== undefined) {
|
|
191
|
-
|
|
200
|
+
if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
|
|
192
201
|
escape = false;
|
|
193
202
|
if (!(utils.isString(actual) && utils.isString(expected))) {
|
|
194
203
|
err.actual = actual = utils.stringify(actual);
|
|
@@ -226,55 +235,57 @@ exports.list = function(failures){
|
|
|
226
235
|
*/
|
|
227
236
|
|
|
228
237
|
function Base(runner) {
|
|
229
|
-
var
|
|
230
|
-
|
|
231
|
-
, failures = this.failures = [];
|
|
238
|
+
var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
|
|
239
|
+
var failures = this.failures = [];
|
|
232
240
|
|
|
233
|
-
if (!runner)
|
|
241
|
+
if (!runner) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
234
244
|
this.runner = runner;
|
|
235
245
|
|
|
236
246
|
runner.stats = stats;
|
|
237
247
|
|
|
238
|
-
runner.on('start', function(){
|
|
239
|
-
stats.start = new Date;
|
|
248
|
+
runner.on('start', function() {
|
|
249
|
+
stats.start = new Date();
|
|
240
250
|
});
|
|
241
251
|
|
|
242
|
-
runner.on('suite', function(suite){
|
|
252
|
+
runner.on('suite', function(suite) {
|
|
243
253
|
stats.suites = stats.suites || 0;
|
|
244
254
|
suite.root || stats.suites++;
|
|
245
255
|
});
|
|
246
256
|
|
|
247
|
-
runner.on('test end', function(
|
|
257
|
+
runner.on('test end', function() {
|
|
248
258
|
stats.tests = stats.tests || 0;
|
|
249
259
|
stats.tests++;
|
|
250
260
|
});
|
|
251
261
|
|
|
252
|
-
runner.on('pass', function(test){
|
|
262
|
+
runner.on('pass', function(test) {
|
|
253
263
|
stats.passes = stats.passes || 0;
|
|
254
264
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
265
|
+
if (test.duration > test.slow()) {
|
|
266
|
+
test.speed = 'slow';
|
|
267
|
+
} else if (test.duration > test.slow() / 2) {
|
|
268
|
+
test.speed = 'medium';
|
|
269
|
+
} else {
|
|
270
|
+
test.speed = 'fast';
|
|
271
|
+
}
|
|
261
272
|
|
|
262
273
|
stats.passes++;
|
|
263
274
|
});
|
|
264
275
|
|
|
265
|
-
runner.on('fail', function(test, err){
|
|
276
|
+
runner.on('fail', function(test, err) {
|
|
266
277
|
stats.failures = stats.failures || 0;
|
|
267
278
|
stats.failures++;
|
|
268
279
|
test.err = err;
|
|
269
280
|
failures.push(test);
|
|
270
281
|
});
|
|
271
282
|
|
|
272
|
-
runner.on('end', function(){
|
|
273
|
-
stats.end = new Date;
|
|
274
|
-
stats.duration = new Date - stats.start;
|
|
283
|
+
runner.on('end', function() {
|
|
284
|
+
stats.end = new Date();
|
|
285
|
+
stats.duration = new Date() - stats.start;
|
|
275
286
|
});
|
|
276
287
|
|
|
277
|
-
runner.on('pending', function(){
|
|
288
|
+
runner.on('pending', function() {
|
|
278
289
|
stats.pending++;
|
|
279
290
|
});
|
|
280
291
|
}
|
|
@@ -285,10 +296,8 @@ function Base(runner) {
|
|
|
285
296
|
*
|
|
286
297
|
* @api public
|
|
287
298
|
*/
|
|
288
|
-
|
|
289
|
-
Base.prototype.epilogue = function(){
|
|
299
|
+
Base.prototype.epilogue = function() {
|
|
290
300
|
var stats = this.stats;
|
|
291
|
-
var tests;
|
|
292
301
|
var fmt;
|
|
293
302
|
|
|
294
303
|
console.log();
|
|
@@ -326,26 +335,24 @@ Base.prototype.epilogue = function(){
|
|
|
326
335
|
/**
|
|
327
336
|
* Pad the given `str` to `len`.
|
|
328
337
|
*
|
|
329
|
-
* @param {String} str
|
|
330
|
-
* @param {String} len
|
|
331
|
-
* @return {String}
|
|
332
338
|
* @api private
|
|
339
|
+
* @param {string} str
|
|
340
|
+
* @param {string} len
|
|
341
|
+
* @return {string}
|
|
333
342
|
*/
|
|
334
|
-
|
|
335
343
|
function pad(str, len) {
|
|
336
344
|
str = String(str);
|
|
337
345
|
return Array(len - str.length + 1).join(' ') + str;
|
|
338
346
|
}
|
|
339
347
|
|
|
340
|
-
|
|
341
348
|
/**
|
|
342
349
|
* Returns an inline diff between 2 strings with coloured ANSI output
|
|
343
350
|
*
|
|
344
|
-
* @param {Error} Error with actual/expected
|
|
345
|
-
* @return {String} Diff
|
|
346
351
|
* @api private
|
|
352
|
+
* @param {Error} err with actual/expected
|
|
353
|
+
* @param {boolean} escape
|
|
354
|
+
* @return {string} Diff
|
|
347
355
|
*/
|
|
348
|
-
|
|
349
356
|
function inlineDiff(err, escape) {
|
|
350
357
|
var msg = errorDiff(err, 'WordsWithSpace', escape);
|
|
351
358
|
|
|
@@ -353,7 +360,7 @@ function inlineDiff(err, escape) {
|
|
|
353
360
|
var lines = msg.split('\n');
|
|
354
361
|
if (lines.length > 4) {
|
|
355
362
|
var width = String(lines.length).length;
|
|
356
|
-
msg = lines.map(function(str, i){
|
|
363
|
+
msg = lines.map(function(str, i) {
|
|
357
364
|
return pad(++i, width) + ' |' + ' ' + str;
|
|
358
365
|
}).join('\n');
|
|
359
366
|
}
|
|
@@ -373,51 +380,64 @@ function inlineDiff(err, escape) {
|
|
|
373
380
|
}
|
|
374
381
|
|
|
375
382
|
/**
|
|
376
|
-
* Returns a unified diff between
|
|
383
|
+
* Returns a unified diff between two strings.
|
|
377
384
|
*
|
|
378
|
-
* @param {Error} Error with actual/expected
|
|
379
|
-
* @return {String} Diff
|
|
380
385
|
* @api private
|
|
386
|
+
* @param {Error} err with actual/expected
|
|
387
|
+
* @param {boolean} escape
|
|
388
|
+
* @return {string} The diff.
|
|
381
389
|
*/
|
|
382
|
-
|
|
383
390
|
function unifiedDiff(err, escape) {
|
|
384
391
|
var indent = ' ';
|
|
385
392
|
function cleanUp(line) {
|
|
386
393
|
if (escape) {
|
|
387
394
|
line = escapeInvisibles(line);
|
|
388
395
|
}
|
|
389
|
-
if (line[0] === '+')
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (line
|
|
393
|
-
|
|
396
|
+
if (line[0] === '+') {
|
|
397
|
+
return indent + colorLines('diff added', line);
|
|
398
|
+
}
|
|
399
|
+
if (line[0] === '-') {
|
|
400
|
+
return indent + colorLines('diff removed', line);
|
|
401
|
+
}
|
|
402
|
+
if (line.match(/\@\@/)) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
if (line.match(/\\ No newline/)) {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
return indent + line;
|
|
394
409
|
}
|
|
395
410
|
function notBlank(line) {
|
|
396
|
-
return line
|
|
411
|
+
return typeof line !== 'undefined' && line !== null;
|
|
397
412
|
}
|
|
398
413
|
var msg = diff.createPatch('string', err.actual, err.expected);
|
|
399
414
|
var lines = msg.split('\n').splice(4);
|
|
400
415
|
return '\n '
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
416
|
+
+ colorLines('diff added', '+ expected') + ' '
|
|
417
|
+
+ colorLines('diff removed', '- actual')
|
|
418
|
+
+ '\n\n'
|
|
419
|
+
+ lines.map(cleanUp).filter(notBlank).join('\n');
|
|
405
420
|
}
|
|
406
421
|
|
|
407
422
|
/**
|
|
408
423
|
* Return a character diff for `err`.
|
|
409
424
|
*
|
|
410
|
-
* @param {Error} err
|
|
411
|
-
* @return {String}
|
|
412
425
|
* @api private
|
|
426
|
+
* @param {Error} err
|
|
427
|
+
* @param {string} type
|
|
428
|
+
* @param {boolean} escape
|
|
429
|
+
* @return {string}
|
|
413
430
|
*/
|
|
414
|
-
|
|
415
431
|
function errorDiff(err, type, escape) {
|
|
416
|
-
var actual
|
|
432
|
+
var actual = escape ? escapeInvisibles(err.actual) : err.actual;
|
|
417
433
|
var expected = escape ? escapeInvisibles(err.expected) : err.expected;
|
|
418
|
-
return diff['diff' + type](actual, expected).map(function(str){
|
|
419
|
-
if (str.added)
|
|
420
|
-
|
|
434
|
+
return diff['diff' + type](actual, expected).map(function(str) {
|
|
435
|
+
if (str.added) {
|
|
436
|
+
return colorLines('diff added', str.value);
|
|
437
|
+
}
|
|
438
|
+
if (str.removed) {
|
|
439
|
+
return colorLines('diff removed', str.value);
|
|
440
|
+
}
|
|
421
441
|
return str.value;
|
|
422
442
|
}).join('');
|
|
423
443
|
}
|
|
@@ -425,42 +445,43 @@ function errorDiff(err, type, escape) {
|
|
|
425
445
|
/**
|
|
426
446
|
* Returns a string with all invisible characters in plain text
|
|
427
447
|
*
|
|
428
|
-
* @param {String} line
|
|
429
|
-
* @return {String}
|
|
430
448
|
* @api private
|
|
449
|
+
* @param {string} line
|
|
450
|
+
* @return {string}
|
|
431
451
|
*/
|
|
432
452
|
function escapeInvisibles(line) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
453
|
+
return line.replace(/\t/g, '<tab>')
|
|
454
|
+
.replace(/\r/g, '<CR>')
|
|
455
|
+
.replace(/\n/g, '<LF>\n');
|
|
436
456
|
}
|
|
437
457
|
|
|
438
458
|
/**
|
|
439
459
|
* Color lines for `str`, using the color `name`.
|
|
440
460
|
*
|
|
441
|
-
* @param {String} name
|
|
442
|
-
* @param {String} str
|
|
443
|
-
* @return {String}
|
|
444
461
|
* @api private
|
|
462
|
+
* @param {string} name
|
|
463
|
+
* @param {string} str
|
|
464
|
+
* @return {string}
|
|
445
465
|
*/
|
|
446
|
-
|
|
447
466
|
function colorLines(name, str) {
|
|
448
|
-
return str.split('\n').map(function(str){
|
|
467
|
+
return str.split('\n').map(function(str) {
|
|
449
468
|
return color(name, str);
|
|
450
469
|
}).join('\n');
|
|
451
470
|
}
|
|
452
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Object#toString reference.
|
|
474
|
+
*/
|
|
475
|
+
var objToString = Object.prototype.toString;
|
|
476
|
+
|
|
453
477
|
/**
|
|
454
478
|
* Check that a / b have the same type.
|
|
455
479
|
*
|
|
480
|
+
* @api private
|
|
456
481
|
* @param {Object} a
|
|
457
482
|
* @param {Object} b
|
|
458
|
-
* @return {
|
|
459
|
-
* @api private
|
|
483
|
+
* @return {boolean}
|
|
460
484
|
*/
|
|
461
|
-
|
|
462
485
|
function sameType(a, b) {
|
|
463
|
-
a
|
|
464
|
-
b = Object.prototype.toString.call(b);
|
|
465
|
-
return a == b;
|
|
486
|
+
return objToString.call(a) === objToString.call(b);
|
|
466
487
|
}
|
package/lib/reporters/doc.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var Base = require('./base')
|
|
6
|
-
|
|
5
|
+
var Base = require('./base');
|
|
6
|
+
var utils = require('../utils');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Expose `Doc`.
|
|
@@ -17,21 +17,19 @@ exports = module.exports = Doc;
|
|
|
17
17
|
* @param {Runner} runner
|
|
18
18
|
* @api public
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
20
|
function Doc(runner) {
|
|
22
21
|
Base.call(this, runner);
|
|
23
22
|
|
|
24
|
-
var
|
|
25
|
-
, stats = this.stats
|
|
26
|
-
, total = runner.total
|
|
27
|
-
, indents = 2;
|
|
23
|
+
var indents = 2;
|
|
28
24
|
|
|
29
25
|
function indent() {
|
|
30
26
|
return Array(indents).join(' ');
|
|
31
27
|
}
|
|
32
28
|
|
|
33
|
-
runner.on('suite', function(suite){
|
|
34
|
-
if (suite.root)
|
|
29
|
+
runner.on('suite', function(suite) {
|
|
30
|
+
if (suite.root) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
35
33
|
++indents;
|
|
36
34
|
console.log('%s<section class="suite">', indent());
|
|
37
35
|
++indents;
|
|
@@ -39,21 +37,23 @@ function Doc(runner) {
|
|
|
39
37
|
console.log('%s<dl>', indent());
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
runner.on('suite end', function(suite){
|
|
43
|
-
if (suite.root)
|
|
40
|
+
runner.on('suite end', function(suite) {
|
|
41
|
+
if (suite.root) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
44
|
console.log('%s</dl>', indent());
|
|
45
45
|
--indents;
|
|
46
46
|
console.log('%s</section>', indent());
|
|
47
47
|
--indents;
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
runner.on('pass', function(test){
|
|
50
|
+
runner.on('pass', function(test) {
|
|
51
51
|
console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
|
|
52
52
|
var code = utils.escape(utils.clean(test.fn.toString()));
|
|
53
53
|
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
runner.on('fail', function(test, err){
|
|
56
|
+
runner.on('fail', function(test, err) {
|
|
57
57
|
console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
|
|
58
58
|
var code = utils.escape(utils.clean(test.fn.toString()));
|
|
59
59
|
console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
|
package/lib/reporters/dot.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var Base = require('./base')
|
|
6
|
-
|
|
5
|
+
var Base = require('./base');
|
|
6
|
+
var inherits = require('../utils').inherits;
|
|
7
|
+
var color = Base.color;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Expose `Dot`.
|
|
@@ -14,42 +15,46 @@ exports = module.exports = Dot;
|
|
|
14
15
|
/**
|
|
15
16
|
* Initialize a new `Dot` matrix test reporter.
|
|
16
17
|
*
|
|
17
|
-
* @param {Runner} runner
|
|
18
18
|
* @api public
|
|
19
|
+
* @param {Runner} runner
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
21
|
function Dot(runner) {
|
|
22
22
|
Base.call(this, runner);
|
|
23
23
|
|
|
24
|
-
var self = this
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
, n = -1;
|
|
24
|
+
var self = this;
|
|
25
|
+
var width = Base.window.width * .75 | 0;
|
|
26
|
+
var n = -1;
|
|
28
27
|
|
|
29
|
-
runner.on('start', function(){
|
|
28
|
+
runner.on('start', function() {
|
|
30
29
|
process.stdout.write('\n');
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
runner.on('pending', function(
|
|
34
|
-
if (++n % width
|
|
32
|
+
runner.on('pending', function() {
|
|
33
|
+
if (++n % width === 0) {
|
|
34
|
+
process.stdout.write('\n ');
|
|
35
|
+
}
|
|
35
36
|
process.stdout.write(color('pending', Base.symbols.dot));
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
runner.on('pass', function(test){
|
|
39
|
-
if (++n % width
|
|
40
|
-
|
|
39
|
+
runner.on('pass', function(test) {
|
|
40
|
+
if (++n % width === 0) {
|
|
41
|
+
process.stdout.write('\n ');
|
|
42
|
+
}
|
|
43
|
+
if (test.speed === 'slow') {
|
|
41
44
|
process.stdout.write(color('bright yellow', Base.symbols.dot));
|
|
42
45
|
} else {
|
|
43
46
|
process.stdout.write(color(test.speed, Base.symbols.dot));
|
|
44
47
|
}
|
|
45
48
|
});
|
|
46
49
|
|
|
47
|
-
runner.on('fail', function(
|
|
48
|
-
if (++n % width
|
|
50
|
+
runner.on('fail', function() {
|
|
51
|
+
if (++n % width === 0) {
|
|
52
|
+
process.stdout.write('\n ');
|
|
53
|
+
}
|
|
49
54
|
process.stdout.write(color('fail', Base.symbols.dot));
|
|
50
55
|
});
|
|
51
56
|
|
|
52
|
-
runner.on('end', function(){
|
|
57
|
+
runner.on('end', function() {
|
|
53
58
|
console.log();
|
|
54
59
|
self.epilogue();
|
|
55
60
|
});
|
|
@@ -58,5 +63,4 @@ function Dot(runner) {
|
|
|
58
63
|
/**
|
|
59
64
|
* Inherit from `Base.prototype`.
|
|
60
65
|
*/
|
|
61
|
-
|
|
62
|
-
Dot.prototype.__proto__ = Base.prototype;
|
|
66
|
+
inherits(Dot, Base);
|