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.
Files changed (53) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/bin/_mocha +170 -104
  5. package/bin/mocha +22 -13
  6. package/bin/options.js +7 -5
  7. package/browser-entry.js +43 -22
  8. package/lib/browser/.eslintrc.yaml +4 -0
  9. package/lib/browser/debug.js +6 -3
  10. package/lib/browser/events.js +11 -9
  11. package/lib/browser/progress.js +9 -7
  12. package/lib/browser/tty.js +4 -2
  13. package/lib/context.js +11 -9
  14. package/lib/hook.js +4 -2
  15. package/lib/interfaces/bdd.js +11 -9
  16. package/lib/interfaces/common.js +16 -14
  17. package/lib/interfaces/exports.js +4 -2
  18. package/lib/interfaces/index.js +2 -0
  19. package/lib/interfaces/qunit.js +12 -8
  20. package/lib/interfaces/tdd.js +9 -7
  21. package/lib/mocha.js +36 -34
  22. package/lib/ms.js +12 -10
  23. package/lib/pending.js +2 -1
  24. package/lib/reporters/base.js +52 -50
  25. package/lib/reporters/doc.js +8 -6
  26. package/lib/reporters/dot.js +9 -7
  27. package/lib/reporters/html.js +32 -30
  28. package/lib/reporters/index.js +2 -0
  29. package/lib/reporters/json-stream.js +8 -6
  30. package/lib/reporters/json.js +11 -9
  31. package/lib/reporters/landing.js +8 -6
  32. package/lib/reporters/list.js +13 -11
  33. package/lib/reporters/markdown.js +12 -10
  34. package/lib/reporters/min.js +4 -2
  35. package/lib/reporters/nyan.js +22 -20
  36. package/lib/reporters/progress.js +7 -5
  37. package/lib/reporters/spec.js +17 -15
  38. package/lib/reporters/tap.js +10 -8
  39. package/lib/reporters/xunit.js +14 -12
  40. package/lib/runnable.js +43 -32
  41. package/lib/runner.js +78 -63
  42. package/lib/suite.js +24 -22
  43. package/lib/test.js +4 -2
  44. package/lib/utils.js +115 -90
  45. package/mocha.js +1185 -800
  46. package/package.json +9 -2
  47. package/lib/interfaces/bdd.js.orig +0 -118
  48. package/lib/mocha.js.orig +0 -532
  49. package/lib/runnable.js.orig +0 -378
  50. package/lib/runner.js.orig +0 -934
  51. package/lib/suite.js.orig +0 -418
  52. package/lib/test.js.orig +0 -52
  53. package/lib/utils.js.orig +0 -758
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha",
3
- "version": "3.0.2",
3
+ "version": "3.2.0",
4
4
  "description": "simple, flexible, fun test framework",
5
5
  "keywords": [
6
6
  "mocha",
@@ -314,17 +314,24 @@
314
314
  "supports-color": "3.1.2"
315
315
  },
316
316
  "devDependencies": {
317
+ "assert": "^1.4.1",
317
318
  "browserify": "^13.0.0",
318
319
  "coffee-script": "^1.10.0",
319
320
  "eslint": "^2.13.1",
321
+ "eslint-config-semistandard": "^6.0.2",
322
+ "eslint-config-standard": "^5.0.0",
323
+ "eslint-plugin-promise": "^2.0.1",
324
+ "eslint-plugin-standard": "1.3.2",
320
325
  "expect.js": "^0.3.1",
321
326
  "karma": "^1.1.0",
322
327
  "karma-browserify": "^5.0.5",
328
+ "karma-chrome-launcher": "^2.0.0",
323
329
  "karma-expect": "^1.1.2",
324
- "karma-no-mocha": "^2.0.0",
330
+ "karma-mocha": "^1.3.0",
325
331
  "karma-phantomjs-launcher": "^0.2.3",
326
332
  "karma-sauce-launcher": "^1.0.0",
327
333
  "karma-spec-reporter": "0.0.26",
334
+ "os-name": "^2.0.1",
328
335
  "phantomjs": "1.9.8",
329
336
  "rimraf": "^2.5.2",
330
337
  "should": "^9.0.2",
@@ -1,118 +0,0 @@
1
- /**
2
- * Module dependencies.
3
- */
4
-
5
- var Suite = require('../suite');
6
- var Test = require('../test');
7
-
8
- /**
9
- * BDD-style interface:
10
- *
11
- * describe('Array', function() {
12
- * describe('#indexOf()', function() {
13
- * it('should return -1 when not present', function() {
14
- * // ...
15
- * });
16
- *
17
- * it('should return the index when present', function() {
18
- * // ...
19
- * });
20
- * });
21
- * });
22
- *
23
- * @param {Suite} suite Root suite.
24
- */
25
- module.exports = function(suite) {
26
- var suites = [suite];
27
-
28
- suite.on('pre-require', function(context, file, mocha) {
29
- var common = require('./common')(suites, context);
30
-
31
- context.before = common.before;
32
- context.after = common.after;
33
- context.beforeEach = common.beforeEach;
34
- context.afterEach = common.afterEach;
35
- context.run = mocha.options.delay && common.runWithSuite(suite);
36
- /**
37
- * Describe a "suite" with the given `title`
38
- * and callback `fn` containing nested suites
39
- * and/or tests.
40
- */
41
-
42
- context.describe = context.context = function(title, fn) {
43
- var suite = Suite.create(suites[0], title);
44
- suite.file = file;
45
- suites.unshift(suite);
46
- fn.call(suite);
47
- suites.shift();
48
- return suite;
49
- };
50
-
51
- /**
52
- * Pending describe.
53
- */
54
-
55
- context.xdescribe = context.xcontext = context.describe.skip = function(title, fn) {
56
- var suite = Suite.create(suites[0], title);
57
- suite.pending = true;
58
- suites.unshift(suite);
59
- fn.call(suite);
60
- suites.shift();
61
- };
62
-
63
- /**
64
- * Exclusive suite.
65
- */
66
-
67
- context.describe.only = function(title, fn) {
68
- return common.suite.only(mocha, context.describe(title, fn));
69
- };
70
-
71
- /**
72
- * Describe a specification or test-case
73
- * with the given `title` and callback `fn`
74
- * acting as a thunk.
75
- */
76
-
77
- var it = context.it = context.specify = function(title, fn) {
78
- var suite = suites[0];
79
- if (suite.isPending()) {
80
- fn = null;
81
- }
82
- var test = new Test(title, fn);
83
- test.file = file;
84
- suite.addTest(test);
85
- return test;
86
- };
87
-
88
- /**
89
- * Exclusive test-case.
90
- */
91
-
92
- context.it.only = function(title, fn) {
93
- <<<<<<< 9413c27ac408f704849ab65758402820ae20498f
94
- var test = it(title, fn);
95
- var reString = '^' + escapeRe(test.fullTitle()) + '$';
96
- mocha.grep(new RegExp(reString));
97
- return test;
98
- =======
99
- return common.test.only(mocha, context.it(title, fn));
100
- >>>>>>> feat(runner): fix '.only()' exclusive feature, #1481
101
- };
102
-
103
- /**
104
- * Pending test case.
105
- */
106
-
107
- context.xit = context.xspecify = context.it.skip = function(title) {
108
- context.it(title);
109
- };
110
-
111
- /**
112
- * Number of attempts to retry.
113
- */
114
- context.it.retries = function(n) {
115
- context.retries(n);
116
- };
117
- });
118
- };
package/lib/mocha.js.orig DELETED
@@ -1,532 +0,0 @@
1
- /*!
2
- * mocha
3
- * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
4
- * MIT Licensed
5
- */
6
-
7
- /**
8
- * Module dependencies.
9
- */
10
-
11
- var escapeRe = require('escape-string-regexp');
12
- var path = require('path');
13
- var reporters = require('./reporters');
14
- var utils = require('./utils');
15
-
16
- /**
17
- * Expose `Mocha`.
18
- */
19
-
20
- exports = module.exports = Mocha;
21
-
22
- /**
23
- * To require local UIs and reporters when running in node.
24
- */
25
-
26
- if (!process.browser) {
27
- var cwd = process.cwd();
28
- module.paths.push(cwd, path.join(cwd, 'node_modules'));
29
- }
30
-
31
- /**
32
- * Expose internals.
33
- */
34
-
35
- exports.utils = utils;
36
- exports.interfaces = require('./interfaces');
37
- exports.reporters = reporters;
38
- exports.Runnable = require('./runnable');
39
- exports.Context = require('./context');
40
- exports.Runner = require('./runner');
41
- exports.Suite = require('./suite');
42
- exports.Hook = require('./hook');
43
- exports.Test = require('./test');
44
-
45
- /**
46
- * Return image `name` path.
47
- *
48
- * @api private
49
- * @param {string} name
50
- * @return {string}
51
- */
52
- function image(name) {
53
- return path.join(__dirname, '../images', name + '.png');
54
- }
55
-
56
- /**
57
- * Set up mocha with `options`.
58
- *
59
- * Options:
60
- *
61
- * - `ui` name "bdd", "tdd", "exports" etc
62
- * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
63
- * - `globals` array of accepted globals
64
- * - `timeout` timeout in milliseconds
65
- * - `retries` number of times to retry failed tests
66
- * - `bail` bail on the first test failure
67
- * - `slow` milliseconds to wait before considering a test slow
68
- * - `ignoreLeaks` ignore global leaks
69
- * - `fullTrace` display the full stack-trace on failing
70
- * - `grep` string or regexp to filter tests with
71
- * - `randomMode` mode for randomization of tests
72
- * - `randomSeed` seed for randomization of tests
73
- *
74
- * @param {Object} options
75
- * @api public
76
- */
77
- function Mocha(options) {
78
- options = options || {};
79
- this.files = [];
80
- this.options = options;
81
- if (options.grep) {
82
- this.grep(new RegExp(options.grep));
83
- }
84
- if (options.fgrep) {
85
- this.grep(options.fgrep);
86
- }
87
- this.suite = new exports.Suite('', new exports.Context());
88
- this.ui(options.ui);
89
- this.bail(options.bail);
90
- this.reporter(options.reporter, options.reporterOptions);
91
- if (typeof options.timeout !== 'undefined' && options.timeout !== null) {
92
- this.timeout(options.timeout);
93
- }
94
- if (typeof options.retries !== 'undefined' && options.retries !== null) {
95
- this.retries(options.retries);
96
- }
97
- this.useColors(options.useColors);
98
- if (options.enableTimeouts !== null) {
99
- this.enableTimeouts(options.enableTimeouts);
100
- }
101
- if (options.slow) {
102
- this.slow(options.slow);
103
- }
104
- }
105
-
106
- /**
107
- * Enable or disable bailing on the first failure.
108
- *
109
- * @api public
110
- * @param {boolean} [bail]
111
- */
112
- Mocha.prototype.bail = function(bail) {
113
- if (!arguments.length) {
114
- bail = true;
115
- }
116
- this.suite.bail(bail);
117
- return this;
118
- };
119
-
120
- /**
121
- * Add test `file`.
122
- *
123
- * @api public
124
- * @param {string} file
125
- */
126
- Mocha.prototype.addFile = function(file) {
127
- this.files.push(file);
128
- return this;
129
- };
130
-
131
- /**
132
- * Set reporter to `reporter`, defaults to "spec".
133
- *
134
- * @param {String|Function} reporter name or constructor
135
- * @param {Object} reporterOptions optional options
136
- * @api public
137
- * @param {string|Function} reporter name or constructor
138
- * @param {Object} reporterOptions optional options
139
- */
140
- Mocha.prototype.reporter = function(reporter, reporterOptions) {
141
- if (typeof reporter === 'function') {
142
- this._reporter = reporter;
143
- } else {
144
- reporter = reporter || 'spec';
145
- var _reporter;
146
- // Try to load a built-in reporter.
147
- if (reporters[reporter]) {
148
- _reporter = reporters[reporter];
149
- }
150
- // Try to load reporters from process.cwd() and node_modules
151
- if (!_reporter) {
152
- try {
153
- _reporter = require(reporter);
154
- } catch (err) {
155
- err.message.indexOf('Cannot find module') !== -1
156
- ? console.warn('"' + reporter + '" reporter not found')
157
- : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
158
- }
159
- }
160
- if (!_reporter && reporter === 'teamcity') {
161
- console.warn('The Teamcity reporter was moved to a package named '
162
- + 'mocha-teamcity-reporter '
163
- + '(https://npmjs.org/package/mocha-teamcity-reporter).');
164
- }
165
- if (!_reporter) {
166
- throw new Error('invalid reporter "' + reporter + '"');
167
- }
168
- this._reporter = _reporter;
169
- }
170
- this.options.reporterOptions = reporterOptions;
171
- return this;
172
- };
173
-
174
- /**
175
- * Set test UI `name`, defaults to "bdd".
176
- *
177
- * @api public
178
- * @param {string} bdd
179
- */
180
- Mocha.prototype.ui = function(name) {
181
- name = name || 'bdd';
182
- this._ui = exports.interfaces[name];
183
- if (!this._ui) {
184
- try {
185
- this._ui = require(name);
186
- } catch (err) {
187
- throw new Error('invalid interface "' + name + '"');
188
- }
189
- }
190
- this._ui = this._ui(this.suite);
191
-
192
- this.suite.on('pre-require', function(context) {
193
- exports.afterEach = context.afterEach || context.teardown;
194
- exports.after = context.after || context.suiteTeardown;
195
- exports.beforeEach = context.beforeEach || context.setup;
196
- exports.before = context.before || context.suiteSetup;
197
- exports.describe = context.describe || context.suite;
198
- exports.it = context.it || context.test;
199
- exports.setup = context.setup || context.beforeEach;
200
- exports.suiteSetup = context.suiteSetup || context.before;
201
- exports.suiteTeardown = context.suiteTeardown || context.after;
202
- exports.suite = context.suite || context.describe;
203
- exports.teardown = context.teardown || context.afterEach;
204
- exports.test = context.test || context.it;
205
- exports.run = context.run;
206
- });
207
-
208
- return this;
209
- };
210
-
211
- /**
212
- * Load registered files.
213
- *
214
- * @api private
215
- */
216
- Mocha.prototype.loadFiles = function(fn) {
217
- var self = this;
218
- var suite = this.suite;
219
- this.files.forEach(function(file) {
220
- file = path.resolve(file);
221
- suite.emit('pre-require', global, file, self);
222
- suite.emit('require', require(file), file, self);
223
- suite.emit('post-require', global, file, self);
224
- });
225
- fn && fn();
226
- };
227
-
228
- /**
229
- * Enable growl support.
230
- *
231
- * @api private
232
- */
233
- Mocha.prototype._growl = function(runner, reporter) {
234
- var notify = require('growl');
235
-
236
- runner.on('end', function() {
237
- var stats = reporter.stats;
238
- if (stats.failures) {
239
- var msg = stats.failures + ' of ' + runner.total + ' tests failed';
240
- notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
241
- } else {
242
- notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
243
- name: 'mocha',
244
- title: 'Passed',
245
- image: image('ok')
246
- });
247
- }
248
- });
249
- };
250
-
251
- /**
252
- * Add regexp to grep, if `re` is a string it is escaped.
253
- *
254
- * @param {RegExp|String} re
255
- * @return {Mocha}
256
- * @api public
257
- * @param {RegExp|string} re
258
- * @return {Mocha}
259
- */
260
- Mocha.prototype.grep = function(re) {
261
- this.options.grep = typeof re === 'string' ? new RegExp(escapeRe(re)) : re;
262
- return this;
263
- };
264
-
265
- /**
266
- * Invert `.grep()` matches.
267
- *
268
- * @return {Mocha}
269
- * @api public
270
- */
271
- Mocha.prototype.invert = function() {
272
- this.options.invert = true;
273
- return this;
274
- };
275
-
276
- /**
277
- * Apply randomization to the tests
278
- *
279
- * @param {String} mode
280
- * @param seed
281
- * @return {Mocha}
282
- * @api public
283
- */
284
-
285
- Mocha.prototype.randomize = function(mode, seed){
286
- if (mode !== 'tests' /* && mode !== 'suites' && mode !== 'both' */) {
287
- throw new Error('unrecognized randomization mode "' + mode + '"');
288
- }
289
- this.options.randomizeMode = mode;
290
- this.options.randomizeSeed = seed != null ? seed : Math.random();
291
- return this;
292
- };
293
-
294
- /**
295
- * Ignore global leaks.
296
- *
297
- * @param {Boolean} ignore
298
- * @return {Mocha}
299
- * @api public
300
- * @param {boolean} ignore
301
- * @return {Mocha}
302
- */
303
- Mocha.prototype.ignoreLeaks = function(ignore) {
304
- this.options.ignoreLeaks = Boolean(ignore);
305
- return this;
306
- };
307
-
308
- /**
309
- * Enable global leak checking.
310
- *
311
- * @return {Mocha}
312
- * @api public
313
- */
314
- Mocha.prototype.checkLeaks = function() {
315
- this.options.ignoreLeaks = false;
316
- return this;
317
- };
318
-
319
- /**
320
- * Display long stack-trace on failing
321
- *
322
- * @return {Mocha}
323
- * @api public
324
- */
325
- Mocha.prototype.fullTrace = function() {
326
- this.options.fullStackTrace = true;
327
- return this;
328
- };
329
-
330
- /**
331
- * Enable growl support.
332
- *
333
- * @return {Mocha}
334
- * @api public
335
- */
336
- Mocha.prototype.growl = function() {
337
- this.options.growl = true;
338
- return this;
339
- };
340
-
341
- /**
342
- * Ignore `globals` array or string.
343
- *
344
- * @param {Array|String} globals
345
- * @return {Mocha}
346
- * @api public
347
- * @param {Array|string} globals
348
- * @return {Mocha}
349
- */
350
- Mocha.prototype.globals = function(globals) {
351
- this.options.globals = (this.options.globals || []).concat(globals);
352
- return this;
353
- };
354
-
355
- /**
356
- * Emit color output.
357
- *
358
- * @param {Boolean} colors
359
- * @return {Mocha}
360
- * @api public
361
- * @param {boolean} colors
362
- * @return {Mocha}
363
- */
364
- Mocha.prototype.useColors = function(colors) {
365
- if (colors !== undefined) {
366
- this.options.useColors = colors;
367
- }
368
- return this;
369
- };
370
-
371
- /**
372
- * Use inline diffs rather than +/-.
373
- *
374
- * @param {Boolean} inlineDiffs
375
- * @return {Mocha}
376
- * @api public
377
- * @param {boolean} inlineDiffs
378
- * @return {Mocha}
379
- */
380
- Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
381
- this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
382
- return this;
383
- };
384
-
385
- /**
386
- * Set the timeout in milliseconds.
387
- *
388
- * @param {Number} timeout
389
- * @return {Mocha}
390
- * @api public
391
- * @param {number} timeout
392
- * @return {Mocha}
393
- */
394
- Mocha.prototype.timeout = function(timeout) {
395
- this.suite.timeout(timeout);
396
- return this;
397
- };
398
-
399
- /**
400
- * Set the number of times to retry failed tests.
401
- *
402
- * @param {Number} retry times
403
- * @return {Mocha}
404
- * @api public
405
- */
406
- Mocha.prototype.retries = function(n) {
407
- this.suite.retries(n);
408
- return this;
409
- };
410
-
411
- /**
412
- * Set slowness threshold in milliseconds.
413
- *
414
- * @param {Number} slow
415
- * @return {Mocha}
416
- * @api public
417
- * @param {number} slow
418
- * @return {Mocha}
419
- */
420
- Mocha.prototype.slow = function(slow) {
421
- this.suite.slow(slow);
422
- return this;
423
- };
424
-
425
- /**
426
- * Enable timeouts.
427
- *
428
- * @param {Boolean} enabled
429
- * @return {Mocha}
430
- * @api public
431
- * @param {boolean} enabled
432
- * @return {Mocha}
433
- */
434
- Mocha.prototype.enableTimeouts = function(enabled) {
435
- this.suite.enableTimeouts(arguments.length && enabled !== undefined ? enabled : true);
436
- return this;
437
- };
438
-
439
- /**
440
- * Makes all tests async (accepting a callback)
441
- *
442
- * @return {Mocha}
443
- * @api public
444
- */
445
- Mocha.prototype.asyncOnly = function() {
446
- this.options.asyncOnly = true;
447
- return this;
448
- };
449
-
450
- /**
451
- * Disable syntax highlighting (in browser).
452
- *
453
- * @api public
454
- */
455
- Mocha.prototype.noHighlighting = function() {
456
- this.options.noHighlighting = true;
457
- return this;
458
- };
459
-
460
- /**
461
- * Enable uncaught errors to propagate (in browser).
462
- *
463
- * @return {Mocha}
464
- * @api public
465
- */
466
- Mocha.prototype.allowUncaught = function() {
467
- this.options.allowUncaught = true;
468
- return this;
469
- };
470
-
471
- /**
472
- * Delay root suite execution.
473
- * @returns {Mocha}
474
- */
475
- Mocha.prototype.delay = function delay() {
476
- this.options.delay = true;
477
- return this;
478
- };
479
-
480
- /**
481
- * Run tests and invoke `fn()` when complete.
482
- *
483
- * @api public
484
- * @param {Function} fn
485
- * @return {Runner}
486
- */
487
- Mocha.prototype.run = function(fn) {
488
- if (this.files.length) {
489
- this.loadFiles();
490
- }
491
- var suite = this.suite;
492
- var options = this.options;
493
- options.files = this.files;
494
- var runner = new exports.Runner(suite, options.delay);
495
- var reporter = new this._reporter(runner, options);
496
- runner.ignoreLeaks = options.ignoreLeaks !== false;
497
- runner.fullStackTrace = options.fullStackTrace;
498
- runner.asyncOnly = options.asyncOnly;
499
- <<<<<<< e939d8e4379a622e28064ca3a75f3e1bda7e225b
500
- runner.allowUncaught = options.allowUncaught;
501
- if (options.grep) {
502
- runner.grep(options.grep, options.invert);
503
- }
504
- if (options.globals) {
505
- runner.globals(options.globals);
506
- }
507
- if (options.growl) {
508
- this._growl(runner, reporter);
509
- }
510
- =======
511
- if (options.grep) runner.grep(options.grep, options.invert);
512
- if (options.globals) runner.globals(options.globals);
513
- if (options.randomizeMode !== undefined) {
514
- runner.randomize(options.randomizeMode, options.randomizeSeed);
515
- }
516
- if (options.growl) this._growl(runner, reporter);
517
- >>>>>>> Add randomization support
518
- if (options.useColors !== undefined) {
519
- exports.reporters.Base.useColors = options.useColors;
520
- }
521
- exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
522
-
523
- function done(failures) {
524
- if (reporter.done) {
525
- reporter.done(failures, fn);
526
- } else {
527
- fn && fn(failures);
528
- }
529
- }
530
-
531
- return runner.run(done);
532
- };