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,216 +1,216 @@
1
- 'use strict';
2
- /**
3
- * @module XUnit
4
- */
5
- /**
6
- * Module dependencies.
7
- */
8
-
9
- var Base = require('./base');
10
- var utils = require('../utils');
11
- var fs = require('fs');
12
- var mkdirp = require('mkdirp');
13
- var path = require('path');
14
- var errors = require('../errors');
15
- var createUnsupportedError = errors.createUnsupportedError;
16
- var constants = require('../runner').constants;
17
- var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
18
- var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
19
- var EVENT_RUN_END = constants.EVENT_RUN_END;
20
- var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
21
- var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
22
- var inherits = utils.inherits;
23
- var escape = utils.escape;
24
-
25
- /**
26
- * Save timer references to avoid Sinon interfering (see GH-237).
27
- */
28
- var Date = global.Date;
29
-
30
- /**
31
- * Expose `XUnit`.
32
- */
33
-
34
- exports = module.exports = XUnit;
35
-
36
- /**
37
- * Constructs a new `XUnit` reporter instance.
38
- *
39
- * @public
40
- * @class
41
- * @memberof Mocha.reporters
42
- * @extends Mocha.reporters.Base
43
- * @param {Runner} runner - Instance triggers reporter actions.
44
- * @param {Object} [options] - runner options
45
- */
46
- function XUnit(runner, options) {
47
- Base.call(this, runner, options);
48
-
49
- var stats = this.stats;
50
- var tests = [];
51
- var self = this;
52
-
53
- // the name of the test suite, as it will appear in the resulting XML file
54
- var suiteName;
55
-
56
- // the default name of the test suite if none is provided
57
- var DEFAULT_SUITE_NAME = 'Mocha Tests';
58
-
59
- if (options && options.reporterOptions) {
60
- if (options.reporterOptions.output) {
61
- if (!fs.createWriteStream) {
62
- throw createUnsupportedError('file output not supported in browser');
63
- }
64
-
65
- mkdirp.sync(path.dirname(options.reporterOptions.output));
66
- self.fileStream = fs.createWriteStream(options.reporterOptions.output);
67
- }
68
-
69
- // get the suite name from the reporter options (if provided)
70
- suiteName = options.reporterOptions.suiteName;
71
- }
72
-
73
- // fall back to the default suite name
74
- suiteName = suiteName || DEFAULT_SUITE_NAME;
75
-
76
- runner.on(EVENT_TEST_PENDING, function(test) {
77
- tests.push(test);
78
- });
79
-
80
- runner.on(EVENT_TEST_PASS, function(test) {
81
- tests.push(test);
82
- });
83
-
84
- runner.on(EVENT_TEST_FAIL, function(test) {
85
- tests.push(test);
86
- });
87
-
88
- runner.once(EVENT_RUN_END, function() {
89
- self.write(
90
- tag(
91
- 'testsuite',
92
- {
93
- name: suiteName,
94
- tests: stats.tests,
95
- failures: 0,
96
- errors: stats.failures,
97
- skipped: stats.tests - stats.failures - stats.passes,
98
- timestamp: new Date().toUTCString(),
99
- time: stats.duration / 1000 || 0
100
- },
101
- false
102
- )
103
- );
104
-
105
- tests.forEach(function(t) {
106
- self.test(t);
107
- });
108
-
109
- self.write('</testsuite>');
110
- });
111
- }
112
-
113
- /**
114
- * Inherit from `Base.prototype`.
115
- */
116
- inherits(XUnit, Base);
117
-
118
- /**
119
- * Override done to close the stream (if it's a file).
120
- *
121
- * @param failures
122
- * @param {Function} fn
123
- */
124
- XUnit.prototype.done = function(failures, fn) {
125
- if (this.fileStream) {
126
- this.fileStream.end(function() {
127
- fn(failures);
128
- });
129
- } else {
130
- fn(failures);
131
- }
132
- };
133
-
134
- /**
135
- * Write out the given line.
136
- *
137
- * @param {string} line
138
- */
139
- XUnit.prototype.write = function(line) {
140
- if (this.fileStream) {
141
- this.fileStream.write(line + '\n');
142
- } else if (typeof process === 'object' && process.stdout) {
143
- process.stdout.write(line + '\n');
144
- } else {
145
- console.log(line);
146
- }
147
- };
148
-
149
- /**
150
- * Output tag for the given `test.`
151
- *
152
- * @param {Test} test
153
- */
154
- XUnit.prototype.test = function(test) {
155
- Base.useColors = false;
156
-
157
- var attrs = {
158
- classname: test.parent.fullTitle(),
159
- name: test.title,
160
- time: test.duration / 1000 || 0
161
- };
162
-
163
- if (test.state === STATE_FAILED) {
164
- var err = test.err;
165
- var diff =
166
- Base.hideDiff || !err.actual || !err.expected
167
- ? ''
168
- : '\n' + Base.generateDiff(err.actual, err.expected);
169
- this.write(
170
- tag(
171
- 'testcase',
172
- attrs,
173
- false,
174
- tag(
175
- 'failure',
176
- {},
177
- false,
178
- escape(err.message) + escape(diff) + '\n' + escape(err.stack)
179
- )
180
- )
181
- );
182
- } else if (test.isPending()) {
183
- this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
184
- } else {
185
- this.write(tag('testcase', attrs, true));
186
- }
187
- };
188
-
189
- /**
190
- * HTML tag helper.
191
- *
192
- * @param name
193
- * @param attrs
194
- * @param close
195
- * @param content
196
- * @return {string}
197
- */
198
- function tag(name, attrs, close, content) {
199
- var end = close ? '/>' : '>';
200
- var pairs = [];
201
- var tag;
202
-
203
- for (var key in attrs) {
204
- if (Object.prototype.hasOwnProperty.call(attrs, key)) {
205
- pairs.push(key + '="' + escape(attrs[key]) + '"');
206
- }
207
- }
208
-
209
- tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
210
- if (content) {
211
- tag += content + '</' + name + end;
212
- }
213
- return tag;
214
- }
215
-
216
- XUnit.description = 'XUnit-compatible XML output';
1
+ 'use strict';
2
+ /**
3
+ * @module XUnit
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var utils = require('../utils');
11
+ var fs = require('fs');
12
+ var mkdirp = require('mkdirp');
13
+ var path = require('path');
14
+ var errors = require('../errors');
15
+ var createUnsupportedError = errors.createUnsupportedError;
16
+ var constants = require('../runner').constants;
17
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
18
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
19
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
20
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
21
+ var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
22
+ var inherits = utils.inherits;
23
+ var escape = utils.escape;
24
+
25
+ /**
26
+ * Save timer references to avoid Sinon interfering (see GH-237).
27
+ */
28
+ var Date = global.Date;
29
+
30
+ /**
31
+ * Expose `XUnit`.
32
+ */
33
+
34
+ exports = module.exports = XUnit;
35
+
36
+ /**
37
+ * Constructs a new `XUnit` reporter instance.
38
+ *
39
+ * @public
40
+ * @class
41
+ * @memberof Mocha.reporters
42
+ * @extends Mocha.reporters.Base
43
+ * @param {Runner} runner - Instance triggers reporter actions.
44
+ * @param {Object} [options] - runner options
45
+ */
46
+ function XUnit(runner, options) {
47
+ Base.call(this, runner, options);
48
+
49
+ var stats = this.stats;
50
+ var tests = [];
51
+ var self = this;
52
+
53
+ // the name of the test suite, as it will appear in the resulting XML file
54
+ var suiteName;
55
+
56
+ // the default name of the test suite if none is provided
57
+ var DEFAULT_SUITE_NAME = 'Mocha Tests';
58
+
59
+ if (options && options.reporterOptions) {
60
+ if (options.reporterOptions.output) {
61
+ if (!fs.createWriteStream) {
62
+ throw createUnsupportedError('file output not supported in browser');
63
+ }
64
+
65
+ mkdirp.sync(path.dirname(options.reporterOptions.output));
66
+ self.fileStream = fs.createWriteStream(options.reporterOptions.output);
67
+ }
68
+
69
+ // get the suite name from the reporter options (if provided)
70
+ suiteName = options.reporterOptions.suiteName;
71
+ }
72
+
73
+ // fall back to the default suite name
74
+ suiteName = suiteName || DEFAULT_SUITE_NAME;
75
+
76
+ runner.on(EVENT_TEST_PENDING, function(test) {
77
+ tests.push(test);
78
+ });
79
+
80
+ runner.on(EVENT_TEST_PASS, function(test) {
81
+ tests.push(test);
82
+ });
83
+
84
+ runner.on(EVENT_TEST_FAIL, function(test) {
85
+ tests.push(test);
86
+ });
87
+
88
+ runner.once(EVENT_RUN_END, function() {
89
+ self.write(
90
+ tag(
91
+ 'testsuite',
92
+ {
93
+ name: suiteName,
94
+ tests: stats.tests,
95
+ failures: 0,
96
+ errors: stats.failures,
97
+ skipped: stats.tests - stats.failures - stats.passes,
98
+ timestamp: new Date().toUTCString(),
99
+ time: stats.duration / 1000 || 0
100
+ },
101
+ false
102
+ )
103
+ );
104
+
105
+ tests.forEach(function(t) {
106
+ self.test(t);
107
+ });
108
+
109
+ self.write('</testsuite>');
110
+ });
111
+ }
112
+
113
+ /**
114
+ * Inherit from `Base.prototype`.
115
+ */
116
+ inherits(XUnit, Base);
117
+
118
+ /**
119
+ * Override done to close the stream (if it's a file).
120
+ *
121
+ * @param failures
122
+ * @param {Function} fn
123
+ */
124
+ XUnit.prototype.done = function(failures, fn) {
125
+ if (this.fileStream) {
126
+ this.fileStream.end(function() {
127
+ fn(failures);
128
+ });
129
+ } else {
130
+ fn(failures);
131
+ }
132
+ };
133
+
134
+ /**
135
+ * Write out the given line.
136
+ *
137
+ * @param {string} line
138
+ */
139
+ XUnit.prototype.write = function(line) {
140
+ if (this.fileStream) {
141
+ this.fileStream.write(line + '\n');
142
+ } else if (typeof process === 'object' && process.stdout) {
143
+ process.stdout.write(line + '\n');
144
+ } else {
145
+ console.log(line);
146
+ }
147
+ };
148
+
149
+ /**
150
+ * Output tag for the given `test.`
151
+ *
152
+ * @param {Test} test
153
+ */
154
+ XUnit.prototype.test = function(test) {
155
+ Base.useColors = false;
156
+
157
+ var attrs = {
158
+ classname: test.parent.fullTitle(),
159
+ name: test.title,
160
+ time: test.duration / 1000 || 0
161
+ };
162
+
163
+ if (test.state === STATE_FAILED) {
164
+ var err = test.err;
165
+ var diff =
166
+ Base.hideDiff || !err.actual || !err.expected
167
+ ? ''
168
+ : '\n' + Base.generateDiff(err.actual, err.expected);
169
+ this.write(
170
+ tag(
171
+ 'testcase',
172
+ attrs,
173
+ false,
174
+ tag(
175
+ 'failure',
176
+ {},
177
+ false,
178
+ escape(err.message) + escape(diff) + '\n' + escape(err.stack)
179
+ )
180
+ )
181
+ );
182
+ } else if (test.isPending()) {
183
+ this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
184
+ } else {
185
+ this.write(tag('testcase', attrs, true));
186
+ }
187
+ };
188
+
189
+ /**
190
+ * HTML tag helper.
191
+ *
192
+ * @param name
193
+ * @param attrs
194
+ * @param close
195
+ * @param content
196
+ * @return {string}
197
+ */
198
+ function tag(name, attrs, close, content) {
199
+ var end = close ? '/>' : '>';
200
+ var pairs = [];
201
+ var tag;
202
+
203
+ for (var key in attrs) {
204
+ if (Object.prototype.hasOwnProperty.call(attrs, key)) {
205
+ pairs.push(key + '="' + escape(attrs[key]) + '"');
206
+ }
207
+ }
208
+
209
+ tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
210
+ if (content) {
211
+ tag += content + '</' + name + end;
212
+ }
213
+ return tag;
214
+ }
215
+
216
+ XUnit.description = 'XUnit-compatible XML output';