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.
Files changed (45) hide show
  1. package/CHANGELOG.md +119 -9
  2. package/bin/_mocha +90 -35
  3. package/bin/options.js +14 -8
  4. package/browser-entry.js +20 -16
  5. package/lib/browser/progress.js +8 -8
  6. package/lib/browser/tty.js +2 -2
  7. package/lib/context.js +11 -9
  8. package/lib/hook.js +7 -9
  9. package/lib/interfaces/bdd.js +12 -13
  10. package/lib/interfaces/common.js +20 -15
  11. package/lib/interfaces/exports.js +2 -7
  12. package/lib/interfaces/qunit.js +6 -10
  13. package/lib/interfaces/tdd.js +7 -11
  14. package/lib/mocha.js +94 -54
  15. package/lib/ms.js +12 -6
  16. package/lib/pending.js +1 -5
  17. package/lib/reporters/base.js +102 -64
  18. package/lib/reporters/doc.js +23 -9
  19. package/lib/reporters/dot.js +14 -8
  20. package/lib/reporters/html.js +81 -41
  21. package/lib/reporters/json-stream.js +16 -9
  22. package/lib/reporters/json.js +47 -12
  23. package/lib/reporters/json.js.orig +128 -0
  24. package/lib/reporters/landing.js +14 -8
  25. package/lib/reporters/list.js +16 -10
  26. package/lib/reporters/markdown.js +18 -12
  27. package/lib/reporters/min.js +9 -3
  28. package/lib/reporters/nyan.js +31 -25
  29. package/lib/reporters/progress.js +13 -7
  30. package/lib/reporters/spec.js +19 -11
  31. package/lib/reporters/tap.js +15 -9
  32. package/lib/reporters/xunit.js +48 -24
  33. package/lib/runnable.js +88 -66
  34. package/lib/runner.js +117 -90
  35. package/lib/suite.js +76 -63
  36. package/lib/test.js +9 -13
  37. package/lib/utils.js +137 -85
  38. package/mocha.js +1914 -1162
  39. package/package.json +462 -299
  40. package/CHANGELOG.md.orig +0 -1736
  41. package/README.md.orig +0 -132
  42. package/bin/.eslintrc.yml +0 -3
  43. package/images/error.png +0 -0
  44. package/images/ok.png +0 -0
  45. package/lib/browser/.eslintrc.yml +0 -4
package/lib/context.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Context
4
+ */
3
5
  /**
4
6
  * Expose `Context`.
5
7
  */
@@ -11,16 +13,16 @@ module.exports = Context;
11
13
  *
12
14
  * @api private
13
15
  */
14
- function Context () {}
16
+ function Context() {}
15
17
 
16
18
  /**
17
19
  * Set or get the context `Runnable` to `runnable`.
18
20
  *
19
21
  * @api private
20
22
  * @param {Runnable} runnable
21
- * @return {Context}
23
+ * @return {Context} context
22
24
  */
23
- Context.prototype.runnable = function (runnable) {
25
+ Context.prototype.runnable = function(runnable) {
24
26
  if (!arguments.length) {
25
27
  return this._runnable;
26
28
  }
@@ -35,7 +37,7 @@ Context.prototype.runnable = function (runnable) {
35
37
  * @param {number} ms
36
38
  * @return {Context} self
37
39
  */
38
- Context.prototype.timeout = function (ms) {
40
+ Context.prototype.timeout = function(ms) {
39
41
  if (!arguments.length) {
40
42
  return this.runnable().timeout();
41
43
  }
@@ -50,7 +52,7 @@ Context.prototype.timeout = function (ms) {
50
52
  * @param {boolean} enabled
51
53
  * @return {Context} self
52
54
  */
53
- Context.prototype.enableTimeouts = function (enabled) {
55
+ Context.prototype.enableTimeouts = function(enabled) {
54
56
  if (!arguments.length) {
55
57
  return this.runnable().enableTimeouts();
56
58
  }
@@ -65,7 +67,7 @@ Context.prototype.enableTimeouts = function (enabled) {
65
67
  * @param {number} ms
66
68
  * @return {Context} self
67
69
  */
68
- Context.prototype.slow = function (ms) {
70
+ Context.prototype.slow = function(ms) {
69
71
  if (!arguments.length) {
70
72
  return this.runnable().slow();
71
73
  }
@@ -79,7 +81,7 @@ Context.prototype.slow = function (ms) {
79
81
  * @api private
80
82
  * @throws Pending
81
83
  */
82
- Context.prototype.skip = function () {
84
+ Context.prototype.skip = function() {
83
85
  this.runnable().skip();
84
86
  };
85
87
 
@@ -90,7 +92,7 @@ Context.prototype.skip = function () {
90
92
  * @param {number} n
91
93
  * @return {Context} self
92
94
  */
93
- Context.prototype.retries = function (n) {
95
+ Context.prototype.retries = function(n) {
94
96
  if (!arguments.length) {
95
97
  return this.runnable().retries();
96
98
  }
package/lib/hook.js CHANGED
@@ -1,9 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
3
  var Runnable = require('./runnable');
8
4
  var inherits = require('./utils').inherits;
9
5
 
@@ -14,13 +10,14 @@ var inherits = require('./utils').inherits;
14
10
  module.exports = Hook;
15
11
 
16
12
  /**
17
- * Initialize a new `Hook` with the given `title` and callback `fn`.
13
+ * Initialize a new `Hook` with the given `title` and callback `fn`
18
14
  *
15
+ * @class
16
+ * @extends Runnable
19
17
  * @param {String} title
20
18
  * @param {Function} fn
21
- * @api private
22
19
  */
23
- function Hook (title, fn) {
20
+ function Hook(title, fn) {
24
21
  Runnable.call(this, title, fn);
25
22
  this.type = 'hook';
26
23
  }
@@ -33,11 +30,12 @@ inherits(Hook, Runnable);
33
30
  /**
34
31
  * Get or set the test `err`.
35
32
  *
33
+ * @memberof Hook
34
+ * @public
36
35
  * @param {Error} err
37
36
  * @return {Error}
38
- * @api public
39
37
  */
40
- Hook.prototype.error = function (err) {
38
+ Hook.prototype.error = function(err) {
41
39
  if (!arguments.length) {
42
40
  err = this._error;
43
41
  this._error = null;
@@ -1,9 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
3
  var Test = require('../test');
8
4
 
9
5
  /**
@@ -23,10 +19,10 @@ var Test = require('../test');
23
19
  *
24
20
  * @param {Suite} suite Root suite.
25
21
  */
26
- module.exports = function (suite) {
22
+ module.exports = function bddInterface(suite) {
27
23
  var suites = [suite];
28
24
 
29
- suite.on('pre-require', function (context, file, mocha) {
25
+ suite.on('pre-require', function(context, file, mocha) {
30
26
  var common = require('./common')(suites, context, mocha);
31
27
 
32
28
  context.before = common.before;
@@ -40,7 +36,7 @@ module.exports = function (suite) {
40
36
  * and/or tests.
41
37
  */
42
38
 
43
- context.describe = context.context = function (title, fn) {
39
+ context.describe = context.context = function(title, fn) {
44
40
  return common.suite.create({
45
41
  title: title,
46
42
  file: file,
@@ -52,7 +48,10 @@ module.exports = function (suite) {
52
48
  * Pending describe.
53
49
  */
54
50
 
55
- context.xdescribe = context.xcontext = context.describe.skip = function (title, fn) {
51
+ context.xdescribe = context.xcontext = context.describe.skip = function(
52
+ title,
53
+ fn
54
+ ) {
56
55
  return common.suite.skip({
57
56
  title: title,
58
57
  file: file,
@@ -64,7 +63,7 @@ module.exports = function (suite) {
64
63
  * Exclusive suite.
65
64
  */
66
65
 
67
- context.describe.only = function (title, fn) {
66
+ context.describe.only = function(title, fn) {
68
67
  return common.suite.only({
69
68
  title: title,
70
69
  file: file,
@@ -78,7 +77,7 @@ module.exports = function (suite) {
78
77
  * acting as a thunk.
79
78
  */
80
79
 
81
- context.it = context.specify = function (title, fn) {
80
+ context.it = context.specify = function(title, fn) {
82
81
  var suite = suites[0];
83
82
  if (suite.isPending()) {
84
83
  fn = null;
@@ -93,7 +92,7 @@ module.exports = function (suite) {
93
92
  * Exclusive test-case.
94
93
  */
95
94
 
96
- context.it.only = function (title, fn) {
95
+ context.it.only = function(title, fn) {
97
96
  return common.test.only(mocha, context.it(title, fn));
98
97
  };
99
98
 
@@ -101,14 +100,14 @@ module.exports = function (suite) {
101
100
  * Pending test case.
102
101
  */
103
102
 
104
- context.xit = context.xspecify = context.it.skip = function (title) {
103
+ context.xit = context.xspecify = context.it.skip = function(title) {
105
104
  return context.it(title);
106
105
  };
107
106
 
108
107
  /**
109
108
  * Number of attempts to retry.
110
109
  */
111
- context.it.retries = function (n) {
110
+ context.it.retries = function(n) {
112
111
  context.retries(n);
113
112
  };
114
113
  });
@@ -10,7 +10,7 @@ var Suite = require('../suite');
10
10
  * @param {Mocha} mocha
11
11
  * @return {Object} An object containing common functions.
12
12
  */
13
- module.exports = function (suites, context, mocha) {
13
+ module.exports = function(suites, context, mocha) {
14
14
  return {
15
15
  /**
16
16
  * This is only present if flag --delay is passed into Mocha. It triggers
@@ -19,8 +19,8 @@ module.exports = function (suites, context, mocha) {
19
19
  * @param {Suite} suite The root suite.
20
20
  * @return {Function} A function which runs the root suite
21
21
  */
22
- runWithSuite: function runWithSuite (suite) {
23
- return function run () {
22
+ runWithSuite: function runWithSuite(suite) {
23
+ return function run() {
24
24
  suite.run();
25
25
  };
26
26
  },
@@ -31,7 +31,7 @@ module.exports = function (suites, context, mocha) {
31
31
  * @param {string} name
32
32
  * @param {Function} fn
33
33
  */
34
- before: function (name, fn) {
34
+ before: function(name, fn) {
35
35
  suites[0].beforeAll(name, fn);
36
36
  },
37
37
 
@@ -41,7 +41,7 @@ module.exports = function (suites, context, mocha) {
41
41
  * @param {string} name
42
42
  * @param {Function} fn
43
43
  */
44
- after: function (name, fn) {
44
+ after: function(name, fn) {
45
45
  suites[0].afterAll(name, fn);
46
46
  },
47
47
 
@@ -51,7 +51,7 @@ module.exports = function (suites, context, mocha) {
51
51
  * @param {string} name
52
52
  * @param {Function} fn
53
53
  */
54
- beforeEach: function (name, fn) {
54
+ beforeEach: function(name, fn) {
55
55
  suites[0].beforeEach(name, fn);
56
56
  },
57
57
 
@@ -61,7 +61,7 @@ module.exports = function (suites, context, mocha) {
61
61
  * @param {string} name
62
62
  * @param {Function} fn
63
63
  */
64
- afterEach: function (name, fn) {
64
+ afterEach: function(name, fn) {
65
65
  suites[0].afterEach(name, fn);
66
66
  },
67
67
 
@@ -73,7 +73,7 @@ module.exports = function (suites, context, mocha) {
73
73
  * @param {Object} opts
74
74
  * @returns {Suite}
75
75
  */
76
- only: function only (opts) {
76
+ only: function only(opts) {
77
77
  opts.isOnly = true;
78
78
  return this.create(opts);
79
79
  },
@@ -85,7 +85,7 @@ module.exports = function (suites, context, mocha) {
85
85
  * @param {Object} opts
86
86
  * @returns {Suite}
87
87
  */
88
- skip: function skip (opts) {
88
+ skip: function skip(opts) {
89
89
  opts.pending = true;
90
90
  return this.create(opts);
91
91
  },
@@ -100,7 +100,7 @@ module.exports = function (suites, context, mocha) {
100
100
  * @param {boolean} [opts.isOnly] Is Suite exclusive?
101
101
  * @returns {Suite}
102
102
  */
103
- create: function create (opts) {
103
+ create: function create(opts) {
104
104
  var suite = Suite.create(suites[0], opts.title);
105
105
  suite.pending = Boolean(opts.pending);
106
106
  suite.file = opts.file;
@@ -112,7 +112,13 @@ module.exports = function (suites, context, mocha) {
112
112
  opts.fn.call(suite);
113
113
  suites.shift();
114
114
  } else if (typeof opts.fn === 'undefined' && !suite.pending) {
115
- throw new Error('Suite "' + suite.fullTitle() + '" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.');
115
+ throw new Error(
116
+ 'Suite "' +
117
+ suite.fullTitle() +
118
+ '" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.'
119
+ );
120
+ } else if (!opts.fn && suite.pending) {
121
+ suites.shift();
116
122
  }
117
123
 
118
124
  return suite;
@@ -120,7 +126,6 @@ module.exports = function (suites, context, mocha) {
120
126
  },
121
127
 
122
128
  test: {
123
-
124
129
  /**
125
130
  * Exclusive test-case.
126
131
  *
@@ -128,7 +133,7 @@ module.exports = function (suites, context, mocha) {
128
133
  * @param {Function} test
129
134
  * @returns {*}
130
135
  */
131
- only: function (mocha, test) {
136
+ only: function(mocha, test) {
132
137
  test.parent._onlyTests = test.parent._onlyTests.concat(test);
133
138
  return test;
134
139
  },
@@ -138,7 +143,7 @@ module.exports = function (suites, context, mocha) {
138
143
  *
139
144
  * @param {string} title
140
145
  */
141
- skip: function (title) {
146
+ skip: function(title) {
142
147
  context.test(title);
143
148
  },
144
149
 
@@ -147,7 +152,7 @@ module.exports = function (suites, context, mocha) {
147
152
  *
148
153
  * @param {number} n
149
154
  */
150
- retries: function (n) {
155
+ retries: function(n) {
151
156
  context.retries(n);
152
157
  }
153
158
  }
@@ -1,9 +1,4 @@
1
1
  'use strict';
2
-
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
2
  var Suite = require('../suite');
8
3
  var Test = require('../test');
9
4
 
@@ -24,12 +19,12 @@ var Test = require('../test');
24
19
  *
25
20
  * @param {Suite} suite Root suite.
26
21
  */
27
- module.exports = function (suite) {
22
+ module.exports = function(suite) {
28
23
  var suites = [suite];
29
24
 
30
25
  suite.on('require', visit);
31
26
 
32
- function visit (obj, file) {
27
+ function visit(obj, file) {
33
28
  var suite;
34
29
  for (var key in obj) {
35
30
  if (typeof obj[key] === 'function') {
@@ -1,9 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
3
  var Test = require('../test');
8
4
 
9
5
  /**
@@ -31,10 +27,10 @@ var Test = require('../test');
31
27
  *
32
28
  * @param {Suite} suite Root suite.
33
29
  */
34
- module.exports = function (suite) {
30
+ module.exports = function qUnitInterface(suite) {
35
31
  var suites = [suite];
36
32
 
37
- suite.on('pre-require', function (context, file, mocha) {
33
+ suite.on('pre-require', function(context, file, mocha) {
38
34
  var common = require('./common')(suites, context, mocha);
39
35
 
40
36
  context.before = common.before;
@@ -46,7 +42,7 @@ module.exports = function (suite) {
46
42
  * Describe a "suite" with the given `title`.
47
43
  */
48
44
 
49
- context.suite = function (title) {
45
+ context.suite = function(title) {
50
46
  if (suites.length > 1) {
51
47
  suites.shift();
52
48
  }
@@ -61,7 +57,7 @@ module.exports = function (suite) {
61
57
  * Exclusive Suite.
62
58
  */
63
59
 
64
- context.suite.only = function (title) {
60
+ context.suite.only = function(title) {
65
61
  if (suites.length > 1) {
66
62
  suites.shift();
67
63
  }
@@ -78,7 +74,7 @@ module.exports = function (suite) {
78
74
  * acting as a thunk.
79
75
  */
80
76
 
81
- context.test = function (title, fn) {
77
+ context.test = function(title, fn) {
82
78
  var test = new Test(title, fn);
83
79
  test.file = file;
84
80
  suites[0].addTest(test);
@@ -89,7 +85,7 @@ module.exports = function (suite) {
89
85
  * Exclusive test-case.
90
86
  */
91
87
 
92
- context.test.only = function (title, fn) {
88
+ context.test.only = function(title, fn) {
93
89
  return common.test.only(mocha, context.test(title, fn));
94
90
  };
95
91
 
@@ -1,9 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
3
  var Test = require('../test');
8
4
 
9
5
  /**
@@ -31,10 +27,10 @@ var Test = require('../test');
31
27
  *
32
28
  * @param {Suite} suite Root suite.
33
29
  */
34
- module.exports = function (suite) {
30
+ module.exports = function(suite) {
35
31
  var suites = [suite];
36
32
 
37
- suite.on('pre-require', function (context, file, mocha) {
33
+ suite.on('pre-require', function(context, file, mocha) {
38
34
  var common = require('./common')(suites, context, mocha);
39
35
 
40
36
  context.setup = common.beforeEach;
@@ -47,7 +43,7 @@ module.exports = function (suite) {
47
43
  * Describe a "suite" with the given `title` and callback `fn` containing
48
44
  * nested suites and/or tests.
49
45
  */
50
- context.suite = function (title, fn) {
46
+ context.suite = function(title, fn) {
51
47
  return common.suite.create({
52
48
  title: title,
53
49
  file: file,
@@ -58,7 +54,7 @@ module.exports = function (suite) {
58
54
  /**
59
55
  * Pending suite.
60
56
  */
61
- context.suite.skip = function (title, fn) {
57
+ context.suite.skip = function(title, fn) {
62
58
  return common.suite.skip({
63
59
  title: title,
64
60
  file: file,
@@ -69,7 +65,7 @@ module.exports = function (suite) {
69
65
  /**
70
66
  * Exclusive test-case.
71
67
  */
72
- context.suite.only = function (title, fn) {
68
+ context.suite.only = function(title, fn) {
73
69
  return common.suite.only({
74
70
  title: title,
75
71
  file: file,
@@ -81,7 +77,7 @@ module.exports = function (suite) {
81
77
  * Describe a specification or test-case with the given `title` and
82
78
  * callback `fn` acting as a thunk.
83
79
  */
84
- context.test = function (title, fn) {
80
+ context.test = function(title, fn) {
85
81
  var suite = suites[0];
86
82
  if (suite.isPending()) {
87
83
  fn = null;
@@ -96,7 +92,7 @@ module.exports = function (suite) {
96
92
  * Exclusive test-case.
97
93
  */
98
94
 
99
- context.test.only = function (title, fn) {
95
+ context.test.only = function(title, fn) {
100
96
  return common.test.only(mocha, context.test(title, fn));
101
97
  };
102
98