mocha 5.1.0 → 6.0.0-1
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 +653 -981
- 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 +84 -58
- package/bin/options.js +6 -39
- package/browser-entry.js +21 -17
- package/lib/browser/growl.js +164 -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 +48 -0
- package/lib/cli/one-and-dones.js +70 -0
- package/lib/cli/options.js +299 -0
- package/lib/cli/run-helpers.js +328 -0
- package/lib/cli/run-option-metadata.js +72 -0
- package/lib/cli/run.js +293 -0
- package/lib/context.js +14 -14
- package/lib/errors.js +139 -0
- package/lib/growl.js +135 -0
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +14 -13
- package/lib/interfaces/common.js +59 -16
- package/lib/interfaces/exports.js +4 -7
- package/lib/interfaces/qunit.js +8 -10
- package/lib/interfaces/tdd.js +10 -11
- package/lib/mocha.js +442 -255
- package/lib/mocharc.json +10 -0
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +92 -117
- package/lib/reporters/doc.js +18 -9
- package/lib/reporters/dot.js +13 -13
- package/lib/reporters/html.js +76 -47
- package/lib/reporters/json-stream.js +38 -23
- package/lib/reporters/json.js +26 -23
- package/lib/reporters/landing.js +9 -8
- package/lib/reporters/list.js +11 -10
- package/lib/reporters/markdown.js +13 -12
- package/lib/reporters/min.js +4 -3
- package/lib/reporters/nyan.js +36 -35
- package/lib/reporters/progress.js +8 -7
- package/lib/reporters/spec.js +14 -11
- package/lib/reporters/tap.js +243 -32
- package/lib/reporters/xunit.js +52 -33
- package/lib/runnable.js +103 -90
- package/lib/runner.js +156 -107
- package/lib/stats-collector.js +81 -0
- package/lib/suite.js +57 -51
- package/lib/test.js +13 -13
- package/lib/utils.js +192 -103
- package/mocha.js +3836 -2046
- package/package.json +122 -38
- package/bin/.eslintrc.yml +0 -3
- package/lib/browser/.eslintrc.yml +0 -4
- package/lib/ms.js +0 -94
- package/lib/reporters/base.js.orig +0 -498
- package/lib/reporters/json.js.orig +0 -128
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Provides a factory function for a {@link StatsCollector} object.
|
|
5
|
+
* @private
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Test statistics collector.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
* @typedef {Object} StatsCollector
|
|
14
|
+
* @property {number} suites - integer count of suites run.
|
|
15
|
+
* @property {number} tests - integer count of tests run.
|
|
16
|
+
* @property {number} passes - integer count of passing tests.
|
|
17
|
+
* @property {number} pending - integer count of pending tests.
|
|
18
|
+
* @property {number} failures - integer count of failed tests.
|
|
19
|
+
* @property {Date} start - time when testing began.
|
|
20
|
+
* @property {Date} end - time when testing concluded.
|
|
21
|
+
* @property {number} duration - number of msecs that testing took.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
var Date = global.Date;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Provides stats such as test duration, number of tests passed / failed etc., by listening for events emitted by `runner`.
|
|
28
|
+
*
|
|
29
|
+
* @private
|
|
30
|
+
* @param {Runner} runner - Runner instance
|
|
31
|
+
* @throws {TypeError} If falsy `runner`
|
|
32
|
+
*/
|
|
33
|
+
function createStatsCollector(runner) {
|
|
34
|
+
/**
|
|
35
|
+
* @type StatsCollector
|
|
36
|
+
*/
|
|
37
|
+
var stats = {
|
|
38
|
+
suites: 0,
|
|
39
|
+
tests: 0,
|
|
40
|
+
passes: 0,
|
|
41
|
+
pending: 0,
|
|
42
|
+
failures: 0
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (!runner) {
|
|
46
|
+
throw new TypeError('Missing runner argument');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
runner.stats = stats;
|
|
50
|
+
|
|
51
|
+
runner.once('start', function() {
|
|
52
|
+
stats.start = new Date();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
runner.on('suite', function(suite) {
|
|
56
|
+
suite.root || stats.suites++;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
runner.on('pass', function() {
|
|
60
|
+
stats.passes++;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
runner.on('fail', function() {
|
|
64
|
+
stats.failures++;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
runner.on('pending', function() {
|
|
68
|
+
stats.pending++;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
runner.on('test end', function() {
|
|
72
|
+
stats.tests++;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
runner.once('end', function() {
|
|
76
|
+
stats.end = new Date();
|
|
77
|
+
stats.duration = stats.end - stats.start;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = createStatsCollector;
|
package/lib/suite.js
CHANGED
|
@@ -11,7 +11,9 @@ var Hook = require('./hook');
|
|
|
11
11
|
var utils = require('./utils');
|
|
12
12
|
var inherits = utils.inherits;
|
|
13
13
|
var debug = require('debug')('mocha:suite');
|
|
14
|
-
var milliseconds = require('
|
|
14
|
+
var milliseconds = require('ms');
|
|
15
|
+
var errors = require('./errors');
|
|
16
|
+
var createInvalidArgumentTypeError = errors.createInvalidArgumentTypeError;
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Expose `Suite`.
|
|
@@ -26,12 +28,11 @@ exports = module.exports = Suite;
|
|
|
26
28
|
*
|
|
27
29
|
* @memberof Mocha
|
|
28
30
|
* @public
|
|
29
|
-
* @api public
|
|
30
31
|
* @param {Suite} parent
|
|
31
32
|
* @param {string} title
|
|
32
33
|
* @return {Suite}
|
|
33
34
|
*/
|
|
34
|
-
exports.create = function
|
|
35
|
+
exports.create = function(parent, title) {
|
|
35
36
|
var suite = new Suite(title, parent.ctx);
|
|
36
37
|
suite.parent = parent;
|
|
37
38
|
title = suite.fullTitle();
|
|
@@ -48,12 +49,18 @@ exports.create = function (parent, title) {
|
|
|
48
49
|
* @param {string} title
|
|
49
50
|
* @param {Context} parentContext
|
|
50
51
|
*/
|
|
51
|
-
function Suite
|
|
52
|
+
function Suite(title, parentContext) {
|
|
52
53
|
if (!utils.isString(title)) {
|
|
53
|
-
throw
|
|
54
|
+
throw createInvalidArgumentTypeError(
|
|
55
|
+
'Suite argument "title" must be a string. Received type "' +
|
|
56
|
+
typeof title +
|
|
57
|
+
'"',
|
|
58
|
+
'title',
|
|
59
|
+
'string'
|
|
60
|
+
);
|
|
54
61
|
}
|
|
55
62
|
this.title = title;
|
|
56
|
-
function Context
|
|
63
|
+
function Context() {}
|
|
57
64
|
Context.prototype = parentContext;
|
|
58
65
|
this.ctx = new Context();
|
|
59
66
|
this.suites = [];
|
|
@@ -82,10 +89,10 @@ inherits(Suite, EventEmitter);
|
|
|
82
89
|
/**
|
|
83
90
|
* Return a clone of this `Suite`.
|
|
84
91
|
*
|
|
85
|
-
* @
|
|
92
|
+
* @private
|
|
86
93
|
* @return {Suite}
|
|
87
94
|
*/
|
|
88
|
-
Suite.prototype.clone = function
|
|
95
|
+
Suite.prototype.clone = function() {
|
|
89
96
|
var suite = new Suite(this.title);
|
|
90
97
|
debug('clone');
|
|
91
98
|
suite.ctx = this.ctx;
|
|
@@ -100,11 +107,11 @@ Suite.prototype.clone = function () {
|
|
|
100
107
|
/**
|
|
101
108
|
* Set or get timeout `ms` or short-hand such as "2s".
|
|
102
109
|
*
|
|
103
|
-
* @
|
|
110
|
+
* @private
|
|
104
111
|
* @param {number|string} ms
|
|
105
112
|
* @return {Suite|number} for chaining
|
|
106
113
|
*/
|
|
107
|
-
Suite.prototype.timeout = function
|
|
114
|
+
Suite.prototype.timeout = function(ms) {
|
|
108
115
|
if (!arguments.length) {
|
|
109
116
|
return this._timeout;
|
|
110
117
|
}
|
|
@@ -122,11 +129,11 @@ Suite.prototype.timeout = function (ms) {
|
|
|
122
129
|
/**
|
|
123
130
|
* Set or get number of times to retry a failed test.
|
|
124
131
|
*
|
|
125
|
-
* @
|
|
132
|
+
* @private
|
|
126
133
|
* @param {number|string} n
|
|
127
134
|
* @return {Suite|number} for chaining
|
|
128
135
|
*/
|
|
129
|
-
Suite.prototype.retries = function
|
|
136
|
+
Suite.prototype.retries = function(n) {
|
|
130
137
|
if (!arguments.length) {
|
|
131
138
|
return this._retries;
|
|
132
139
|
}
|
|
@@ -136,13 +143,13 @@ Suite.prototype.retries = function (n) {
|
|
|
136
143
|
};
|
|
137
144
|
|
|
138
145
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
Suite.prototype.enableTimeouts = function
|
|
146
|
+
* Set or get timeout to `enabled`.
|
|
147
|
+
*
|
|
148
|
+
* @private
|
|
149
|
+
* @param {boolean} enabled
|
|
150
|
+
* @return {Suite|boolean} self or enabled
|
|
151
|
+
*/
|
|
152
|
+
Suite.prototype.enableTimeouts = function(enabled) {
|
|
146
153
|
if (!arguments.length) {
|
|
147
154
|
return this._enableTimeouts;
|
|
148
155
|
}
|
|
@@ -154,11 +161,11 @@ Suite.prototype.enableTimeouts = function (enabled) {
|
|
|
154
161
|
/**
|
|
155
162
|
* Set or get slow `ms` or short-hand such as "2s".
|
|
156
163
|
*
|
|
157
|
-
* @
|
|
164
|
+
* @private
|
|
158
165
|
* @param {number|string} ms
|
|
159
166
|
* @return {Suite|number} for chaining
|
|
160
167
|
*/
|
|
161
|
-
Suite.prototype.slow = function
|
|
168
|
+
Suite.prototype.slow = function(ms) {
|
|
162
169
|
if (!arguments.length) {
|
|
163
170
|
return this._slow;
|
|
164
171
|
}
|
|
@@ -173,11 +180,11 @@ Suite.prototype.slow = function (ms) {
|
|
|
173
180
|
/**
|
|
174
181
|
* Set or get whether to bail after first error.
|
|
175
182
|
*
|
|
176
|
-
* @
|
|
183
|
+
* @private
|
|
177
184
|
* @param {boolean} bail
|
|
178
185
|
* @return {Suite|number} for chaining
|
|
179
186
|
*/
|
|
180
|
-
Suite.prototype.bail = function
|
|
187
|
+
Suite.prototype.bail = function(bail) {
|
|
181
188
|
if (!arguments.length) {
|
|
182
189
|
return this._bail;
|
|
183
190
|
}
|
|
@@ -189,9 +196,9 @@ Suite.prototype.bail = function (bail) {
|
|
|
189
196
|
/**
|
|
190
197
|
* Check if this suite or its parent suite is marked as pending.
|
|
191
198
|
*
|
|
192
|
-
* @
|
|
199
|
+
* @private
|
|
193
200
|
*/
|
|
194
|
-
Suite.prototype.isPending = function
|
|
201
|
+
Suite.prototype.isPending = function() {
|
|
195
202
|
return this.pending || (this.parent && this.parent.isPending());
|
|
196
203
|
};
|
|
197
204
|
|
|
@@ -202,7 +209,7 @@ Suite.prototype.isPending = function () {
|
|
|
202
209
|
* @param {Function} fn - Hook callback
|
|
203
210
|
* @returns {Hook} A new hook
|
|
204
211
|
*/
|
|
205
|
-
Suite.prototype._createHook = function
|
|
212
|
+
Suite.prototype._createHook = function(title, fn) {
|
|
206
213
|
var hook = new Hook(title, fn);
|
|
207
214
|
hook.parent = this;
|
|
208
215
|
hook.timeout(this.timeout());
|
|
@@ -217,12 +224,12 @@ Suite.prototype._createHook = function (title, fn) {
|
|
|
217
224
|
/**
|
|
218
225
|
* Run `fn(test[, done])` before running tests.
|
|
219
226
|
*
|
|
220
|
-
* @
|
|
227
|
+
* @private
|
|
221
228
|
* @param {string} title
|
|
222
229
|
* @param {Function} fn
|
|
223
230
|
* @return {Suite} for chaining
|
|
224
231
|
*/
|
|
225
|
-
Suite.prototype.beforeAll = function
|
|
232
|
+
Suite.prototype.beforeAll = function(title, fn) {
|
|
226
233
|
if (this.isPending()) {
|
|
227
234
|
return this;
|
|
228
235
|
}
|
|
@@ -241,12 +248,12 @@ Suite.prototype.beforeAll = function (title, fn) {
|
|
|
241
248
|
/**
|
|
242
249
|
* Run `fn(test[, done])` after running tests.
|
|
243
250
|
*
|
|
244
|
-
* @
|
|
251
|
+
* @private
|
|
245
252
|
* @param {string} title
|
|
246
253
|
* @param {Function} fn
|
|
247
254
|
* @return {Suite} for chaining
|
|
248
255
|
*/
|
|
249
|
-
Suite.prototype.afterAll = function
|
|
256
|
+
Suite.prototype.afterAll = function(title, fn) {
|
|
250
257
|
if (this.isPending()) {
|
|
251
258
|
return this;
|
|
252
259
|
}
|
|
@@ -265,12 +272,12 @@ Suite.prototype.afterAll = function (title, fn) {
|
|
|
265
272
|
/**
|
|
266
273
|
* Run `fn(test[, done])` before each test case.
|
|
267
274
|
*
|
|
268
|
-
* @
|
|
275
|
+
* @private
|
|
269
276
|
* @param {string} title
|
|
270
277
|
* @param {Function} fn
|
|
271
278
|
* @return {Suite} for chaining
|
|
272
279
|
*/
|
|
273
|
-
Suite.prototype.beforeEach = function
|
|
280
|
+
Suite.prototype.beforeEach = function(title, fn) {
|
|
274
281
|
if (this.isPending()) {
|
|
275
282
|
return this;
|
|
276
283
|
}
|
|
@@ -289,12 +296,12 @@ Suite.prototype.beforeEach = function (title, fn) {
|
|
|
289
296
|
/**
|
|
290
297
|
* Run `fn(test[, done])` after each test case.
|
|
291
298
|
*
|
|
292
|
-
* @
|
|
299
|
+
* @private
|
|
293
300
|
* @param {string} title
|
|
294
301
|
* @param {Function} fn
|
|
295
302
|
* @return {Suite} for chaining
|
|
296
303
|
*/
|
|
297
|
-
Suite.prototype.afterEach = function
|
|
304
|
+
Suite.prototype.afterEach = function(title, fn) {
|
|
298
305
|
if (this.isPending()) {
|
|
299
306
|
return this;
|
|
300
307
|
}
|
|
@@ -313,11 +320,11 @@ Suite.prototype.afterEach = function (title, fn) {
|
|
|
313
320
|
/**
|
|
314
321
|
* Add a test `suite`.
|
|
315
322
|
*
|
|
316
|
-
* @
|
|
323
|
+
* @private
|
|
317
324
|
* @param {Suite} suite
|
|
318
325
|
* @return {Suite} for chaining
|
|
319
326
|
*/
|
|
320
|
-
Suite.prototype.addSuite = function
|
|
327
|
+
Suite.prototype.addSuite = function(suite) {
|
|
321
328
|
suite.parent = this;
|
|
322
329
|
suite.timeout(this.timeout());
|
|
323
330
|
suite.retries(this.retries());
|
|
@@ -332,11 +339,11 @@ Suite.prototype.addSuite = function (suite) {
|
|
|
332
339
|
/**
|
|
333
340
|
* Add a `test` to this suite.
|
|
334
341
|
*
|
|
335
|
-
* @
|
|
342
|
+
* @private
|
|
336
343
|
* @param {Test} test
|
|
337
344
|
* @return {Suite} for chaining
|
|
338
345
|
*/
|
|
339
|
-
Suite.prototype.addTest = function
|
|
346
|
+
Suite.prototype.addTest = function(test) {
|
|
340
347
|
test.parent = this;
|
|
341
348
|
test.timeout(this.timeout());
|
|
342
349
|
test.retries(this.retries());
|
|
@@ -354,10 +361,9 @@ Suite.prototype.addTest = function (test) {
|
|
|
354
361
|
*
|
|
355
362
|
* @memberof Mocha.Suite
|
|
356
363
|
* @public
|
|
357
|
-
* @api public
|
|
358
364
|
* @return {string}
|
|
359
365
|
*/
|
|
360
|
-
Suite.prototype.fullTitle = function
|
|
366
|
+
Suite.prototype.fullTitle = function() {
|
|
361
367
|
return this.titlePath().join(' ');
|
|
362
368
|
};
|
|
363
369
|
|
|
@@ -367,10 +373,9 @@ Suite.prototype.fullTitle = function () {
|
|
|
367
373
|
*
|
|
368
374
|
* @memberof Mocha.Suite
|
|
369
375
|
* @public
|
|
370
|
-
* @api public
|
|
371
376
|
* @return {string}
|
|
372
377
|
*/
|
|
373
|
-
Suite.prototype.titlePath = function
|
|
378
|
+
Suite.prototype.titlePath = function() {
|
|
374
379
|
var result = [];
|
|
375
380
|
if (this.parent) {
|
|
376
381
|
result = result.concat(this.parent.titlePath());
|
|
@@ -386,26 +391,27 @@ Suite.prototype.titlePath = function () {
|
|
|
386
391
|
*
|
|
387
392
|
* @memberof Mocha.Suite
|
|
388
393
|
* @public
|
|
389
|
-
* @api public
|
|
390
394
|
* @return {number}
|
|
391
395
|
*/
|
|
392
|
-
Suite.prototype.total = function
|
|
393
|
-
return
|
|
394
|
-
|
|
395
|
-
|
|
396
|
+
Suite.prototype.total = function() {
|
|
397
|
+
return (
|
|
398
|
+
this.suites.reduce(function(sum, suite) {
|
|
399
|
+
return sum + suite.total();
|
|
400
|
+
}, 0) + this.tests.length
|
|
401
|
+
);
|
|
396
402
|
};
|
|
397
403
|
|
|
398
404
|
/**
|
|
399
405
|
* Iterates through each suite recursively to find all tests. Applies a
|
|
400
406
|
* function in the format `fn(test)`.
|
|
401
407
|
*
|
|
402
|
-
* @
|
|
408
|
+
* @private
|
|
403
409
|
* @param {Function} fn
|
|
404
410
|
* @return {Suite}
|
|
405
411
|
*/
|
|
406
|
-
Suite.prototype.eachTest = function
|
|
412
|
+
Suite.prototype.eachTest = function(fn) {
|
|
407
413
|
this.tests.forEach(fn);
|
|
408
|
-
this.suites.forEach(function
|
|
414
|
+
this.suites.forEach(function(suite) {
|
|
409
415
|
suite.eachTest(fn);
|
|
410
416
|
});
|
|
411
417
|
return this;
|
|
@@ -414,7 +420,7 @@ Suite.prototype.eachTest = function (fn) {
|
|
|
414
420
|
/**
|
|
415
421
|
* This will run the root suite if we happen to be running in delayed mode.
|
|
416
422
|
*/
|
|
417
|
-
Suite.prototype.run = function run
|
|
423
|
+
Suite.prototype.run = function run() {
|
|
418
424
|
if (this.root) {
|
|
419
425
|
this.emit('run');
|
|
420
426
|
}
|
package/lib/test.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
2
|
var Runnable = require('./runnable');
|
|
8
3
|
var utils = require('./utils');
|
|
4
|
+
var errors = require('./errors');
|
|
5
|
+
var createInvalidArgumentTypeError = errors.createInvalidArgumentTypeError;
|
|
9
6
|
var isString = utils.isString;
|
|
10
7
|
|
|
11
|
-
/**
|
|
12
|
-
* Expose `Test`.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
8
|
module.exports = Test;
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Initialize a new `Test` with the given `title` and callback `fn`.
|
|
19
12
|
*
|
|
20
|
-
* @
|
|
13
|
+
* @class
|
|
14
|
+
* @extends Runnable
|
|
21
15
|
* @param {String} title
|
|
22
16
|
* @param {Function} fn
|
|
23
17
|
*/
|
|
24
|
-
function Test
|
|
18
|
+
function Test(title, fn) {
|
|
25
19
|
if (!isString(title)) {
|
|
26
|
-
throw
|
|
20
|
+
throw createInvalidArgumentTypeError(
|
|
21
|
+
'Test argument "title" should be a string. Received type "' +
|
|
22
|
+
typeof title +
|
|
23
|
+
'"',
|
|
24
|
+
'title',
|
|
25
|
+
'string'
|
|
26
|
+
);
|
|
27
27
|
}
|
|
28
28
|
Runnable.call(this, title, fn);
|
|
29
29
|
this.pending = !fn;
|
|
@@ -35,7 +35,7 @@ function Test (title, fn) {
|
|
|
35
35
|
*/
|
|
36
36
|
utils.inherits(Test, Runnable);
|
|
37
37
|
|
|
38
|
-
Test.prototype.clone = function
|
|
38
|
+
Test.prototype.clone = function() {
|
|
39
39
|
var test = new Test(this.title, this.fn);
|
|
40
40
|
test.timeout(this.timeout());
|
|
41
41
|
test.slow(this.slow());
|