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,294 +1,294 @@
1
- 'use strict';
2
- /**
3
- * @module TAP
4
- */
5
- /**
6
- * Module dependencies.
7
- */
8
-
9
- var util = require('util');
10
- var Base = require('./base');
11
- var constants = require('../runner').constants;
12
- var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
13
- var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
14
- var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
15
- var EVENT_RUN_END = constants.EVENT_RUN_END;
16
- var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
17
- var EVENT_TEST_END = constants.EVENT_TEST_END;
18
- var inherits = require('../utils').inherits;
19
- var sprintf = util.format;
20
-
21
- /**
22
- * Expose `TAP`.
23
- */
24
-
25
- exports = module.exports = TAP;
26
-
27
- /**
28
- * Constructs a new `TAP` reporter instance.
29
- *
30
- * @public
31
- * @class
32
- * @memberof Mocha.reporters
33
- * @extends Mocha.reporters.Base
34
- * @param {Runner} runner - Instance triggers reporter actions.
35
- * @param {Object} [options] - runner options
36
- */
37
- function TAP(runner, options) {
38
- Base.call(this, runner, options);
39
-
40
- var self = this;
41
- var n = 1;
42
-
43
- var tapVersion = '12';
44
- if (options && options.reporterOptions) {
45
- if (options.reporterOptions.tapVersion) {
46
- tapVersion = options.reporterOptions.tapVersion.toString();
47
- }
48
- }
49
-
50
- this._producer = createProducer(tapVersion);
51
-
52
- runner.once(EVENT_RUN_BEGIN, function() {
53
- var ntests = runner.grepTotal(runner.suite);
54
- self._producer.writeVersion();
55
- self._producer.writePlan(ntests);
56
- });
57
-
58
- runner.on(EVENT_TEST_END, function() {
59
- ++n;
60
- });
61
-
62
- runner.on(EVENT_TEST_PENDING, function(test) {
63
- self._producer.writePending(n, test);
64
- });
65
-
66
- runner.on(EVENT_TEST_PASS, function(test) {
67
- self._producer.writePass(n, test);
68
- });
69
-
70
- runner.on(EVENT_TEST_FAIL, function(test, err) {
71
- self._producer.writeFail(n, test, err);
72
- });
73
-
74
- runner.once(EVENT_RUN_END, function() {
75
- self._producer.writeEpilogue(runner.stats);
76
- });
77
- }
78
-
79
- /**
80
- * Inherit from `Base.prototype`.
81
- */
82
- inherits(TAP, Base);
83
-
84
- /**
85
- * Returns a TAP-safe title of `test`.
86
- *
87
- * @private
88
- * @param {Test} test - Test instance.
89
- * @return {String} title with any hash character removed
90
- */
91
- function title(test) {
92
- return test.fullTitle().replace(/#/g, '');
93
- }
94
-
95
- /**
96
- * Writes newline-terminated formatted string to reporter output stream.
97
- *
98
- * @private
99
- * @param {string} format - `printf`-like format string
100
- * @param {...*} [varArgs] - Format string arguments
101
- */
102
- function println(format, varArgs) {
103
- var vargs = Array.from(arguments);
104
- vargs[0] += '\n';
105
- process.stdout.write(sprintf.apply(null, vargs));
106
- }
107
-
108
- /**
109
- * Returns a `tapVersion`-appropriate TAP producer instance, if possible.
110
- *
111
- * @private
112
- * @param {string} tapVersion - Version of TAP specification to produce.
113
- * @returns {TAPProducer} specification-appropriate instance
114
- * @throws {Error} if specification version has no associated producer.
115
- */
116
- function createProducer(tapVersion) {
117
- var producers = {
118
- '12': new TAP12Producer(),
119
- '13': new TAP13Producer()
120
- };
121
- var producer = producers[tapVersion];
122
-
123
- if (!producer) {
124
- throw new Error(
125
- 'invalid or unsupported TAP version: ' + JSON.stringify(tapVersion)
126
- );
127
- }
128
-
129
- return producer;
130
- }
131
-
132
- /**
133
- * @summary
134
- * Constructs a new TAPProducer.
135
- *
136
- * @description
137
- * <em>Only</em> to be used as an abstract base class.
138
- *
139
- * @private
140
- * @constructor
141
- */
142
- function TAPProducer() {}
143
-
144
- /**
145
- * Writes the TAP version to reporter output stream.
146
- *
147
- * @abstract
148
- */
149
- TAPProducer.prototype.writeVersion = function() {};
150
-
151
- /**
152
- * Writes the plan to reporter output stream.
153
- *
154
- * @abstract
155
- * @param {number} ntests - Number of tests that are planned to run.
156
- */
157
- TAPProducer.prototype.writePlan = function(ntests) {
158
- println('%d..%d', 1, ntests);
159
- };
160
-
161
- /**
162
- * Writes that test passed to reporter output stream.
163
- *
164
- * @abstract
165
- * @param {number} n - Index of test that passed.
166
- * @param {Test} test - Instance containing test information.
167
- */
168
- TAPProducer.prototype.writePass = function(n, test) {
169
- println('ok %d %s', n, title(test));
170
- };
171
-
172
- /**
173
- * Writes that test was skipped to reporter output stream.
174
- *
175
- * @abstract
176
- * @param {number} n - Index of test that was skipped.
177
- * @param {Test} test - Instance containing test information.
178
- */
179
- TAPProducer.prototype.writePending = function(n, test) {
180
- println('ok %d %s # SKIP -', n, title(test));
181
- };
182
-
183
- /**
184
- * Writes that test failed to reporter output stream.
185
- *
186
- * @abstract
187
- * @param {number} n - Index of test that failed.
188
- * @param {Test} test - Instance containing test information.
189
- * @param {Error} err - Reason the test failed.
190
- */
191
- TAPProducer.prototype.writeFail = function(n, test, err) {
192
- println('not ok %d %s', n, title(test));
193
- };
194
-
195
- /**
196
- * Writes the summary epilogue to reporter output stream.
197
- *
198
- * @abstract
199
- * @param {Object} stats - Object containing run statistics.
200
- */
201
- TAPProducer.prototype.writeEpilogue = function(stats) {
202
- // :TBD: Why is this not counting pending tests?
203
- println('# tests ' + (stats.passes + stats.failures));
204
- println('# pass ' + stats.passes);
205
- // :TBD: Why are we not showing pending results?
206
- println('# fail ' + stats.failures);
207
- };
208
-
209
- /**
210
- * @summary
211
- * Constructs a new TAP12Producer.
212
- *
213
- * @description
214
- * Produces output conforming to the TAP12 specification.
215
- *
216
- * @private
217
- * @constructor
218
- * @extends TAPProducer
219
- * @see {@link https://testanything.org/tap-specification.html|Specification}
220
- */
221
- function TAP12Producer() {
222
- /**
223
- * Writes that test failed to reporter output stream, with error formatting.
224
- * @override
225
- */
226
- this.writeFail = function(n, test, err) {
227
- TAPProducer.prototype.writeFail.call(this, n, test, err);
228
- if (err.message) {
229
- println(err.message.replace(/^/gm, ' '));
230
- }
231
- if (err.stack) {
232
- println(err.stack.replace(/^/gm, ' '));
233
- }
234
- };
235
- }
236
-
237
- /**
238
- * Inherit from `TAPProducer.prototype`.
239
- */
240
- inherits(TAP12Producer, TAPProducer);
241
-
242
- /**
243
- * @summary
244
- * Constructs a new TAP13Producer.
245
- *
246
- * @description
247
- * Produces output conforming to the TAP13 specification.
248
- *
249
- * @private
250
- * @constructor
251
- * @extends TAPProducer
252
- * @see {@link https://testanything.org/tap-version-13-specification.html|Specification}
253
- */
254
- function TAP13Producer() {
255
- /**
256
- * Writes the TAP version to reporter output stream.
257
- * @override
258
- */
259
- this.writeVersion = function() {
260
- println('TAP version 13');
261
- };
262
-
263
- /**
264
- * Writes that test failed to reporter output stream, with error formatting.
265
- * @override
266
- */
267
- this.writeFail = function(n, test, err) {
268
- TAPProducer.prototype.writeFail.call(this, n, test, err);
269
- var emitYamlBlock = err.message != null || err.stack != null;
270
- if (emitYamlBlock) {
271
- println(indent(1) + '---');
272
- if (err.message) {
273
- println(indent(2) + 'message: |-');
274
- println(err.message.replace(/^/gm, indent(3)));
275
- }
276
- if (err.stack) {
277
- println(indent(2) + 'stack: |-');
278
- println(err.stack.replace(/^/gm, indent(3)));
279
- }
280
- println(indent(1) + '...');
281
- }
282
- };
283
-
284
- function indent(level) {
285
- return Array(level + 1).join(' ');
286
- }
287
- }
288
-
289
- /**
290
- * Inherit from `TAPProducer.prototype`.
291
- */
292
- inherits(TAP13Producer, TAPProducer);
293
-
294
- TAP.description = 'TAP-compatible output';
1
+ 'use strict';
2
+ /**
3
+ * @module TAP
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var util = require('util');
10
+ var Base = require('./base');
11
+ var constants = require('../runner').constants;
12
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
13
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
14
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
15
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
16
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
17
+ var EVENT_TEST_END = constants.EVENT_TEST_END;
18
+ var inherits = require('../utils').inherits;
19
+ var sprintf = util.format;
20
+
21
+ /**
22
+ * Expose `TAP`.
23
+ */
24
+
25
+ exports = module.exports = TAP;
26
+
27
+ /**
28
+ * Constructs a new `TAP` reporter instance.
29
+ *
30
+ * @public
31
+ * @class
32
+ * @memberof Mocha.reporters
33
+ * @extends Mocha.reporters.Base
34
+ * @param {Runner} runner - Instance triggers reporter actions.
35
+ * @param {Object} [options] - runner options
36
+ */
37
+ function TAP(runner, options) {
38
+ Base.call(this, runner, options);
39
+
40
+ var self = this;
41
+ var n = 1;
42
+
43
+ var tapVersion = '12';
44
+ if (options && options.reporterOptions) {
45
+ if (options.reporterOptions.tapVersion) {
46
+ tapVersion = options.reporterOptions.tapVersion.toString();
47
+ }
48
+ }
49
+
50
+ this._producer = createProducer(tapVersion);
51
+
52
+ runner.once(EVENT_RUN_BEGIN, function() {
53
+ var ntests = runner.grepTotal(runner.suite);
54
+ self._producer.writeVersion();
55
+ self._producer.writePlan(ntests);
56
+ });
57
+
58
+ runner.on(EVENT_TEST_END, function() {
59
+ ++n;
60
+ });
61
+
62
+ runner.on(EVENT_TEST_PENDING, function(test) {
63
+ self._producer.writePending(n, test);
64
+ });
65
+
66
+ runner.on(EVENT_TEST_PASS, function(test) {
67
+ self._producer.writePass(n, test);
68
+ });
69
+
70
+ runner.on(EVENT_TEST_FAIL, function(test, err) {
71
+ self._producer.writeFail(n, test, err);
72
+ });
73
+
74
+ runner.once(EVENT_RUN_END, function() {
75
+ self._producer.writeEpilogue(runner.stats);
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Inherit from `Base.prototype`.
81
+ */
82
+ inherits(TAP, Base);
83
+
84
+ /**
85
+ * Returns a TAP-safe title of `test`.
86
+ *
87
+ * @private
88
+ * @param {Test} test - Test instance.
89
+ * @return {String} title with any hash character removed
90
+ */
91
+ function title(test) {
92
+ return test.fullTitle().replace(/#/g, '');
93
+ }
94
+
95
+ /**
96
+ * Writes newline-terminated formatted string to reporter output stream.
97
+ *
98
+ * @private
99
+ * @param {string} format - `printf`-like format string
100
+ * @param {...*} [varArgs] - Format string arguments
101
+ */
102
+ function println(format, varArgs) {
103
+ var vargs = Array.from(arguments);
104
+ vargs[0] += '\n';
105
+ process.stdout.write(sprintf.apply(null, vargs));
106
+ }
107
+
108
+ /**
109
+ * Returns a `tapVersion`-appropriate TAP producer instance, if possible.
110
+ *
111
+ * @private
112
+ * @param {string} tapVersion - Version of TAP specification to produce.
113
+ * @returns {TAPProducer} specification-appropriate instance
114
+ * @throws {Error} if specification version has no associated producer.
115
+ */
116
+ function createProducer(tapVersion) {
117
+ var producers = {
118
+ '12': new TAP12Producer(),
119
+ '13': new TAP13Producer()
120
+ };
121
+ var producer = producers[tapVersion];
122
+
123
+ if (!producer) {
124
+ throw new Error(
125
+ 'invalid or unsupported TAP version: ' + JSON.stringify(tapVersion)
126
+ );
127
+ }
128
+
129
+ return producer;
130
+ }
131
+
132
+ /**
133
+ * @summary
134
+ * Constructs a new TAPProducer.
135
+ *
136
+ * @description
137
+ * <em>Only</em> to be used as an abstract base class.
138
+ *
139
+ * @private
140
+ * @constructor
141
+ */
142
+ function TAPProducer() {}
143
+
144
+ /**
145
+ * Writes the TAP version to reporter output stream.
146
+ *
147
+ * @abstract
148
+ */
149
+ TAPProducer.prototype.writeVersion = function() {};
150
+
151
+ /**
152
+ * Writes the plan to reporter output stream.
153
+ *
154
+ * @abstract
155
+ * @param {number} ntests - Number of tests that are planned to run.
156
+ */
157
+ TAPProducer.prototype.writePlan = function(ntests) {
158
+ println('%d..%d', 1, ntests);
159
+ };
160
+
161
+ /**
162
+ * Writes that test passed to reporter output stream.
163
+ *
164
+ * @abstract
165
+ * @param {number} n - Index of test that passed.
166
+ * @param {Test} test - Instance containing test information.
167
+ */
168
+ TAPProducer.prototype.writePass = function(n, test) {
169
+ println('ok %d %s', n, title(test));
170
+ };
171
+
172
+ /**
173
+ * Writes that test was skipped to reporter output stream.
174
+ *
175
+ * @abstract
176
+ * @param {number} n - Index of test that was skipped.
177
+ * @param {Test} test - Instance containing test information.
178
+ */
179
+ TAPProducer.prototype.writePending = function(n, test) {
180
+ println('ok %d %s # SKIP -', n, title(test));
181
+ };
182
+
183
+ /**
184
+ * Writes that test failed to reporter output stream.
185
+ *
186
+ * @abstract
187
+ * @param {number} n - Index of test that failed.
188
+ * @param {Test} test - Instance containing test information.
189
+ * @param {Error} err - Reason the test failed.
190
+ */
191
+ TAPProducer.prototype.writeFail = function(n, test, err) {
192
+ println('not ok %d %s', n, title(test));
193
+ };
194
+
195
+ /**
196
+ * Writes the summary epilogue to reporter output stream.
197
+ *
198
+ * @abstract
199
+ * @param {Object} stats - Object containing run statistics.
200
+ */
201
+ TAPProducer.prototype.writeEpilogue = function(stats) {
202
+ // :TBD: Why is this not counting pending tests?
203
+ println('# tests ' + (stats.passes + stats.failures));
204
+ println('# pass ' + stats.passes);
205
+ // :TBD: Why are we not showing pending results?
206
+ println('# fail ' + stats.failures);
207
+ };
208
+
209
+ /**
210
+ * @summary
211
+ * Constructs a new TAP12Producer.
212
+ *
213
+ * @description
214
+ * Produces output conforming to the TAP12 specification.
215
+ *
216
+ * @private
217
+ * @constructor
218
+ * @extends TAPProducer
219
+ * @see {@link https://testanything.org/tap-specification.html|Specification}
220
+ */
221
+ function TAP12Producer() {
222
+ /**
223
+ * Writes that test failed to reporter output stream, with error formatting.
224
+ * @override
225
+ */
226
+ this.writeFail = function(n, test, err) {
227
+ TAPProducer.prototype.writeFail.call(this, n, test, err);
228
+ if (err.message) {
229
+ println(err.message.replace(/^/gm, ' '));
230
+ }
231
+ if (err.stack) {
232
+ println(err.stack.replace(/^/gm, ' '));
233
+ }
234
+ };
235
+ }
236
+
237
+ /**
238
+ * Inherit from `TAPProducer.prototype`.
239
+ */
240
+ inherits(TAP12Producer, TAPProducer);
241
+
242
+ /**
243
+ * @summary
244
+ * Constructs a new TAP13Producer.
245
+ *
246
+ * @description
247
+ * Produces output conforming to the TAP13 specification.
248
+ *
249
+ * @private
250
+ * @constructor
251
+ * @extends TAPProducer
252
+ * @see {@link https://testanything.org/tap-version-13-specification.html|Specification}
253
+ */
254
+ function TAP13Producer() {
255
+ /**
256
+ * Writes the TAP version to reporter output stream.
257
+ * @override
258
+ */
259
+ this.writeVersion = function() {
260
+ println('TAP version 13');
261
+ };
262
+
263
+ /**
264
+ * Writes that test failed to reporter output stream, with error formatting.
265
+ * @override
266
+ */
267
+ this.writeFail = function(n, test, err) {
268
+ TAPProducer.prototype.writeFail.call(this, n, test, err);
269
+ var emitYamlBlock = err.message != null || err.stack != null;
270
+ if (emitYamlBlock) {
271
+ println(indent(1) + '---');
272
+ if (err.message) {
273
+ println(indent(2) + 'message: |-');
274
+ println(err.message.replace(/^/gm, indent(3)));
275
+ }
276
+ if (err.stack) {
277
+ println(indent(2) + 'stack: |-');
278
+ println(err.stack.replace(/^/gm, indent(3)));
279
+ }
280
+ println(indent(1) + '...');
281
+ }
282
+ };
283
+
284
+ function indent(level) {
285
+ return Array(level + 1).join(' ');
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Inherit from `TAPProducer.prototype`.
291
+ */
292
+ inherits(TAP13Producer, TAPProducer);
293
+
294
+ TAP.description = 'TAP-compatible output';