mocha 3.0.2 → 3.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 +103 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/bin/_mocha +170 -104
- package/bin/mocha +22 -13
- package/bin/options.js +7 -5
- package/browser-entry.js +43 -22
- package/lib/browser/.eslintrc.yaml +4 -0
- package/lib/browser/debug.js +6 -3
- package/lib/browser/events.js +11 -9
- package/lib/browser/progress.js +9 -7
- package/lib/browser/tty.js +4 -2
- package/lib/context.js +11 -9
- package/lib/hook.js +4 -2
- package/lib/interfaces/bdd.js +11 -9
- package/lib/interfaces/common.js +16 -14
- package/lib/interfaces/exports.js +4 -2
- package/lib/interfaces/index.js +2 -0
- package/lib/interfaces/qunit.js +12 -8
- package/lib/interfaces/tdd.js +9 -7
- package/lib/mocha.js +36 -34
- package/lib/ms.js +12 -10
- package/lib/pending.js +2 -1
- package/lib/reporters/base.js +52 -50
- package/lib/reporters/doc.js +8 -6
- package/lib/reporters/dot.js +9 -7
- package/lib/reporters/html.js +32 -30
- package/lib/reporters/index.js +2 -0
- package/lib/reporters/json-stream.js +8 -6
- package/lib/reporters/json.js +11 -9
- package/lib/reporters/landing.js +8 -6
- package/lib/reporters/list.js +13 -11
- package/lib/reporters/markdown.js +12 -10
- package/lib/reporters/min.js +4 -2
- package/lib/reporters/nyan.js +22 -20
- package/lib/reporters/progress.js +7 -5
- package/lib/reporters/spec.js +17 -15
- package/lib/reporters/tap.js +10 -8
- package/lib/reporters/xunit.js +14 -12
- package/lib/runnable.js +43 -32
- package/lib/runner.js +78 -63
- package/lib/suite.js +24 -22
- package/lib/test.js +4 -2
- package/lib/utils.js +115 -90
- package/mocha.js +1185 -800
- package/package.json +9 -2
- package/lib/interfaces/bdd.js.orig +0 -118
- package/lib/mocha.js.orig +0 -532
- package/lib/runnable.js.orig +0 -378
- package/lib/runner.js.orig +0 -934
- package/lib/suite.js.orig +0 -418
- package/lib/test.js.orig +0 -52
- package/lib/utils.js.orig +0 -758
package/lib/suite.js.orig
DELETED
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var EventEmitter = require('events').EventEmitter;
|
|
6
|
-
var Hook = require('./hook');
|
|
7
|
-
var utils = require('./utils');
|
|
8
|
-
var inherits = utils.inherits;
|
|
9
|
-
var debug = require('debug')('mocha:suite');
|
|
10
|
-
var milliseconds = require('./ms');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Expose `Suite`.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
exports = module.exports = Suite;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a new `Suite` with the given `title` and parent `Suite`. When a suite
|
|
20
|
-
* with the same title is already present, that suite is returned to provide
|
|
21
|
-
* nicer reporter and more flexible meta-testing.
|
|
22
|
-
*
|
|
23
|
-
* @api public
|
|
24
|
-
* @param {Suite} parent
|
|
25
|
-
* @param {string} title
|
|
26
|
-
* @return {Suite}
|
|
27
|
-
*/
|
|
28
|
-
exports.create = function(parent, title) {
|
|
29
|
-
var suite = new Suite(title, parent.ctx);
|
|
30
|
-
suite.parent = parent;
|
|
31
|
-
title = suite.fullTitle();
|
|
32
|
-
parent.addSuite(suite);
|
|
33
|
-
return suite;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Initialize a new `Suite` with the given `title` and `ctx`.
|
|
38
|
-
*
|
|
39
|
-
* @api private
|
|
40
|
-
* @param {string} title
|
|
41
|
-
* @param {Context} parentContext
|
|
42
|
-
*/
|
|
43
|
-
function Suite(title, parentContext) {
|
|
44
|
-
this.title = title;
|
|
45
|
-
function Context() {}
|
|
46
|
-
Context.prototype = parentContext;
|
|
47
|
-
this.ctx = new Context();
|
|
48
|
-
this.suites = [];
|
|
49
|
-
this.tests = [];
|
|
50
|
-
this.pending = false;
|
|
51
|
-
this._beforeEach = [];
|
|
52
|
-
this._beforeAll = [];
|
|
53
|
-
this._afterEach = [];
|
|
54
|
-
this._afterAll = [];
|
|
55
|
-
this.root = !title;
|
|
56
|
-
this._timeout = 2000;
|
|
57
|
-
this._enableTimeouts = true;
|
|
58
|
-
this._slow = 75;
|
|
59
|
-
this._bail = false;
|
|
60
|
-
<<<<<<< e939d8e4379a622e28064ca3a75f3e1bda7e225b
|
|
61
|
-
this._retries = -1;
|
|
62
|
-
this.delayed = false;
|
|
63
|
-
=======
|
|
64
|
-
this._enableRandomize = true;
|
|
65
|
-
>>>>>>> Add randomization support
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Inherit from `EventEmitter.prototype`.
|
|
70
|
-
*/
|
|
71
|
-
inherits(Suite, EventEmitter);
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Return a clone of this `Suite`.
|
|
75
|
-
*
|
|
76
|
-
* @api private
|
|
77
|
-
* @return {Suite}
|
|
78
|
-
*/
|
|
79
|
-
Suite.prototype.clone = function() {
|
|
80
|
-
var suite = new Suite(this.title);
|
|
81
|
-
debug('clone');
|
|
82
|
-
suite.ctx = this.ctx;
|
|
83
|
-
suite.timeout(this.timeout());
|
|
84
|
-
suite.retries(this.retries());
|
|
85
|
-
suite.enableTimeouts(this.enableTimeouts());
|
|
86
|
-
suite.slow(this.slow());
|
|
87
|
-
suite.bail(this.bail());
|
|
88
|
-
suite.enableRandomize(this.enableRandomize());
|
|
89
|
-
return suite;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Set timeout `ms` or short-hand such as "2s".
|
|
94
|
-
*
|
|
95
|
-
* @api private
|
|
96
|
-
* @param {number|string} ms
|
|
97
|
-
* @return {Suite|number} for chaining
|
|
98
|
-
*/
|
|
99
|
-
Suite.prototype.timeout = function(ms) {
|
|
100
|
-
if (!arguments.length) {
|
|
101
|
-
return this._timeout;
|
|
102
|
-
}
|
|
103
|
-
if (ms.toString() === '0') {
|
|
104
|
-
this._enableTimeouts = false;
|
|
105
|
-
}
|
|
106
|
-
if (typeof ms === 'string') {
|
|
107
|
-
ms = milliseconds(ms);
|
|
108
|
-
}
|
|
109
|
-
debug('timeout %d', ms);
|
|
110
|
-
this._timeout = parseInt(ms, 10);
|
|
111
|
-
return this;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Set number of times to retry a failed test.
|
|
116
|
-
*
|
|
117
|
-
* @api private
|
|
118
|
-
* @param {number|string} n
|
|
119
|
-
* @return {Suite|number} for chaining
|
|
120
|
-
*/
|
|
121
|
-
Suite.prototype.retries = function(n) {
|
|
122
|
-
if (!arguments.length) {
|
|
123
|
-
return this._retries;
|
|
124
|
-
}
|
|
125
|
-
debug('retries %d', n);
|
|
126
|
-
this._retries = parseInt(n, 10) || 0;
|
|
127
|
-
return this;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Set timeout to `enabled`.
|
|
132
|
-
*
|
|
133
|
-
* @api private
|
|
134
|
-
* @param {boolean} enabled
|
|
135
|
-
* @return {Suite|boolean} self or enabled
|
|
136
|
-
*/
|
|
137
|
-
Suite.prototype.enableTimeouts = function(enabled) {
|
|
138
|
-
if (!arguments.length) {
|
|
139
|
-
return this._enableTimeouts;
|
|
140
|
-
}
|
|
141
|
-
debug('enableTimeouts %s', enabled);
|
|
142
|
-
this._enableTimeouts = enabled;
|
|
143
|
-
return this;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Set slow `ms` or short-hand such as "2s".
|
|
148
|
-
*
|
|
149
|
-
* @api private
|
|
150
|
-
* @param {number|string} ms
|
|
151
|
-
* @return {Suite|number} for chaining
|
|
152
|
-
*/
|
|
153
|
-
Suite.prototype.slow = function(ms) {
|
|
154
|
-
if (!arguments.length) {
|
|
155
|
-
return this._slow;
|
|
156
|
-
}
|
|
157
|
-
if (typeof ms === 'string') {
|
|
158
|
-
ms = milliseconds(ms);
|
|
159
|
-
}
|
|
160
|
-
debug('slow %d', ms);
|
|
161
|
-
this._slow = ms;
|
|
162
|
-
return this;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Sets whether to bail after first error.
|
|
167
|
-
*
|
|
168
|
-
* @api private
|
|
169
|
-
* @param {boolean} bail
|
|
170
|
-
* @return {Suite|number} for chaining
|
|
171
|
-
*/
|
|
172
|
-
Suite.prototype.bail = function(bail) {
|
|
173
|
-
if (!arguments.length) {
|
|
174
|
-
return this._bail;
|
|
175
|
-
}
|
|
176
|
-
debug('bail %s', bail);
|
|
177
|
-
this._bail = bail;
|
|
178
|
-
return this;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
<<<<<<< e939d8e4379a622e28064ca3a75f3e1bda7e225b
|
|
183
|
-
* Check if this suite or its parent suite is marked as pending.
|
|
184
|
-
*
|
|
185
|
-
* @api private
|
|
186
|
-
*/
|
|
187
|
-
Suite.prototype.isPending = function() {
|
|
188
|
-
return this.pending || (this.parent && this.parent.isPending());
|
|
189
|
-
=======
|
|
190
|
-
* Set randomization `enabled`.
|
|
191
|
-
*
|
|
192
|
-
* Do NOT use `this.enableRandomize()` in your test; use `describe.noRandom`
|
|
193
|
-
* instead.
|
|
194
|
-
*
|
|
195
|
-
* @param {Boolean} enabled
|
|
196
|
-
* @return {Suite|Boolean} self or enabled
|
|
197
|
-
* @api private
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
Suite.prototype.enableRandomize = function(enabled){
|
|
201
|
-
if (arguments.length === 0) return this._enableRandomize;
|
|
202
|
-
debug('enableRandomize %s', enabled);
|
|
203
|
-
this._enableRandomize = enabled;
|
|
204
|
-
return this;
|
|
205
|
-
>>>>>>> Add randomization support
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Run `fn(test[, done])` before running tests.
|
|
210
|
-
*
|
|
211
|
-
* @api private
|
|
212
|
-
* @param {string} title
|
|
213
|
-
* @param {Function} fn
|
|
214
|
-
* @return {Suite} for chaining
|
|
215
|
-
*/
|
|
216
|
-
Suite.prototype.beforeAll = function(title, fn) {
|
|
217
|
-
if (this.isPending()) {
|
|
218
|
-
return this;
|
|
219
|
-
}
|
|
220
|
-
if (typeof title === 'function') {
|
|
221
|
-
fn = title;
|
|
222
|
-
title = fn.name;
|
|
223
|
-
}
|
|
224
|
-
title = '"before all" hook' + (title ? ': ' + title : '');
|
|
225
|
-
|
|
226
|
-
var hook = new Hook(title, fn);
|
|
227
|
-
hook.parent = this;
|
|
228
|
-
hook.timeout(this.timeout());
|
|
229
|
-
hook.retries(this.retries());
|
|
230
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
231
|
-
hook.slow(this.slow());
|
|
232
|
-
hook.ctx = this.ctx;
|
|
233
|
-
this._beforeAll.push(hook);
|
|
234
|
-
this.emit('beforeAll', hook);
|
|
235
|
-
return this;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Run `fn(test[, done])` after running tests.
|
|
240
|
-
*
|
|
241
|
-
* @api private
|
|
242
|
-
* @param {string} title
|
|
243
|
-
* @param {Function} fn
|
|
244
|
-
* @return {Suite} for chaining
|
|
245
|
-
*/
|
|
246
|
-
Suite.prototype.afterAll = function(title, fn) {
|
|
247
|
-
if (this.isPending()) {
|
|
248
|
-
return this;
|
|
249
|
-
}
|
|
250
|
-
if (typeof title === 'function') {
|
|
251
|
-
fn = title;
|
|
252
|
-
title = fn.name;
|
|
253
|
-
}
|
|
254
|
-
title = '"after all" hook' + (title ? ': ' + title : '');
|
|
255
|
-
|
|
256
|
-
var hook = new Hook(title, fn);
|
|
257
|
-
hook.parent = this;
|
|
258
|
-
hook.timeout(this.timeout());
|
|
259
|
-
hook.retries(this.retries());
|
|
260
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
261
|
-
hook.slow(this.slow());
|
|
262
|
-
hook.ctx = this.ctx;
|
|
263
|
-
this._afterAll.push(hook);
|
|
264
|
-
this.emit('afterAll', hook);
|
|
265
|
-
return this;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Run `fn(test[, done])` before each test case.
|
|
270
|
-
*
|
|
271
|
-
* @api private
|
|
272
|
-
* @param {string} title
|
|
273
|
-
* @param {Function} fn
|
|
274
|
-
* @return {Suite} for chaining
|
|
275
|
-
*/
|
|
276
|
-
Suite.prototype.beforeEach = function(title, fn) {
|
|
277
|
-
if (this.isPending()) {
|
|
278
|
-
return this;
|
|
279
|
-
}
|
|
280
|
-
if (typeof title === 'function') {
|
|
281
|
-
fn = title;
|
|
282
|
-
title = fn.name;
|
|
283
|
-
}
|
|
284
|
-
title = '"before each" hook' + (title ? ': ' + title : '');
|
|
285
|
-
|
|
286
|
-
var hook = new Hook(title, fn);
|
|
287
|
-
hook.parent = this;
|
|
288
|
-
hook.timeout(this.timeout());
|
|
289
|
-
hook.retries(this.retries());
|
|
290
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
291
|
-
hook.slow(this.slow());
|
|
292
|
-
hook.ctx = this.ctx;
|
|
293
|
-
this._beforeEach.push(hook);
|
|
294
|
-
this.emit('beforeEach', hook);
|
|
295
|
-
return this;
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Run `fn(test[, done])` after each test case.
|
|
300
|
-
*
|
|
301
|
-
* @api private
|
|
302
|
-
* @param {string} title
|
|
303
|
-
* @param {Function} fn
|
|
304
|
-
* @return {Suite} for chaining
|
|
305
|
-
*/
|
|
306
|
-
Suite.prototype.afterEach = function(title, fn) {
|
|
307
|
-
if (this.isPending()) {
|
|
308
|
-
return this;
|
|
309
|
-
}
|
|
310
|
-
if (typeof title === 'function') {
|
|
311
|
-
fn = title;
|
|
312
|
-
title = fn.name;
|
|
313
|
-
}
|
|
314
|
-
title = '"after each" hook' + (title ? ': ' + title : '');
|
|
315
|
-
|
|
316
|
-
var hook = new Hook(title, fn);
|
|
317
|
-
hook.parent = this;
|
|
318
|
-
hook.timeout(this.timeout());
|
|
319
|
-
hook.retries(this.retries());
|
|
320
|
-
hook.enableTimeouts(this.enableTimeouts());
|
|
321
|
-
hook.slow(this.slow());
|
|
322
|
-
hook.ctx = this.ctx;
|
|
323
|
-
this._afterEach.push(hook);
|
|
324
|
-
this.emit('afterEach', hook);
|
|
325
|
-
return this;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Add a test `suite`.
|
|
330
|
-
*
|
|
331
|
-
* @api private
|
|
332
|
-
* @param {Suite} suite
|
|
333
|
-
* @return {Suite} for chaining
|
|
334
|
-
*/
|
|
335
|
-
Suite.prototype.addSuite = function(suite) {
|
|
336
|
-
suite.parent = this;
|
|
337
|
-
suite.timeout(this.timeout());
|
|
338
|
-
suite.retries(this.retries());
|
|
339
|
-
suite.enableTimeouts(this.enableTimeouts());
|
|
340
|
-
suite.slow(this.slow());
|
|
341
|
-
suite.bail(this.bail());
|
|
342
|
-
this.suites.push(suite);
|
|
343
|
-
this.emit('suite', suite);
|
|
344
|
-
return this;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Add a `test` to this suite.
|
|
349
|
-
*
|
|
350
|
-
* @api private
|
|
351
|
-
* @param {Test} test
|
|
352
|
-
* @return {Suite} for chaining
|
|
353
|
-
*/
|
|
354
|
-
Suite.prototype.addTest = function(test) {
|
|
355
|
-
test.parent = this;
|
|
356
|
-
test.timeout(this.timeout());
|
|
357
|
-
test.retries(this.retries());
|
|
358
|
-
test.enableTimeouts(this.enableTimeouts());
|
|
359
|
-
test.slow(this.slow());
|
|
360
|
-
test.ctx = this.ctx;
|
|
361
|
-
this.tests.push(test);
|
|
362
|
-
this.emit('test', test);
|
|
363
|
-
return this;
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Return the full title generated by recursively concatenating the parent's
|
|
368
|
-
* full title.
|
|
369
|
-
*
|
|
370
|
-
* @api public
|
|
371
|
-
* @return {string}
|
|
372
|
-
*/
|
|
373
|
-
Suite.prototype.fullTitle = function() {
|
|
374
|
-
if (this.parent) {
|
|
375
|
-
var full = this.parent.fullTitle();
|
|
376
|
-
if (full) {
|
|
377
|
-
return full + ' ' + this.title;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return this.title;
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Return the total number of tests.
|
|
385
|
-
*
|
|
386
|
-
* @api public
|
|
387
|
-
* @return {number}
|
|
388
|
-
*/
|
|
389
|
-
Suite.prototype.total = function() {
|
|
390
|
-
return utils.reduce(this.suites, function(sum, suite) {
|
|
391
|
-
return sum + suite.total();
|
|
392
|
-
}, 0) + this.tests.length;
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Iterates through each suite recursively to find all tests. Applies a
|
|
397
|
-
* function in the format `fn(test)`.
|
|
398
|
-
*
|
|
399
|
-
* @api private
|
|
400
|
-
* @param {Function} fn
|
|
401
|
-
* @return {Suite}
|
|
402
|
-
*/
|
|
403
|
-
Suite.prototype.eachTest = function(fn) {
|
|
404
|
-
utils.forEach(this.tests, fn);
|
|
405
|
-
utils.forEach(this.suites, function(suite) {
|
|
406
|
-
suite.eachTest(fn);
|
|
407
|
-
});
|
|
408
|
-
return this;
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* This will run the root suite if we happen to be running in delayed mode.
|
|
413
|
-
*/
|
|
414
|
-
Suite.prototype.run = function run() {
|
|
415
|
-
if (this.root) {
|
|
416
|
-
this.emit('run');
|
|
417
|
-
}
|
|
418
|
-
};
|
package/lib/test.js.orig
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var Runnable = require('./runnable');
|
|
6
|
-
<<<<<<< 29a0de2507c7d84ff2e65b525d754e7c859d6dfd
|
|
7
|
-
var inherits = require('./utils').inherits;
|
|
8
|
-
=======
|
|
9
|
-
var create = require('lodash.create');
|
|
10
|
-
var isString = require('./utils').isString;
|
|
11
|
-
>>>>>>> fix(Suite/Test): untitled suite/test-case #1632
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Expose `Test`.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
module.exports = Test;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Initialize a new `Test` with the given `title` and callback `fn`.
|
|
21
|
-
*
|
|
22
|
-
* @api private
|
|
23
|
-
* @param {String} title
|
|
24
|
-
* @param {Function} fn
|
|
25
|
-
*/
|
|
26
|
-
function Test(title, fn) {
|
|
27
|
-
if (!isString(title)) {
|
|
28
|
-
throw new Error('Test `title` should be a "string" but "' + typeof title + '" was given instead.');
|
|
29
|
-
}
|
|
30
|
-
Runnable.call(this, title, fn);
|
|
31
|
-
this.pending = !fn;
|
|
32
|
-
this.type = 'test';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Inherit from `Runnable.prototype`.
|
|
37
|
-
*/
|
|
38
|
-
inherits(Test, Runnable);
|
|
39
|
-
|
|
40
|
-
Test.prototype.clone = function() {
|
|
41
|
-
var test = new Test(this.title, this.fn);
|
|
42
|
-
test.timeout(this.timeout());
|
|
43
|
-
test.slow(this.slow());
|
|
44
|
-
test.enableTimeouts(this.enableTimeouts());
|
|
45
|
-
test.retries(this.retries());
|
|
46
|
-
test.currentRetry(this.currentRetry());
|
|
47
|
-
test.globals(this.globals());
|
|
48
|
-
test.parent = this.parent;
|
|
49
|
-
test.file = this.file;
|
|
50
|
-
test.ctx = this.ctx;
|
|
51
|
-
return test;
|
|
52
|
-
};
|