mocha 5.0.4 → 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 +119 -9
- package/bin/_mocha +90 -35
- 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 +11 -9
- package/lib/hook.js +7 -9
- package/lib/interfaces/bdd.js +12 -13
- package/lib/interfaces/common.js +20 -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 +94 -54
- package/lib/ms.js +12 -6
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +102 -64
- package/lib/reporters/doc.js +23 -9
- package/lib/reporters/dot.js +14 -8
- package/lib/reporters/html.js +81 -41
- package/lib/reporters/json-stream.js +16 -9
- package/lib/reporters/json.js +47 -12
- package/lib/reporters/json.js.orig +128 -0
- package/lib/reporters/landing.js +14 -8
- package/lib/reporters/list.js +16 -10
- package/lib/reporters/markdown.js +18 -12
- package/lib/reporters/min.js +9 -3
- package/lib/reporters/nyan.js +31 -25
- package/lib/reporters/progress.js +13 -7
- package/lib/reporters/spec.js +19 -11
- package/lib/reporters/tap.js +15 -9
- package/lib/reporters/xunit.js +48 -24
- package/lib/runnable.js +88 -66
- package/lib/runner.js +117 -90
- package/lib/suite.js +76 -63
- package/lib/test.js +9 -13
- package/lib/utils.js +137 -85
- package/mocha.js +1914 -1162
- package/package.json +462 -299
- package/CHANGELOG.md.orig +0 -1736
- package/README.md.orig +0 -132
- package/bin/.eslintrc.yml +0 -3
- package/images/error.png +0 -0
- package/images/ok.png +0 -0
- package/lib/browser/.eslintrc.yml +0 -4
package/lib/suite.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @module Suite
|
|
4
|
+
*/
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Module dependencies.
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
9
|
var EventEmitter = require('events').EventEmitter;
|
|
8
10
|
var Hook = require('./hook');
|
|
9
11
|
var utils = require('./utils');
|
|
@@ -22,12 +24,14 @@ exports = module.exports = Suite;
|
|
|
22
24
|
* with the same title is already present, that suite is returned to provide
|
|
23
25
|
* nicer reporter and more flexible meta-testing.
|
|
24
26
|
*
|
|
27
|
+
* @memberof Mocha
|
|
28
|
+
* @public
|
|
25
29
|
* @api public
|
|
26
30
|
* @param {Suite} parent
|
|
27
31
|
* @param {string} title
|
|
28
32
|
* @return {Suite}
|
|
29
33
|
*/
|
|
30
|
-
exports.create = function
|
|
34
|
+
exports.create = function(parent, title) {
|
|
31
35
|
var suite = new Suite(title, parent.ctx);
|
|
32
36
|
suite.parent = parent;
|
|
33
37
|
title = suite.fullTitle();
|
|
@@ -36,18 +40,24 @@ exports.create = function (parent, title) {
|
|
|
36
40
|
};
|
|
37
41
|
|
|
38
42
|
/**
|
|
39
|
-
* Initialize a new `Suite` with the given `title` and `ctx`.
|
|
43
|
+
* Initialize a new `Suite` with the given `title` and `ctx`. Derived from [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
|
40
44
|
*
|
|
41
|
-
* @
|
|
45
|
+
* @memberof Mocha
|
|
46
|
+
* @public
|
|
47
|
+
* @class
|
|
42
48
|
* @param {string} title
|
|
43
49
|
* @param {Context} parentContext
|
|
44
50
|
*/
|
|
45
|
-
function Suite
|
|
51
|
+
function Suite(title, parentContext) {
|
|
46
52
|
if (!utils.isString(title)) {
|
|
47
|
-
throw new Error(
|
|
53
|
+
throw new Error(
|
|
54
|
+
'Suite `title` should be a "string" but "' +
|
|
55
|
+
typeof title +
|
|
56
|
+
'" was given instead.'
|
|
57
|
+
);
|
|
48
58
|
}
|
|
49
59
|
this.title = title;
|
|
50
|
-
function Context
|
|
60
|
+
function Context() {}
|
|
51
61
|
Context.prototype = parentContext;
|
|
52
62
|
this.ctx = new Context();
|
|
53
63
|
this.suites = [];
|
|
@@ -79,7 +89,7 @@ inherits(Suite, EventEmitter);
|
|
|
79
89
|
* @api private
|
|
80
90
|
* @return {Suite}
|
|
81
91
|
*/
|
|
82
|
-
Suite.prototype.clone = function
|
|
92
|
+
Suite.prototype.clone = function() {
|
|
83
93
|
var suite = new Suite(this.title);
|
|
84
94
|
debug('clone');
|
|
85
95
|
suite.ctx = this.ctx;
|
|
@@ -98,7 +108,7 @@ Suite.prototype.clone = function () {
|
|
|
98
108
|
* @param {number|string} ms
|
|
99
109
|
* @return {Suite|number} for chaining
|
|
100
110
|
*/
|
|
101
|
-
Suite.prototype.timeout = function
|
|
111
|
+
Suite.prototype.timeout = function(ms) {
|
|
102
112
|
if (!arguments.length) {
|
|
103
113
|
return this._timeout;
|
|
104
114
|
}
|
|
@@ -120,7 +130,7 @@ Suite.prototype.timeout = function (ms) {
|
|
|
120
130
|
* @param {number|string} n
|
|
121
131
|
* @return {Suite|number} for chaining
|
|
122
132
|
*/
|
|
123
|
-
Suite.prototype.retries = function
|
|
133
|
+
Suite.prototype.retries = function(n) {
|
|
124
134
|
if (!arguments.length) {
|
|
125
135
|
return this._retries;
|
|
126
136
|
}
|
|
@@ -130,13 +140,13 @@ Suite.prototype.retries = function (n) {
|
|
|
130
140
|
};
|
|
131
141
|
|
|
132
142
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
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) {
|
|
140
150
|
if (!arguments.length) {
|
|
141
151
|
return this._enableTimeouts;
|
|
142
152
|
}
|
|
@@ -152,7 +162,7 @@ Suite.prototype.enableTimeouts = function (enabled) {
|
|
|
152
162
|
* @param {number|string} ms
|
|
153
163
|
* @return {Suite|number} for chaining
|
|
154
164
|
*/
|
|
155
|
-
Suite.prototype.slow = function
|
|
165
|
+
Suite.prototype.slow = function(ms) {
|
|
156
166
|
if (!arguments.length) {
|
|
157
167
|
return this._slow;
|
|
158
168
|
}
|
|
@@ -171,7 +181,7 @@ Suite.prototype.slow = function (ms) {
|
|
|
171
181
|
* @param {boolean} bail
|
|
172
182
|
* @return {Suite|number} for chaining
|
|
173
183
|
*/
|
|
174
|
-
Suite.prototype.bail = function
|
|
184
|
+
Suite.prototype.bail = function(bail) {
|
|
175
185
|
if (!arguments.length) {
|
|
176
186
|
return this._bail;
|
|
177
187
|
}
|
|
@@ -185,10 +195,29 @@ Suite.prototype.bail = function (bail) {
|
|
|
185
195
|
*
|
|
186
196
|
* @api private
|
|
187
197
|
*/
|
|
188
|
-
Suite.prototype.isPending = function
|
|
198
|
+
Suite.prototype.isPending = function() {
|
|
189
199
|
return this.pending || (this.parent && this.parent.isPending());
|
|
190
200
|
};
|
|
191
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Generic hook-creator.
|
|
204
|
+
* @private
|
|
205
|
+
* @param {string} title - Title of hook
|
|
206
|
+
* @param {Function} fn - Hook callback
|
|
207
|
+
* @returns {Hook} A new hook
|
|
208
|
+
*/
|
|
209
|
+
Suite.prototype._createHook = function(title, fn) {
|
|
210
|
+
var hook = new Hook(title, fn);
|
|
211
|
+
hook.parent = this;
|
|
212
|
+
hook.timeout(this.timeout());
|
|
213
|
+
hook.retries(this.retries());
|
|
214
|
+
hook.enableTimeouts(this.enableTimeouts());
|
|
215
|
+
hook.slow(this.slow());
|
|
216
|
+
hook.ctx = this.ctx;
|
|
217
|
+
hook.file = this.file;
|
|
218
|
+
return hook;
|
|
219
|
+
};
|
|
220
|
+
|
|
192
221
|
/**
|
|
193
222
|
* Run `fn(test[, done])` before running tests.
|
|
194
223
|
*
|
|
@@ -197,7 +226,7 @@ Suite.prototype.isPending = function () {
|
|
|
197
226
|
* @param {Function} fn
|
|
198
227
|
* @return {Suite} for chaining
|
|
199
228
|
*/
|
|
200
|
-
Suite.prototype.beforeAll = function
|
|
229
|
+
Suite.prototype.beforeAll = function(title, fn) {
|
|
201
230
|
if (this.isPending()) {
|
|
202
231
|
return this;
|
|
203
232
|
}
|
|
@@ -207,13 +236,7 @@ Suite.prototype.beforeAll = function (title, fn) {
|
|
|
207
236
|
}
|
|
208
237
|
title = '"before all" hook' + (title ? ': ' + title : '');
|
|
209
238
|
|
|
210
|
-
var hook =
|
|
211
|
-
hook.parent = this;
|
|
212
|
-
hook.timeout(this.timeout());
|
|
213
|
-
hook.retries(this.retries());
|
|
214
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
215
|
-
hook.slow(this.slow());
|
|
216
|
-
hook.ctx = this.ctx;
|
|
239
|
+
var hook = this._createHook(title, fn);
|
|
217
240
|
this._beforeAll.push(hook);
|
|
218
241
|
this.emit('beforeAll', hook);
|
|
219
242
|
return this;
|
|
@@ -227,7 +250,7 @@ Suite.prototype.beforeAll = function (title, fn) {
|
|
|
227
250
|
* @param {Function} fn
|
|
228
251
|
* @return {Suite} for chaining
|
|
229
252
|
*/
|
|
230
|
-
Suite.prototype.afterAll = function
|
|
253
|
+
Suite.prototype.afterAll = function(title, fn) {
|
|
231
254
|
if (this.isPending()) {
|
|
232
255
|
return this;
|
|
233
256
|
}
|
|
@@ -237,13 +260,7 @@ Suite.prototype.afterAll = function (title, fn) {
|
|
|
237
260
|
}
|
|
238
261
|
title = '"after all" hook' + (title ? ': ' + title : '');
|
|
239
262
|
|
|
240
|
-
var hook =
|
|
241
|
-
hook.parent = this;
|
|
242
|
-
hook.timeout(this.timeout());
|
|
243
|
-
hook.retries(this.retries());
|
|
244
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
245
|
-
hook.slow(this.slow());
|
|
246
|
-
hook.ctx = this.ctx;
|
|
263
|
+
var hook = this._createHook(title, fn);
|
|
247
264
|
this._afterAll.push(hook);
|
|
248
265
|
this.emit('afterAll', hook);
|
|
249
266
|
return this;
|
|
@@ -257,7 +274,7 @@ Suite.prototype.afterAll = function (title, fn) {
|
|
|
257
274
|
* @param {Function} fn
|
|
258
275
|
* @return {Suite} for chaining
|
|
259
276
|
*/
|
|
260
|
-
Suite.prototype.beforeEach = function
|
|
277
|
+
Suite.prototype.beforeEach = function(title, fn) {
|
|
261
278
|
if (this.isPending()) {
|
|
262
279
|
return this;
|
|
263
280
|
}
|
|
@@ -267,13 +284,7 @@ Suite.prototype.beforeEach = function (title, fn) {
|
|
|
267
284
|
}
|
|
268
285
|
title = '"before each" hook' + (title ? ': ' + title : '');
|
|
269
286
|
|
|
270
|
-
var hook =
|
|
271
|
-
hook.parent = this;
|
|
272
|
-
hook.timeout(this.timeout());
|
|
273
|
-
hook.retries(this.retries());
|
|
274
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
275
|
-
hook.slow(this.slow());
|
|
276
|
-
hook.ctx = this.ctx;
|
|
287
|
+
var hook = this._createHook(title, fn);
|
|
277
288
|
this._beforeEach.push(hook);
|
|
278
289
|
this.emit('beforeEach', hook);
|
|
279
290
|
return this;
|
|
@@ -287,7 +298,7 @@ Suite.prototype.beforeEach = function (title, fn) {
|
|
|
287
298
|
* @param {Function} fn
|
|
288
299
|
* @return {Suite} for chaining
|
|
289
300
|
*/
|
|
290
|
-
Suite.prototype.afterEach = function
|
|
301
|
+
Suite.prototype.afterEach = function(title, fn) {
|
|
291
302
|
if (this.isPending()) {
|
|
292
303
|
return this;
|
|
293
304
|
}
|
|
@@ -297,13 +308,7 @@ Suite.prototype.afterEach = function (title, fn) {
|
|
|
297
308
|
}
|
|
298
309
|
title = '"after each" hook' + (title ? ': ' + title : '');
|
|
299
310
|
|
|
300
|
-
var hook =
|
|
301
|
-
hook.parent = this;
|
|
302
|
-
hook.timeout(this.timeout());
|
|
303
|
-
hook.retries(this.retries());
|
|
304
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
305
|
-
hook.slow(this.slow());
|
|
306
|
-
hook.ctx = this.ctx;
|
|
311
|
+
var hook = this._createHook(title, fn);
|
|
307
312
|
this._afterEach.push(hook);
|
|
308
313
|
this.emit('afterEach', hook);
|
|
309
314
|
return this;
|
|
@@ -316,7 +321,7 @@ Suite.prototype.afterEach = function (title, fn) {
|
|
|
316
321
|
* @param {Suite} suite
|
|
317
322
|
* @return {Suite} for chaining
|
|
318
323
|
*/
|
|
319
|
-
Suite.prototype.addSuite = function
|
|
324
|
+
Suite.prototype.addSuite = function(suite) {
|
|
320
325
|
suite.parent = this;
|
|
321
326
|
suite.timeout(this.timeout());
|
|
322
327
|
suite.retries(this.retries());
|
|
@@ -335,7 +340,7 @@ Suite.prototype.addSuite = function (suite) {
|
|
|
335
340
|
* @param {Test} test
|
|
336
341
|
* @return {Suite} for chaining
|
|
337
342
|
*/
|
|
338
|
-
Suite.prototype.addTest = function
|
|
343
|
+
Suite.prototype.addTest = function(test) {
|
|
339
344
|
test.parent = this;
|
|
340
345
|
test.timeout(this.timeout());
|
|
341
346
|
test.retries(this.retries());
|
|
@@ -351,10 +356,12 @@ Suite.prototype.addTest = function (test) {
|
|
|
351
356
|
* Return the full title generated by recursively concatenating the parent's
|
|
352
357
|
* full title.
|
|
353
358
|
*
|
|
359
|
+
* @memberof Mocha.Suite
|
|
360
|
+
* @public
|
|
354
361
|
* @api public
|
|
355
362
|
* @return {string}
|
|
356
363
|
*/
|
|
357
|
-
Suite.prototype.fullTitle = function
|
|
364
|
+
Suite.prototype.fullTitle = function() {
|
|
358
365
|
return this.titlePath().join(' ');
|
|
359
366
|
};
|
|
360
367
|
|
|
@@ -362,10 +369,12 @@ Suite.prototype.fullTitle = function () {
|
|
|
362
369
|
* Return the title path generated by recursively concatenating the parent's
|
|
363
370
|
* title path.
|
|
364
371
|
*
|
|
372
|
+
* @memberof Mocha.Suite
|
|
373
|
+
* @public
|
|
365
374
|
* @api public
|
|
366
375
|
* @return {string}
|
|
367
376
|
*/
|
|
368
|
-
Suite.prototype.titlePath = function
|
|
377
|
+
Suite.prototype.titlePath = function() {
|
|
369
378
|
var result = [];
|
|
370
379
|
if (this.parent) {
|
|
371
380
|
result = result.concat(this.parent.titlePath());
|
|
@@ -379,13 +388,17 @@ Suite.prototype.titlePath = function () {
|
|
|
379
388
|
/**
|
|
380
389
|
* Return the total number of tests.
|
|
381
390
|
*
|
|
391
|
+
* @memberof Mocha.Suite
|
|
392
|
+
* @public
|
|
382
393
|
* @api public
|
|
383
394
|
* @return {number}
|
|
384
395
|
*/
|
|
385
|
-
Suite.prototype.total = function
|
|
386
|
-
return
|
|
387
|
-
|
|
388
|
-
|
|
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
|
+
);
|
|
389
402
|
};
|
|
390
403
|
|
|
391
404
|
/**
|
|
@@ -396,9 +409,9 @@ Suite.prototype.total = function () {
|
|
|
396
409
|
* @param {Function} fn
|
|
397
410
|
* @return {Suite}
|
|
398
411
|
*/
|
|
399
|
-
Suite.prototype.eachTest = function
|
|
412
|
+
Suite.prototype.eachTest = function(fn) {
|
|
400
413
|
this.tests.forEach(fn);
|
|
401
|
-
this.suites.forEach(function
|
|
414
|
+
this.suites.forEach(function(suite) {
|
|
402
415
|
suite.eachTest(fn);
|
|
403
416
|
});
|
|
404
417
|
return this;
|
|
@@ -407,7 +420,7 @@ Suite.prototype.eachTest = function (fn) {
|
|
|
407
420
|
/**
|
|
408
421
|
* This will run the root suite if we happen to be running in delayed mode.
|
|
409
422
|
*/
|
|
410
|
-
Suite.prototype.run = function run
|
|
423
|
+
Suite.prototype.run = function run() {
|
|
411
424
|
if (this.root) {
|
|
412
425
|
this.emit('run');
|
|
413
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());
|