mocha 6.1.0 → 6.1.4

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 (61) hide show
  1. package/CHANGELOG.md +1776 -1751
  2. package/LICENSE +22 -22
  3. package/README.md +105 -105
  4. package/bin/_mocha +10 -10
  5. package/bin/mocha +149 -149
  6. package/bin/options.js +10 -10
  7. package/browser-entry.js +191 -191
  8. package/index.js +3 -3
  9. package/lib/browser/growl.js +168 -168
  10. package/lib/browser/progress.js +119 -119
  11. package/lib/browser/template.html +18 -18
  12. package/lib/browser/tty.js +13 -13
  13. package/lib/cli/cli.js +69 -69
  14. package/lib/cli/commands.js +13 -13
  15. package/lib/cli/config.js +101 -101
  16. package/lib/cli/index.js +9 -9
  17. package/lib/cli/init.js +37 -37
  18. package/lib/cli/node-flags.js +86 -86
  19. package/lib/cli/one-and-dones.js +70 -70
  20. package/lib/cli/options.js +347 -347
  21. package/lib/cli/run-helpers.js +337 -337
  22. package/lib/cli/run-option-metadata.js +76 -76
  23. package/lib/cli/run.js +297 -297
  24. package/lib/context.js +101 -101
  25. package/lib/errors.js +141 -141
  26. package/lib/growl.js +136 -136
  27. package/lib/hook.js +46 -46
  28. package/lib/interfaces/bdd.js +118 -118
  29. package/lib/interfaces/common.js +191 -191
  30. package/lib/interfaces/exports.js +60 -60
  31. package/lib/interfaces/index.js +6 -6
  32. package/lib/interfaces/qunit.js +99 -99
  33. package/lib/interfaces/tdd.js +107 -107
  34. package/lib/mocha.js +843 -843
  35. package/lib/mocharc.json +10 -10
  36. package/lib/pending.js +12 -12
  37. package/lib/reporters/base.js +491 -491
  38. package/lib/reporters/doc.js +85 -85
  39. package/lib/reporters/dot.js +81 -81
  40. package/lib/reporters/html.js +390 -390
  41. package/lib/reporters/index.js +19 -19
  42. package/lib/reporters/json-stream.js +90 -90
  43. package/lib/reporters/json.js +135 -135
  44. package/lib/reporters/landing.js +108 -108
  45. package/lib/reporters/list.js +78 -78
  46. package/lib/reporters/markdown.js +112 -112
  47. package/lib/reporters/min.js +52 -52
  48. package/lib/reporters/nyan.js +276 -276
  49. package/lib/reporters/progress.js +104 -104
  50. package/lib/reporters/spec.js +99 -99
  51. package/lib/reporters/tap.js +294 -294
  52. package/lib/reporters/xunit.js +216 -216
  53. package/lib/runnable.js +496 -496
  54. package/lib/runner.js +1049 -1049
  55. package/lib/stats-collector.js +83 -83
  56. package/lib/suite.js +642 -642
  57. package/lib/test.js +51 -51
  58. package/lib/utils.js +897 -897
  59. package/mocha.css +326 -326
  60. package/mocha.js +8170 -8476
  61. package/package.json +630 -628
@@ -1,191 +1,191 @@
1
- 'use strict';
2
-
3
- var Suite = require('../suite');
4
- var errors = require('../errors');
5
- var createMissingArgumentError = errors.createMissingArgumentError;
6
-
7
- /**
8
- * Functions common to more than one interface.
9
- *
10
- * @param {Suite[]} suites
11
- * @param {Context} context
12
- * @param {Mocha} mocha
13
- * @return {Object} An object containing common functions.
14
- */
15
- module.exports = function(suites, context, mocha) {
16
- /**
17
- * Check if the suite should be tested.
18
- *
19
- * @private
20
- * @param {Suite} suite - suite to check
21
- * @returns {boolean}
22
- */
23
- function shouldBeTested(suite) {
24
- return (
25
- !mocha.options.grep ||
26
- (mocha.options.grep &&
27
- mocha.options.grep.test(suite.fullTitle()) &&
28
- !mocha.options.invert)
29
- );
30
- }
31
-
32
- return {
33
- /**
34
- * This is only present if flag --delay is passed into Mocha. It triggers
35
- * root suite execution.
36
- *
37
- * @param {Suite} suite The root suite.
38
- * @return {Function} A function which runs the root suite
39
- */
40
- runWithSuite: function runWithSuite(suite) {
41
- return function run() {
42
- suite.run();
43
- };
44
- },
45
-
46
- /**
47
- * Execute before running tests.
48
- *
49
- * @param {string} name
50
- * @param {Function} fn
51
- */
52
- before: function(name, fn) {
53
- suites[0].beforeAll(name, fn);
54
- },
55
-
56
- /**
57
- * Execute after running tests.
58
- *
59
- * @param {string} name
60
- * @param {Function} fn
61
- */
62
- after: function(name, fn) {
63
- suites[0].afterAll(name, fn);
64
- },
65
-
66
- /**
67
- * Execute before each test case.
68
- *
69
- * @param {string} name
70
- * @param {Function} fn
71
- */
72
- beforeEach: function(name, fn) {
73
- suites[0].beforeEach(name, fn);
74
- },
75
-
76
- /**
77
- * Execute after each test case.
78
- *
79
- * @param {string} name
80
- * @param {Function} fn
81
- */
82
- afterEach: function(name, fn) {
83
- suites[0].afterEach(name, fn);
84
- },
85
-
86
- suite: {
87
- /**
88
- * Create an exclusive Suite; convenience function
89
- * See docstring for create() below.
90
- *
91
- * @param {Object} opts
92
- * @returns {Suite}
93
- */
94
- only: function only(opts) {
95
- opts.isOnly = true;
96
- return this.create(opts);
97
- },
98
-
99
- /**
100
- * Create a Suite, but skip it; convenience function
101
- * See docstring for create() below.
102
- *
103
- * @param {Object} opts
104
- * @returns {Suite}
105
- */
106
- skip: function skip(opts) {
107
- opts.pending = true;
108
- return this.create(opts);
109
- },
110
-
111
- /**
112
- * Creates a suite.
113
- *
114
- * @param {Object} opts Options
115
- * @param {string} opts.title Title of Suite
116
- * @param {Function} [opts.fn] Suite Function (not always applicable)
117
- * @param {boolean} [opts.pending] Is Suite pending?
118
- * @param {string} [opts.file] Filepath where this Suite resides
119
- * @param {boolean} [opts.isOnly] Is Suite exclusive?
120
- * @returns {Suite}
121
- */
122
- create: function create(opts) {
123
- var suite = Suite.create(suites[0], opts.title);
124
- suite.pending = Boolean(opts.pending);
125
- suite.file = opts.file;
126
- suites.unshift(suite);
127
- if (opts.isOnly) {
128
- if (mocha.options.forbidOnly && shouldBeTested(suite)) {
129
- throw new Error('`.only` forbidden');
130
- }
131
-
132
- suite.parent.appendOnlySuite(suite);
133
- }
134
- if (suite.pending) {
135
- if (mocha.options.forbidPending && shouldBeTested(suite)) {
136
- throw new Error('Pending test forbidden');
137
- }
138
- }
139
- if (typeof opts.fn === 'function') {
140
- opts.fn.call(suite);
141
- suites.shift();
142
- } else if (typeof opts.fn === 'undefined' && !suite.pending) {
143
- throw createMissingArgumentError(
144
- 'Suite "' +
145
- suite.fullTitle() +
146
- '" was defined but no callback was supplied. ' +
147
- 'Supply a callback or explicitly skip the suite.',
148
- 'callback',
149
- 'function'
150
- );
151
- } else if (!opts.fn && suite.pending) {
152
- suites.shift();
153
- }
154
-
155
- return suite;
156
- }
157
- },
158
-
159
- test: {
160
- /**
161
- * Exclusive test-case.
162
- *
163
- * @param {Object} mocha
164
- * @param {Function} test
165
- * @returns {*}
166
- */
167
- only: function(mocha, test) {
168
- test.parent.appendOnlyTest(test);
169
- return test;
170
- },
171
-
172
- /**
173
- * Pending test case.
174
- *
175
- * @param {string} title
176
- */
177
- skip: function(title) {
178
- context.test(title);
179
- },
180
-
181
- /**
182
- * Number of retry attempts
183
- *
184
- * @param {number} n
185
- */
186
- retries: function(n) {
187
- context.retries(n);
188
- }
189
- }
190
- };
191
- };
1
+ 'use strict';
2
+
3
+ var Suite = require('../suite');
4
+ var errors = require('../errors');
5
+ var createMissingArgumentError = errors.createMissingArgumentError;
6
+
7
+ /**
8
+ * Functions common to more than one interface.
9
+ *
10
+ * @param {Suite[]} suites
11
+ * @param {Context} context
12
+ * @param {Mocha} mocha
13
+ * @return {Object} An object containing common functions.
14
+ */
15
+ module.exports = function(suites, context, mocha) {
16
+ /**
17
+ * Check if the suite should be tested.
18
+ *
19
+ * @private
20
+ * @param {Suite} suite - suite to check
21
+ * @returns {boolean}
22
+ */
23
+ function shouldBeTested(suite) {
24
+ return (
25
+ !mocha.options.grep ||
26
+ (mocha.options.grep &&
27
+ mocha.options.grep.test(suite.fullTitle()) &&
28
+ !mocha.options.invert)
29
+ );
30
+ }
31
+
32
+ return {
33
+ /**
34
+ * This is only present if flag --delay is passed into Mocha. It triggers
35
+ * root suite execution.
36
+ *
37
+ * @param {Suite} suite The root suite.
38
+ * @return {Function} A function which runs the root suite
39
+ */
40
+ runWithSuite: function runWithSuite(suite) {
41
+ return function run() {
42
+ suite.run();
43
+ };
44
+ },
45
+
46
+ /**
47
+ * Execute before running tests.
48
+ *
49
+ * @param {string} name
50
+ * @param {Function} fn
51
+ */
52
+ before: function(name, fn) {
53
+ suites[0].beforeAll(name, fn);
54
+ },
55
+
56
+ /**
57
+ * Execute after running tests.
58
+ *
59
+ * @param {string} name
60
+ * @param {Function} fn
61
+ */
62
+ after: function(name, fn) {
63
+ suites[0].afterAll(name, fn);
64
+ },
65
+
66
+ /**
67
+ * Execute before each test case.
68
+ *
69
+ * @param {string} name
70
+ * @param {Function} fn
71
+ */
72
+ beforeEach: function(name, fn) {
73
+ suites[0].beforeEach(name, fn);
74
+ },
75
+
76
+ /**
77
+ * Execute after each test case.
78
+ *
79
+ * @param {string} name
80
+ * @param {Function} fn
81
+ */
82
+ afterEach: function(name, fn) {
83
+ suites[0].afterEach(name, fn);
84
+ },
85
+
86
+ suite: {
87
+ /**
88
+ * Create an exclusive Suite; convenience function
89
+ * See docstring for create() below.
90
+ *
91
+ * @param {Object} opts
92
+ * @returns {Suite}
93
+ */
94
+ only: function only(opts) {
95
+ opts.isOnly = true;
96
+ return this.create(opts);
97
+ },
98
+
99
+ /**
100
+ * Create a Suite, but skip it; convenience function
101
+ * See docstring for create() below.
102
+ *
103
+ * @param {Object} opts
104
+ * @returns {Suite}
105
+ */
106
+ skip: function skip(opts) {
107
+ opts.pending = true;
108
+ return this.create(opts);
109
+ },
110
+
111
+ /**
112
+ * Creates a suite.
113
+ *
114
+ * @param {Object} opts Options
115
+ * @param {string} opts.title Title of Suite
116
+ * @param {Function} [opts.fn] Suite Function (not always applicable)
117
+ * @param {boolean} [opts.pending] Is Suite pending?
118
+ * @param {string} [opts.file] Filepath where this Suite resides
119
+ * @param {boolean} [opts.isOnly] Is Suite exclusive?
120
+ * @returns {Suite}
121
+ */
122
+ create: function create(opts) {
123
+ var suite = Suite.create(suites[0], opts.title);
124
+ suite.pending = Boolean(opts.pending);
125
+ suite.file = opts.file;
126
+ suites.unshift(suite);
127
+ if (opts.isOnly) {
128
+ if (mocha.options.forbidOnly && shouldBeTested(suite)) {
129
+ throw new Error('`.only` forbidden');
130
+ }
131
+
132
+ suite.parent.appendOnlySuite(suite);
133
+ }
134
+ if (suite.pending) {
135
+ if (mocha.options.forbidPending && shouldBeTested(suite)) {
136
+ throw new Error('Pending test forbidden');
137
+ }
138
+ }
139
+ if (typeof opts.fn === 'function') {
140
+ opts.fn.call(suite);
141
+ suites.shift();
142
+ } else if (typeof opts.fn === 'undefined' && !suite.pending) {
143
+ throw createMissingArgumentError(
144
+ 'Suite "' +
145
+ suite.fullTitle() +
146
+ '" was defined but no callback was supplied. ' +
147
+ 'Supply a callback or explicitly skip the suite.',
148
+ 'callback',
149
+ 'function'
150
+ );
151
+ } else if (!opts.fn && suite.pending) {
152
+ suites.shift();
153
+ }
154
+
155
+ return suite;
156
+ }
157
+ },
158
+
159
+ test: {
160
+ /**
161
+ * Exclusive test-case.
162
+ *
163
+ * @param {Object} mocha
164
+ * @param {Function} test
165
+ * @returns {*}
166
+ */
167
+ only: function(mocha, test) {
168
+ test.parent.appendOnlyTest(test);
169
+ return test;
170
+ },
171
+
172
+ /**
173
+ * Pending test case.
174
+ *
175
+ * @param {string} title
176
+ */
177
+ skip: function(title) {
178
+ context.test(title);
179
+ },
180
+
181
+ /**
182
+ * Number of retry attempts
183
+ *
184
+ * @param {number} n
185
+ */
186
+ retries: function(n) {
187
+ context.retries(n);
188
+ }
189
+ }
190
+ };
191
+ };
@@ -1,60 +1,60 @@
1
- 'use strict';
2
- var Suite = require('../suite');
3
- var Test = require('../test');
4
-
5
- /**
6
- * Exports-style (as Node.js module) interface:
7
- *
8
- * exports.Array = {
9
- * '#indexOf()': {
10
- * 'should return -1 when the value is not present': function() {
11
- *
12
- * },
13
- *
14
- * 'should return the correct index when the value is present': function() {
15
- *
16
- * }
17
- * }
18
- * };
19
- *
20
- * @param {Suite} suite Root suite.
21
- */
22
- module.exports = function(suite) {
23
- var suites = [suite];
24
-
25
- suite.on(Suite.constants.EVENT_FILE_REQUIRE, visit);
26
-
27
- function visit(obj, file) {
28
- var suite;
29
- for (var key in obj) {
30
- if (typeof obj[key] === 'function') {
31
- var fn = obj[key];
32
- switch (key) {
33
- case 'before':
34
- suites[0].beforeAll(fn);
35
- break;
36
- case 'after':
37
- suites[0].afterAll(fn);
38
- break;
39
- case 'beforeEach':
40
- suites[0].beforeEach(fn);
41
- break;
42
- case 'afterEach':
43
- suites[0].afterEach(fn);
44
- break;
45
- default:
46
- var test = new Test(key, fn);
47
- test.file = file;
48
- suites[0].addTest(test);
49
- }
50
- } else {
51
- suite = Suite.create(suites[0], key);
52
- suites.unshift(suite);
53
- visit(obj[key], file);
54
- suites.shift();
55
- }
56
- }
57
- }
58
- };
59
-
60
- module.exports.description = 'Node.js module ("exports") style';
1
+ 'use strict';
2
+ var Suite = require('../suite');
3
+ var Test = require('../test');
4
+
5
+ /**
6
+ * Exports-style (as Node.js module) interface:
7
+ *
8
+ * exports.Array = {
9
+ * '#indexOf()': {
10
+ * 'should return -1 when the value is not present': function() {
11
+ *
12
+ * },
13
+ *
14
+ * 'should return the correct index when the value is present': function() {
15
+ *
16
+ * }
17
+ * }
18
+ * };
19
+ *
20
+ * @param {Suite} suite Root suite.
21
+ */
22
+ module.exports = function(suite) {
23
+ var suites = [suite];
24
+
25
+ suite.on(Suite.constants.EVENT_FILE_REQUIRE, visit);
26
+
27
+ function visit(obj, file) {
28
+ var suite;
29
+ for (var key in obj) {
30
+ if (typeof obj[key] === 'function') {
31
+ var fn = obj[key];
32
+ switch (key) {
33
+ case 'before':
34
+ suites[0].beforeAll(fn);
35
+ break;
36
+ case 'after':
37
+ suites[0].afterAll(fn);
38
+ break;
39
+ case 'beforeEach':
40
+ suites[0].beforeEach(fn);
41
+ break;
42
+ case 'afterEach':
43
+ suites[0].afterEach(fn);
44
+ break;
45
+ default:
46
+ var test = new Test(key, fn);
47
+ test.file = file;
48
+ suites[0].addTest(test);
49
+ }
50
+ } else {
51
+ suite = Suite.create(suites[0], key);
52
+ suites.unshift(suite);
53
+ visit(obj[key], file);
54
+ suites.shift();
55
+ }
56
+ }
57
+ }
58
+ };
59
+
60
+ module.exports.description = 'Node.js module ("exports") style';
@@ -1,6 +1,6 @@
1
- 'use strict';
2
-
3
- exports.bdd = require('./bdd');
4
- exports.tdd = require('./tdd');
5
- exports.qunit = require('./qunit');
6
- exports.exports = require('./exports');
1
+ 'use strict';
2
+
3
+ exports.bdd = require('./bdd');
4
+ exports.tdd = require('./tdd');
5
+ exports.qunit = require('./qunit');
6
+ exports.exports = require('./exports');