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/suite.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var EventEmitter = require('events').EventEmitter
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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');
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Expose `Suite`.
|
|
@@ -15,41 +16,38 @@ var EventEmitter = require('events').EventEmitter
|
|
|
15
16
|
exports = module.exports = Suite;
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* Create a new `Suite` with the given `title`
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* is returned to provide nicer reporter
|
|
22
|
-
* and more flexible meta-testing.
|
|
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.
|
|
23
22
|
*
|
|
23
|
+
* @api public
|
|
24
24
|
* @param {Suite} parent
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {string} title
|
|
26
26
|
* @return {Suite}
|
|
27
|
-
* @api public
|
|
28
27
|
*/
|
|
29
|
-
|
|
30
|
-
exports.create = function(parent, title){
|
|
28
|
+
exports.create = function(parent, title) {
|
|
31
29
|
var suite = new Suite(title, parent.ctx);
|
|
32
30
|
suite.parent = parent;
|
|
33
|
-
if (parent.pending)
|
|
31
|
+
if (parent.pending) {
|
|
32
|
+
suite.pending = true;
|
|
33
|
+
}
|
|
34
34
|
title = suite.fullTitle();
|
|
35
35
|
parent.addSuite(suite);
|
|
36
36
|
return suite;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* Initialize a new `Suite` with the given
|
|
41
|
-
* `title` and `ctx`.
|
|
40
|
+
* Initialize a new `Suite` with the given `title` and `ctx`.
|
|
42
41
|
*
|
|
43
|
-
* @param {String} title
|
|
44
|
-
* @param {Context} ctx
|
|
45
42
|
* @api private
|
|
43
|
+
* @param {string} title
|
|
44
|
+
* @param {Context} parentContext
|
|
46
45
|
*/
|
|
47
|
-
|
|
48
46
|
function Suite(title, parentContext) {
|
|
49
47
|
this.title = title;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.ctx = new
|
|
48
|
+
function Context() {}
|
|
49
|
+
Context.prototype = parentContext;
|
|
50
|
+
this.ctx = new Context();
|
|
53
51
|
this.suites = [];
|
|
54
52
|
this.tests = [];
|
|
55
53
|
this.pending = false;
|
|
@@ -68,17 +66,15 @@ function Suite(title, parentContext) {
|
|
|
68
66
|
/**
|
|
69
67
|
* Inherit from `EventEmitter.prototype`.
|
|
70
68
|
*/
|
|
71
|
-
|
|
72
|
-
Suite.prototype.__proto__ = EventEmitter.prototype;
|
|
69
|
+
inherits(Suite, EventEmitter);
|
|
73
70
|
|
|
74
71
|
/**
|
|
75
72
|
* Return a clone of this `Suite`.
|
|
76
73
|
*
|
|
77
|
-
* @return {Suite}
|
|
78
74
|
* @api private
|
|
75
|
+
* @return {Suite}
|
|
79
76
|
*/
|
|
80
|
-
|
|
81
|
-
Suite.prototype.clone = function(){
|
|
77
|
+
Suite.prototype.clone = function() {
|
|
82
78
|
var suite = new Suite(this.title);
|
|
83
79
|
debug('clone');
|
|
84
80
|
suite.ctx = this.ctx;
|
|
@@ -92,30 +88,36 @@ Suite.prototype.clone = function(){
|
|
|
92
88
|
/**
|
|
93
89
|
* Set timeout `ms` or short-hand such as "2s".
|
|
94
90
|
*
|
|
95
|
-
* @param {Number|String} ms
|
|
96
|
-
* @return {Suite|Number} for chaining
|
|
97
91
|
* @api private
|
|
92
|
+
* @param {number|string} ms
|
|
93
|
+
* @return {Suite|number} for chaining
|
|
98
94
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (
|
|
95
|
+
Suite.prototype.timeout = function(ms) {
|
|
96
|
+
if (!arguments.length) {
|
|
97
|
+
return this._timeout;
|
|
98
|
+
}
|
|
99
|
+
if (ms.toString() === '0') {
|
|
100
|
+
this._enableTimeouts = false;
|
|
101
|
+
}
|
|
102
|
+
if (typeof ms === 'string') {
|
|
103
|
+
ms = milliseconds(ms);
|
|
104
|
+
}
|
|
104
105
|
debug('timeout %d', ms);
|
|
105
106
|
this._timeout = parseInt(ms, 10);
|
|
106
107
|
return this;
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
|
-
* Set timeout `enabled`.
|
|
111
|
+
* Set timeout to `enabled`.
|
|
111
112
|
*
|
|
112
|
-
* @param {Boolean} enabled
|
|
113
|
-
* @return {Suite|Boolean} self or enabled
|
|
114
113
|
* @api private
|
|
114
|
+
* @param {boolean} enabled
|
|
115
|
+
* @return {Suite|boolean} self or enabled
|
|
115
116
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
Suite.prototype.enableTimeouts = function(enabled) {
|
|
118
|
+
if (!arguments.length) {
|
|
119
|
+
return this._enableTimeouts;
|
|
120
|
+
}
|
|
119
121
|
debug('enableTimeouts %s', enabled);
|
|
120
122
|
this._enableTimeouts = enabled;
|
|
121
123
|
return this;
|
|
@@ -124,14 +126,17 @@ Suite.prototype.enableTimeouts = function(enabled){
|
|
|
124
126
|
/**
|
|
125
127
|
* Set slow `ms` or short-hand such as "2s".
|
|
126
128
|
*
|
|
127
|
-
* @param {Number|String} ms
|
|
128
|
-
* @return {Suite|Number} for chaining
|
|
129
129
|
* @api private
|
|
130
|
+
* @param {number|string} ms
|
|
131
|
+
* @return {Suite|number} for chaining
|
|
130
132
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
Suite.prototype.slow = function(ms) {
|
|
134
|
+
if (!arguments.length) {
|
|
135
|
+
return this._slow;
|
|
136
|
+
}
|
|
137
|
+
if (typeof ms === 'string') {
|
|
138
|
+
ms = milliseconds(ms);
|
|
139
|
+
}
|
|
135
140
|
debug('slow %d', ms);
|
|
136
141
|
this._slow = ms;
|
|
137
142
|
return this;
|
|
@@ -140,13 +145,14 @@ Suite.prototype.slow = function(ms){
|
|
|
140
145
|
/**
|
|
141
146
|
* Sets whether to bail after first error.
|
|
142
147
|
*
|
|
143
|
-
* @param {Boolean} bail
|
|
144
|
-
* @return {Suite|Number} for chaining
|
|
145
148
|
* @api private
|
|
149
|
+
* @param {boolean} bail
|
|
150
|
+
* @return {Suite|number} for chaining
|
|
146
151
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
Suite.prototype.bail = function(bail) {
|
|
153
|
+
if (!arguments.length) {
|
|
154
|
+
return this._bail;
|
|
155
|
+
}
|
|
150
156
|
debug('bail %s', bail);
|
|
151
157
|
this._bail = bail;
|
|
152
158
|
return this;
|
|
@@ -155,14 +161,16 @@ Suite.prototype.bail = function(bail){
|
|
|
155
161
|
/**
|
|
156
162
|
* Run `fn(test[, done])` before running tests.
|
|
157
163
|
*
|
|
164
|
+
* @api private
|
|
165
|
+
* @param {string} title
|
|
158
166
|
* @param {Function} fn
|
|
159
167
|
* @return {Suite} for chaining
|
|
160
|
-
* @api private
|
|
161
168
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
Suite.prototype.beforeAll = function(title, fn) {
|
|
170
|
+
if (this.pending) {
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
if (typeof title === 'function') {
|
|
166
174
|
fn = title;
|
|
167
175
|
title = fn.name;
|
|
168
176
|
}
|
|
@@ -182,14 +190,16 @@ Suite.prototype.beforeAll = function(title, fn){
|
|
|
182
190
|
/**
|
|
183
191
|
* Run `fn(test[, done])` after running tests.
|
|
184
192
|
*
|
|
193
|
+
* @api private
|
|
194
|
+
* @param {string} title
|
|
185
195
|
* @param {Function} fn
|
|
186
196
|
* @return {Suite} for chaining
|
|
187
|
-
* @api private
|
|
188
197
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
198
|
+
Suite.prototype.afterAll = function(title, fn) {
|
|
199
|
+
if (this.pending) {
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
if (typeof title === 'function') {
|
|
193
203
|
fn = title;
|
|
194
204
|
title = fn.name;
|
|
195
205
|
}
|
|
@@ -209,14 +219,16 @@ Suite.prototype.afterAll = function(title, fn){
|
|
|
209
219
|
/**
|
|
210
220
|
* Run `fn(test[, done])` before each test case.
|
|
211
221
|
*
|
|
222
|
+
* @api private
|
|
223
|
+
* @param {string} title
|
|
212
224
|
* @param {Function} fn
|
|
213
225
|
* @return {Suite} for chaining
|
|
214
|
-
* @api private
|
|
215
226
|
*/
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
Suite.prototype.beforeEach = function(title, fn) {
|
|
228
|
+
if (this.pending) {
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
if (typeof title === 'function') {
|
|
220
232
|
fn = title;
|
|
221
233
|
title = fn.name;
|
|
222
234
|
}
|
|
@@ -236,14 +248,16 @@ Suite.prototype.beforeEach = function(title, fn){
|
|
|
236
248
|
/**
|
|
237
249
|
* Run `fn(test[, done])` after each test case.
|
|
238
250
|
*
|
|
251
|
+
* @api private
|
|
252
|
+
* @param {string} title
|
|
239
253
|
* @param {Function} fn
|
|
240
254
|
* @return {Suite} for chaining
|
|
241
|
-
* @api private
|
|
242
255
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
256
|
+
Suite.prototype.afterEach = function(title, fn) {
|
|
257
|
+
if (this.pending) {
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
if (typeof title === 'function') {
|
|
247
261
|
fn = title;
|
|
248
262
|
title = fn.name;
|
|
249
263
|
}
|
|
@@ -263,12 +277,11 @@ Suite.prototype.afterEach = function(title, fn){
|
|
|
263
277
|
/**
|
|
264
278
|
* Add a test `suite`.
|
|
265
279
|
*
|
|
280
|
+
* @api private
|
|
266
281
|
* @param {Suite} suite
|
|
267
282
|
* @return {Suite} for chaining
|
|
268
|
-
* @api private
|
|
269
283
|
*/
|
|
270
|
-
|
|
271
|
-
Suite.prototype.addSuite = function(suite){
|
|
284
|
+
Suite.prototype.addSuite = function(suite) {
|
|
272
285
|
suite.parent = this;
|
|
273
286
|
suite.timeout(this.timeout());
|
|
274
287
|
suite.enableTimeouts(this.enableTimeouts());
|
|
@@ -282,12 +295,11 @@ Suite.prototype.addSuite = function(suite){
|
|
|
282
295
|
/**
|
|
283
296
|
* Add a `test` to this suite.
|
|
284
297
|
*
|
|
298
|
+
* @api private
|
|
285
299
|
* @param {Test} test
|
|
286
300
|
* @return {Suite} for chaining
|
|
287
|
-
* @api private
|
|
288
301
|
*/
|
|
289
|
-
|
|
290
|
-
Suite.prototype.addTest = function(test){
|
|
302
|
+
Suite.prototype.addTest = function(test) {
|
|
291
303
|
test.parent = this;
|
|
292
304
|
test.timeout(this.timeout());
|
|
293
305
|
test.enableTimeouts(this.enableTimeouts());
|
|
@@ -299,17 +311,18 @@ Suite.prototype.addTest = function(test){
|
|
|
299
311
|
};
|
|
300
312
|
|
|
301
313
|
/**
|
|
302
|
-
* Return the full title generated by recursively
|
|
303
|
-
*
|
|
314
|
+
* Return the full title generated by recursively concatenating the parent's
|
|
315
|
+
* full title.
|
|
304
316
|
*
|
|
305
|
-
* @return {String}
|
|
306
317
|
* @api public
|
|
318
|
+
* @return {string}
|
|
307
319
|
*/
|
|
308
|
-
|
|
309
|
-
Suite.prototype.fullTitle = function(){
|
|
320
|
+
Suite.prototype.fullTitle = function() {
|
|
310
321
|
if (this.parent) {
|
|
311
322
|
var full = this.parent.fullTitle();
|
|
312
|
-
if (full)
|
|
323
|
+
if (full) {
|
|
324
|
+
return full + ' ' + this.title;
|
|
325
|
+
}
|
|
313
326
|
}
|
|
314
327
|
return this.title;
|
|
315
328
|
};
|
|
@@ -317,29 +330,26 @@ Suite.prototype.fullTitle = function(){
|
|
|
317
330
|
/**
|
|
318
331
|
* Return the total number of tests.
|
|
319
332
|
*
|
|
320
|
-
* @return {Number}
|
|
321
333
|
* @api public
|
|
334
|
+
* @return {number}
|
|
322
335
|
*/
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return utils.reduce(this.suites, function(sum, suite){
|
|
336
|
+
Suite.prototype.total = function() {
|
|
337
|
+
return utils.reduce(this.suites, function(sum, suite) {
|
|
326
338
|
return sum + suite.total();
|
|
327
339
|
}, 0) + this.tests.length;
|
|
328
340
|
};
|
|
329
341
|
|
|
330
342
|
/**
|
|
331
|
-
* Iterates through each suite recursively to find
|
|
332
|
-
*
|
|
333
|
-
* `fn(test)`.
|
|
343
|
+
* Iterates through each suite recursively to find all tests. Applies a
|
|
344
|
+
* function in the format `fn(test)`.
|
|
334
345
|
*
|
|
346
|
+
* @api private
|
|
335
347
|
* @param {Function} fn
|
|
336
348
|
* @return {Suite}
|
|
337
|
-
* @api private
|
|
338
349
|
*/
|
|
339
|
-
|
|
340
|
-
Suite.prototype.eachTest = function(fn){
|
|
350
|
+
Suite.prototype.eachTest = function(fn) {
|
|
341
351
|
utils.forEach(this.tests, fn);
|
|
342
|
-
utils.forEach(this.suites, function(suite){
|
|
352
|
+
utils.forEach(this.suites, function(suite) {
|
|
343
353
|
suite.eachTest(fn);
|
|
344
354
|
});
|
|
345
355
|
return this;
|
package/lib/template.html
CHANGED
package/lib/test.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
var Runnable = require('./runnable');
|
|
6
|
+
var inherits = require('./utils').inherits;
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Expose `Test`.
|
|
@@ -13,11 +14,10 @@ module.exports = Test;
|
|
|
13
14
|
/**
|
|
14
15
|
* Initialize a new `Test` with the given `title` and callback `fn`.
|
|
15
16
|
*
|
|
17
|
+
* @api private
|
|
16
18
|
* @param {String} title
|
|
17
19
|
* @param {Function} fn
|
|
18
|
-
* @api private
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
21
|
function Test(title, fn) {
|
|
22
22
|
Runnable.call(this, title, fn);
|
|
23
23
|
this.pending = !fn;
|
|
@@ -27,5 +27,4 @@ function Test(title, fn) {
|
|
|
27
27
|
/**
|
|
28
28
|
* Inherit from `Runnable.prototype`.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
Test.prototype.__proto__ = Runnable.prototype;
|
|
30
|
+
inherits(Test, Runnable);
|