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/runnable.js.orig
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var EventEmitter = require('events').EventEmitter;
|
|
6
|
-
var JSON = require('json3');
|
|
7
|
-
var Pending = require('./pending');
|
|
8
|
-
var debug = require('debug')('mocha:runnable');
|
|
9
|
-
var milliseconds = require('./ms');
|
|
10
|
-
var utils = require('./utils');
|
|
11
|
-
var create = require('lodash.create');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* eslint-disable no-unused-vars, no-native-reassign */
|
|
18
|
-
var Date = global.Date;
|
|
19
|
-
var setTimeout = global.setTimeout;
|
|
20
|
-
var setInterval = global.setInterval;
|
|
21
|
-
var clearTimeout = global.clearTimeout;
|
|
22
|
-
var clearInterval = global.clearInterval;
|
|
23
|
-
/* eslint-enable no-unused-vars, no-native-reassign */
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Object#toString().
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
var toString = Object.prototype.toString;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Expose `Runnable`.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
module.exports = Runnable;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Initialize a new `Runnable` with the given `title` and callback `fn`.
|
|
39
|
-
*
|
|
40
|
-
* @param {String} title
|
|
41
|
-
* @param {Function} fn
|
|
42
|
-
* @api private
|
|
43
|
-
* @param {string} title
|
|
44
|
-
* @param {Function} fn
|
|
45
|
-
*/
|
|
46
|
-
function Runnable(title, fn) {
|
|
47
|
-
this.title = title;
|
|
48
|
-
this.fn = fn;
|
|
49
|
-
this.body = (fn || '').toString();
|
|
50
|
-
this.async = fn && fn.length;
|
|
51
|
-
this.sync = !this.async;
|
|
52
|
-
this._timeout = 2000;
|
|
53
|
-
this._slow = 75;
|
|
54
|
-
this._enableTimeouts = true;
|
|
55
|
-
this.timedOut = false;
|
|
56
|
-
this._trace = new Error('done() called multiple times');
|
|
57
|
-
this._retries = -1;
|
|
58
|
-
this._currentRetry = 0;
|
|
59
|
-
this.pending = false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Inherit from `EventEmitter.prototype`.
|
|
64
|
-
*/
|
|
65
|
-
Runnable.prototype = create(EventEmitter.prototype, {
|
|
66
|
-
constructor: Runnable
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Set & get timeout `ms`.
|
|
71
|
-
*
|
|
72
|
-
* @api private
|
|
73
|
-
* @param {number|string} ms
|
|
74
|
-
* @return {Runnable|number} ms or Runnable instance.
|
|
75
|
-
*/
|
|
76
|
-
Runnable.prototype.timeout = function(ms) {
|
|
77
|
-
if (!arguments.length) {
|
|
78
|
-
return this._timeout;
|
|
79
|
-
}
|
|
80
|
-
// see #1652 for reasoning
|
|
81
|
-
if (ms === 0 || ms > Math.pow(2, 31)) {
|
|
82
|
-
this._enableTimeouts = false;
|
|
83
|
-
}
|
|
84
|
-
if (typeof ms === 'string') {
|
|
85
|
-
ms = milliseconds(ms);
|
|
86
|
-
}
|
|
87
|
-
debug('timeout %d', ms);
|
|
88
|
-
this._timeout = ms;
|
|
89
|
-
if (this.timer) {
|
|
90
|
-
this.resetTimeout();
|
|
91
|
-
}
|
|
92
|
-
return this;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Set & get slow `ms`.
|
|
97
|
-
*
|
|
98
|
-
* @api private
|
|
99
|
-
* @param {number|string} ms
|
|
100
|
-
* @return {Runnable|number} ms or Runnable instance.
|
|
101
|
-
*/
|
|
102
|
-
Runnable.prototype.slow = function(ms) {
|
|
103
|
-
if (typeof ms === 'undefined') {
|
|
104
|
-
return this._slow;
|
|
105
|
-
}
|
|
106
|
-
if (typeof ms === 'string') {
|
|
107
|
-
ms = milliseconds(ms);
|
|
108
|
-
}
|
|
109
|
-
debug('timeout %d', ms);
|
|
110
|
-
this._slow = ms;
|
|
111
|
-
return this;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Set and get whether timeout is `enabled`.
|
|
116
|
-
*
|
|
117
|
-
* @api private
|
|
118
|
-
* @param {boolean} enabled
|
|
119
|
-
* @return {Runnable|boolean} enabled or Runnable instance.
|
|
120
|
-
*/
|
|
121
|
-
Runnable.prototype.enableTimeouts = function(enabled) {
|
|
122
|
-
if (!arguments.length) {
|
|
123
|
-
return this._enableTimeouts;
|
|
124
|
-
}
|
|
125
|
-
debug('enableTimeouts %s', enabled);
|
|
126
|
-
this._enableTimeouts = enabled;
|
|
127
|
-
return this;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Halt and mark as pending.
|
|
132
|
-
*
|
|
133
|
-
* @api public
|
|
134
|
-
*/
|
|
135
|
-
Runnable.prototype.skip = function() {
|
|
136
|
-
throw new Pending();
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Check if this runnable or its parent suite is marked as pending.
|
|
141
|
-
*
|
|
142
|
-
* @api private
|
|
143
|
-
*/
|
|
144
|
-
Runnable.prototype.isPending = function() {
|
|
145
|
-
return this.pending || (this.parent && this.parent.isPending());
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Set number of retries.
|
|
150
|
-
*
|
|
151
|
-
* @api private
|
|
152
|
-
*/
|
|
153
|
-
Runnable.prototype.retries = function(n) {
|
|
154
|
-
if (!arguments.length) {
|
|
155
|
-
return this._retries;
|
|
156
|
-
}
|
|
157
|
-
this._retries = n;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Get current retry
|
|
162
|
-
*
|
|
163
|
-
* @api private
|
|
164
|
-
*/
|
|
165
|
-
Runnable.prototype.currentRetry = function(n) {
|
|
166
|
-
if (!arguments.length) {
|
|
167
|
-
return this._currentRetry;
|
|
168
|
-
}
|
|
169
|
-
this._currentRetry = n;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Return the full title generated by recursively concatenating the parent's
|
|
174
|
-
* full title.
|
|
175
|
-
*
|
|
176
|
-
* @api public
|
|
177
|
-
* @return {string}
|
|
178
|
-
*/
|
|
179
|
-
Runnable.prototype.fullTitle = function() {
|
|
180
|
-
return this.parent.fullTitle() + ' ' + this.title;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Clear the timeout.
|
|
185
|
-
*
|
|
186
|
-
* @api private
|
|
187
|
-
*/
|
|
188
|
-
Runnable.prototype.clearTimeout = function() {
|
|
189
|
-
clearTimeout(this.timer);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Inspect the runnable void of private properties.
|
|
194
|
-
*
|
|
195
|
-
* @api private
|
|
196
|
-
* @return {string}
|
|
197
|
-
*/
|
|
198
|
-
Runnable.prototype.inspect = function() {
|
|
199
|
-
return JSON.stringify(this, function(key, val) {
|
|
200
|
-
if (key[0] === '_') {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (key === 'parent') {
|
|
204
|
-
return '#<Suite>';
|
|
205
|
-
}
|
|
206
|
-
if (key === 'ctx') {
|
|
207
|
-
return '#<Context>';
|
|
208
|
-
}
|
|
209
|
-
return val;
|
|
210
|
-
}, 2);
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Reset the timeout.
|
|
215
|
-
*
|
|
216
|
-
* @api private
|
|
217
|
-
*/
|
|
218
|
-
Runnable.prototype.resetTimeout = function() {
|
|
219
|
-
var self = this;
|
|
220
|
-
var ms = this.timeout() || 1e9;
|
|
221
|
-
|
|
222
|
-
if (!this._enableTimeouts) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
this.clearTimeout();
|
|
226
|
-
this.timer = setTimeout(function() {
|
|
227
|
-
if (!self._enableTimeouts) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
self.callback(new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.'));
|
|
231
|
-
self.timedOut = true;
|
|
232
|
-
}, ms);
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Whitelist a list of globals for this test run.
|
|
237
|
-
*
|
|
238
|
-
* @api private
|
|
239
|
-
* @param {string[]} globals
|
|
240
|
-
*/
|
|
241
|
-
Runnable.prototype.globals = function(globals) {
|
|
242
|
-
if (!arguments.length) {
|
|
243
|
-
return this._allowedGlobals;
|
|
244
|
-
}
|
|
245
|
-
this._allowedGlobals = globals;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Run the test and invoke `fn(err)`.
|
|
250
|
-
*
|
|
251
|
-
* @param {Function} fn
|
|
252
|
-
* @api private
|
|
253
|
-
*/
|
|
254
|
-
Runnable.prototype.run = function(fn) {
|
|
255
|
-
var self = this;
|
|
256
|
-
var start = new Date();
|
|
257
|
-
var ctx = this.ctx;
|
|
258
|
-
var finished;
|
|
259
|
-
var emitted;
|
|
260
|
-
|
|
261
|
-
// Sometimes the ctx exists, but it is not runnable
|
|
262
|
-
if (ctx && ctx.runnable) {
|
|
263
|
-
ctx.runnable(this);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// called multiple times
|
|
267
|
-
function multiple(err) {
|
|
268
|
-
if (emitted) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
emitted = true;
|
|
272
|
-
self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// finished
|
|
276
|
-
function done(err) {
|
|
277
|
-
var ms = self.timeout();
|
|
278
|
-
if (self.timedOut) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
if (finished) {
|
|
282
|
-
return multiple(err || self._trace);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
self.clearTimeout();
|
|
286
|
-
self.duration = new Date() - start;
|
|
287
|
-
finished = true;
|
|
288
|
-
if (!err && self.duration > ms && self._enableTimeouts) {
|
|
289
|
-
err = new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.');
|
|
290
|
-
}
|
|
291
|
-
fn(err);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// for .resetTimeout()
|
|
295
|
-
this.callback = done;
|
|
296
|
-
|
|
297
|
-
// explicit async with `done` argument
|
|
298
|
-
if (this.async) {
|
|
299
|
-
this.resetTimeout();
|
|
300
|
-
|
|
301
|
-
if (this.allowUncaught) {
|
|
302
|
-
return callFnAsync(this.fn);
|
|
303
|
-
}
|
|
304
|
-
try {
|
|
305
|
-
// allows skip() to be used in an explicit async context
|
|
306
|
-
this.skip = function() {
|
|
307
|
-
done(new Pending());
|
|
308
|
-
};
|
|
309
|
-
callFnAsync(this.fn);
|
|
310
|
-
} catch (err) {
|
|
311
|
-
done(utils.getError(err));
|
|
312
|
-
}
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
<<<<<<< 9413c27ac408f704849ab65758402820ae20498f
|
|
317
|
-
if (this.allowUncaught) {
|
|
318
|
-
callFn(this.fn);
|
|
319
|
-
done();
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
=======
|
|
324
|
-
>>>>>>> Allow --async-only to be satisfied by returning a promise
|
|
325
|
-
// sync or promise-returning
|
|
326
|
-
try {
|
|
327
|
-
if (this.isPending()) {
|
|
328
|
-
done();
|
|
329
|
-
} else {
|
|
330
|
-
callFn(this.fn);
|
|
331
|
-
}
|
|
332
|
-
} catch (err) {
|
|
333
|
-
done(utils.getError(err));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function callFn(fn) {
|
|
337
|
-
var result = fn.call(ctx);
|
|
338
|
-
if (result && typeof result.then === 'function') {
|
|
339
|
-
self.resetTimeout();
|
|
340
|
-
result
|
|
341
|
-
.then(function() {
|
|
342
|
-
done();
|
|
343
|
-
// Return null so libraries like bluebird do not warn about
|
|
344
|
-
// subsequently constructed Promises.
|
|
345
|
-
return null;
|
|
346
|
-
},
|
|
347
|
-
function(reason) {
|
|
348
|
-
done(reason || new Error('Promise rejected with no or falsy reason'));
|
|
349
|
-
});
|
|
350
|
-
} else {
|
|
351
|
-
if (self.asyncOnly) {
|
|
352
|
-
return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
done();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function callFnAsync(fn) {
|
|
360
|
-
var result = fn.call(ctx, function(err) {
|
|
361
|
-
if (err instanceof Error || toString.call(err) === '[object Error]') {
|
|
362
|
-
return done(err);
|
|
363
|
-
}
|
|
364
|
-
if (err) {
|
|
365
|
-
if (Object.prototype.toString.call(err) === '[object Object]') {
|
|
366
|
-
return done(new Error('done() invoked with non-Error: '
|
|
367
|
-
+ JSON.stringify(err)));
|
|
368
|
-
}
|
|
369
|
-
return done(new Error('done() invoked with non-Error: ' + err));
|
|
370
|
-
}
|
|
371
|
-
if (result && utils.isPromise(result)) {
|
|
372
|
-
return done(new Error('Asynchronous resolution method is overspecified. Specify a callback *or* return a Promise, not both.'));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
done();
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
};
|