mocha 5.1.1 → 5.2.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 +32 -0
- package/bin/_mocha +82 -36
- package/bin/options.js +14 -8
- package/browser-entry.js +20 -16
- package/lib/browser/progress.js +8 -8
- package/lib/browser/tty.js +2 -2
- package/lib/context.js +7 -7
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +12 -13
- package/lib/interfaces/common.js +18 -15
- package/lib/interfaces/exports.js +2 -7
- package/lib/interfaces/qunit.js +6 -10
- package/lib/interfaces/tdd.js +7 -11
- package/lib/mocha.js +56 -57
- package/lib/ms.js +7 -5
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +91 -63
- package/lib/reporters/doc.js +16 -8
- package/lib/reporters/dot.js +7 -7
- package/lib/reporters/html.js +74 -40
- package/lib/reporters/json-stream.js +7 -7
- package/lib/reporters/json.js +21 -19
- package/lib/reporters/landing.js +7 -7
- package/lib/reporters/list.js +9 -9
- package/lib/reporters/markdown.js +11 -11
- package/lib/reporters/min.js +2 -2
- package/lib/reporters/nyan.js +24 -24
- package/lib/reporters/progress.js +6 -6
- package/lib/reporters/spec.js +12 -10
- package/lib/reporters/tap.js +8 -8
- package/lib/reporters/xunit.js +41 -23
- package/lib/runnable.js +64 -62
- package/lib/runner.js +99 -78
- package/lib/suite.js +39 -33
- package/lib/test.js +9 -13
- package/lib/utils.js +131 -85
- package/mocha.js +1556 -1064
- package/package.json +32 -19
- package/images/error.png +0 -0
- package/images/ok.png +0 -0
package/lib/suite.js
CHANGED
|
@@ -31,7 +31,7 @@ exports = module.exports = Suite;
|
|
|
31
31
|
* @param {string} title
|
|
32
32
|
* @return {Suite}
|
|
33
33
|
*/
|
|
34
|
-
exports.create = function
|
|
34
|
+
exports.create = function(parent, title) {
|
|
35
35
|
var suite = new Suite(title, parent.ctx);
|
|
36
36
|
suite.parent = parent;
|
|
37
37
|
title = suite.fullTitle();
|
|
@@ -48,12 +48,16 @@ exports.create = function (parent, title) {
|
|
|
48
48
|
* @param {string} title
|
|
49
49
|
* @param {Context} parentContext
|
|
50
50
|
*/
|
|
51
|
-
function Suite
|
|
51
|
+
function Suite(title, parentContext) {
|
|
52
52
|
if (!utils.isString(title)) {
|
|
53
|
-
throw new Error(
|
|
53
|
+
throw new Error(
|
|
54
|
+
'Suite `title` should be a "string" but "' +
|
|
55
|
+
typeof title +
|
|
56
|
+
'" was given instead.'
|
|
57
|
+
);
|
|
54
58
|
}
|
|
55
59
|
this.title = title;
|
|
56
|
-
function Context
|
|
60
|
+
function Context() {}
|
|
57
61
|
Context.prototype = parentContext;
|
|
58
62
|
this.ctx = new Context();
|
|
59
63
|
this.suites = [];
|
|
@@ -85,7 +89,7 @@ inherits(Suite, EventEmitter);
|
|
|
85
89
|
* @api private
|
|
86
90
|
* @return {Suite}
|
|
87
91
|
*/
|
|
88
|
-
Suite.prototype.clone = function
|
|
92
|
+
Suite.prototype.clone = function() {
|
|
89
93
|
var suite = new Suite(this.title);
|
|
90
94
|
debug('clone');
|
|
91
95
|
suite.ctx = this.ctx;
|
|
@@ -104,7 +108,7 @@ Suite.prototype.clone = function () {
|
|
|
104
108
|
* @param {number|string} ms
|
|
105
109
|
* @return {Suite|number} for chaining
|
|
106
110
|
*/
|
|
107
|
-
Suite.prototype.timeout = function
|
|
111
|
+
Suite.prototype.timeout = function(ms) {
|
|
108
112
|
if (!arguments.length) {
|
|
109
113
|
return this._timeout;
|
|
110
114
|
}
|
|
@@ -126,7 +130,7 @@ Suite.prototype.timeout = function (ms) {
|
|
|
126
130
|
* @param {number|string} n
|
|
127
131
|
* @return {Suite|number} for chaining
|
|
128
132
|
*/
|
|
129
|
-
Suite.prototype.retries = function
|
|
133
|
+
Suite.prototype.retries = function(n) {
|
|
130
134
|
if (!arguments.length) {
|
|
131
135
|
return this._retries;
|
|
132
136
|
}
|
|
@@ -136,13 +140,13 @@ Suite.prototype.retries = function (n) {
|
|
|
136
140
|
};
|
|
137
141
|
|
|
138
142
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
Suite.prototype.enableTimeouts = function
|
|
143
|
+
* Set or get timeout to `enabled`.
|
|
144
|
+
*
|
|
145
|
+
* @api private
|
|
146
|
+
* @param {boolean} enabled
|
|
147
|
+
* @return {Suite|boolean} self or enabled
|
|
148
|
+
*/
|
|
149
|
+
Suite.prototype.enableTimeouts = function(enabled) {
|
|
146
150
|
if (!arguments.length) {
|
|
147
151
|
return this._enableTimeouts;
|
|
148
152
|
}
|
|
@@ -158,7 +162,7 @@ Suite.prototype.enableTimeouts = function (enabled) {
|
|
|
158
162
|
* @param {number|string} ms
|
|
159
163
|
* @return {Suite|number} for chaining
|
|
160
164
|
*/
|
|
161
|
-
Suite.prototype.slow = function
|
|
165
|
+
Suite.prototype.slow = function(ms) {
|
|
162
166
|
if (!arguments.length) {
|
|
163
167
|
return this._slow;
|
|
164
168
|
}
|
|
@@ -177,7 +181,7 @@ Suite.prototype.slow = function (ms) {
|
|
|
177
181
|
* @param {boolean} bail
|
|
178
182
|
* @return {Suite|number} for chaining
|
|
179
183
|
*/
|
|
180
|
-
Suite.prototype.bail = function
|
|
184
|
+
Suite.prototype.bail = function(bail) {
|
|
181
185
|
if (!arguments.length) {
|
|
182
186
|
return this._bail;
|
|
183
187
|
}
|
|
@@ -191,7 +195,7 @@ Suite.prototype.bail = function (bail) {
|
|
|
191
195
|
*
|
|
192
196
|
* @api private
|
|
193
197
|
*/
|
|
194
|
-
Suite.prototype.isPending = function
|
|
198
|
+
Suite.prototype.isPending = function() {
|
|
195
199
|
return this.pending || (this.parent && this.parent.isPending());
|
|
196
200
|
};
|
|
197
201
|
|
|
@@ -202,7 +206,7 @@ Suite.prototype.isPending = function () {
|
|
|
202
206
|
* @param {Function} fn - Hook callback
|
|
203
207
|
* @returns {Hook} A new hook
|
|
204
208
|
*/
|
|
205
|
-
Suite.prototype._createHook = function
|
|
209
|
+
Suite.prototype._createHook = function(title, fn) {
|
|
206
210
|
var hook = new Hook(title, fn);
|
|
207
211
|
hook.parent = this;
|
|
208
212
|
hook.timeout(this.timeout());
|
|
@@ -222,7 +226,7 @@ Suite.prototype._createHook = function (title, fn) {
|
|
|
222
226
|
* @param {Function} fn
|
|
223
227
|
* @return {Suite} for chaining
|
|
224
228
|
*/
|
|
225
|
-
Suite.prototype.beforeAll = function
|
|
229
|
+
Suite.prototype.beforeAll = function(title, fn) {
|
|
226
230
|
if (this.isPending()) {
|
|
227
231
|
return this;
|
|
228
232
|
}
|
|
@@ -246,7 +250,7 @@ Suite.prototype.beforeAll = function (title, fn) {
|
|
|
246
250
|
* @param {Function} fn
|
|
247
251
|
* @return {Suite} for chaining
|
|
248
252
|
*/
|
|
249
|
-
Suite.prototype.afterAll = function
|
|
253
|
+
Suite.prototype.afterAll = function(title, fn) {
|
|
250
254
|
if (this.isPending()) {
|
|
251
255
|
return this;
|
|
252
256
|
}
|
|
@@ -270,7 +274,7 @@ Suite.prototype.afterAll = function (title, fn) {
|
|
|
270
274
|
* @param {Function} fn
|
|
271
275
|
* @return {Suite} for chaining
|
|
272
276
|
*/
|
|
273
|
-
Suite.prototype.beforeEach = function
|
|
277
|
+
Suite.prototype.beforeEach = function(title, fn) {
|
|
274
278
|
if (this.isPending()) {
|
|
275
279
|
return this;
|
|
276
280
|
}
|
|
@@ -294,7 +298,7 @@ Suite.prototype.beforeEach = function (title, fn) {
|
|
|
294
298
|
* @param {Function} fn
|
|
295
299
|
* @return {Suite} for chaining
|
|
296
300
|
*/
|
|
297
|
-
Suite.prototype.afterEach = function
|
|
301
|
+
Suite.prototype.afterEach = function(title, fn) {
|
|
298
302
|
if (this.isPending()) {
|
|
299
303
|
return this;
|
|
300
304
|
}
|
|
@@ -317,7 +321,7 @@ Suite.prototype.afterEach = function (title, fn) {
|
|
|
317
321
|
* @param {Suite} suite
|
|
318
322
|
* @return {Suite} for chaining
|
|
319
323
|
*/
|
|
320
|
-
Suite.prototype.addSuite = function
|
|
324
|
+
Suite.prototype.addSuite = function(suite) {
|
|
321
325
|
suite.parent = this;
|
|
322
326
|
suite.timeout(this.timeout());
|
|
323
327
|
suite.retries(this.retries());
|
|
@@ -336,7 +340,7 @@ Suite.prototype.addSuite = function (suite) {
|
|
|
336
340
|
* @param {Test} test
|
|
337
341
|
* @return {Suite} for chaining
|
|
338
342
|
*/
|
|
339
|
-
Suite.prototype.addTest = function
|
|
343
|
+
Suite.prototype.addTest = function(test) {
|
|
340
344
|
test.parent = this;
|
|
341
345
|
test.timeout(this.timeout());
|
|
342
346
|
test.retries(this.retries());
|
|
@@ -357,7 +361,7 @@ Suite.prototype.addTest = function (test) {
|
|
|
357
361
|
* @api public
|
|
358
362
|
* @return {string}
|
|
359
363
|
*/
|
|
360
|
-
Suite.prototype.fullTitle = function
|
|
364
|
+
Suite.prototype.fullTitle = function() {
|
|
361
365
|
return this.titlePath().join(' ');
|
|
362
366
|
};
|
|
363
367
|
|
|
@@ -370,7 +374,7 @@ Suite.prototype.fullTitle = function () {
|
|
|
370
374
|
* @api public
|
|
371
375
|
* @return {string}
|
|
372
376
|
*/
|
|
373
|
-
Suite.prototype.titlePath = function
|
|
377
|
+
Suite.prototype.titlePath = function() {
|
|
374
378
|
var result = [];
|
|
375
379
|
if (this.parent) {
|
|
376
380
|
result = result.concat(this.parent.titlePath());
|
|
@@ -389,10 +393,12 @@ Suite.prototype.titlePath = function () {
|
|
|
389
393
|
* @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
|
/**
|
|
@@ -403,9 +409,9 @@ Suite.prototype.total = function () {
|
|
|
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,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
2
|
var Runnable = require('./runnable');
|
|
8
3
|
var utils = require('./utils');
|
|
9
4
|
var isString = utils.isString;
|
|
10
5
|
|
|
11
|
-
/**
|
|
12
|
-
* Expose `Test`.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
6
|
module.exports = Test;
|
|
16
7
|
|
|
17
8
|
/**
|
|
18
9
|
* Initialize a new `Test` with the given `title` and callback `fn`.
|
|
19
10
|
*
|
|
20
|
-
* @
|
|
11
|
+
* @class
|
|
12
|
+
* @extends Runnable
|
|
21
13
|
* @param {String} title
|
|
22
14
|
* @param {Function} fn
|
|
23
15
|
*/
|
|
24
|
-
function Test
|
|
16
|
+
function Test(title, fn) {
|
|
25
17
|
if (!isString(title)) {
|
|
26
|
-
throw new Error(
|
|
18
|
+
throw new Error(
|
|
19
|
+
'Test `title` should be a "string" but "' +
|
|
20
|
+
typeof title +
|
|
21
|
+
'" was given instead.'
|
|
22
|
+
);
|
|
27
23
|
}
|
|
28
24
|
Runnable.call(this, title, fn);
|
|
29
25
|
this.pending = !fn;
|
|
@@ -35,7 +31,7 @@ function Test (title, fn) {
|
|
|
35
31
|
*/
|
|
36
32
|
utils.inherits(Test, Runnable);
|
|
37
33
|
|
|
38
|
-
Test.prototype.clone = function
|
|
34
|
+
Test.prototype.clone = function() {
|
|
39
35
|
var test = new Test(this.title, this.fn);
|
|
40
36
|
test.timeout(this.timeout());
|
|
41
37
|
test.slow(this.slow());
|