mocha 9.1.2

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 (76) hide show
  1. package/CHANGELOG.md +1015 -0
  2. package/LICENSE +22 -0
  3. package/README.md +70 -0
  4. package/assets/growl/error.png +0 -0
  5. package/assets/growl/ok.png +0 -0
  6. package/bin/_mocha +10 -0
  7. package/bin/mocha +142 -0
  8. package/browser-entry.js +216 -0
  9. package/index.js +3 -0
  10. package/lib/browser/growl.js +169 -0
  11. package/lib/browser/highlight-tags.js +39 -0
  12. package/lib/browser/parse-query.js +24 -0
  13. package/lib/browser/progress.js +123 -0
  14. package/lib/browser/template.html +20 -0
  15. package/lib/cli/cli.js +89 -0
  16. package/lib/cli/collect-files.js +92 -0
  17. package/lib/cli/commands.js +13 -0
  18. package/lib/cli/config.js +105 -0
  19. package/lib/cli/index.js +3 -0
  20. package/lib/cli/init.js +36 -0
  21. package/lib/cli/lookup-files.js +145 -0
  22. package/lib/cli/node-flags.js +85 -0
  23. package/lib/cli/one-and-dones.js +69 -0
  24. package/lib/cli/options.js +261 -0
  25. package/lib/cli/run-helpers.js +243 -0
  26. package/lib/cli/run-option-metadata.js +117 -0
  27. package/lib/cli/run.js +379 -0
  28. package/lib/cli/watch-run.js +380 -0
  29. package/lib/context.js +86 -0
  30. package/lib/errors.js +563 -0
  31. package/lib/hook.js +89 -0
  32. package/lib/interfaces/bdd.js +111 -0
  33. package/lib/interfaces/common.js +193 -0
  34. package/lib/interfaces/exports.js +60 -0
  35. package/lib/interfaces/index.js +6 -0
  36. package/lib/interfaces/qunit.js +98 -0
  37. package/lib/interfaces/tdd.js +106 -0
  38. package/lib/mocha.js +1374 -0
  39. package/lib/mocharc.json +10 -0
  40. package/lib/nodejs/buffered-worker-pool.js +172 -0
  41. package/lib/nodejs/esm-utils.js +109 -0
  42. package/lib/nodejs/file-unloader.js +15 -0
  43. package/lib/nodejs/growl.js +137 -0
  44. package/lib/nodejs/parallel-buffered-runner.js +433 -0
  45. package/lib/nodejs/reporters/parallel-buffered.js +165 -0
  46. package/lib/nodejs/serializer.js +412 -0
  47. package/lib/nodejs/worker.js +151 -0
  48. package/lib/pending.js +16 -0
  49. package/lib/plugin-loader.js +286 -0
  50. package/lib/reporters/base.js +537 -0
  51. package/lib/reporters/doc.js +95 -0
  52. package/lib/reporters/dot.js +81 -0
  53. package/lib/reporters/html.js +390 -0
  54. package/lib/reporters/index.js +19 -0
  55. package/lib/reporters/json-stream.js +92 -0
  56. package/lib/reporters/json.js +162 -0
  57. package/lib/reporters/landing.js +116 -0
  58. package/lib/reporters/list.js +78 -0
  59. package/lib/reporters/markdown.js +112 -0
  60. package/lib/reporters/min.js +52 -0
  61. package/lib/reporters/nyan.js +276 -0
  62. package/lib/reporters/progress.js +104 -0
  63. package/lib/reporters/spec.js +99 -0
  64. package/lib/reporters/tap.js +293 -0
  65. package/lib/reporters/xunit.js +217 -0
  66. package/lib/runnable.js +476 -0
  67. package/lib/runner.js +1269 -0
  68. package/lib/stats-collector.js +83 -0
  69. package/lib/suite.js +695 -0
  70. package/lib/test.js +113 -0
  71. package/lib/utils.js +641 -0
  72. package/mocha-es2018.js +19816 -0
  73. package/mocha.css +325 -0
  74. package/mocha.js +30844 -0
  75. package/mocha.js.map +1 -0
  76. package/package.json +200 -0
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+ /**
3
+ * @module Landing
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var inherits = require('../utils').inherits;
11
+ var constants = require('../runner').constants;
12
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
13
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
14
+ var EVENT_TEST_END = constants.EVENT_TEST_END;
15
+ var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
16
+
17
+ var cursor = Base.cursor;
18
+ var color = Base.color;
19
+
20
+ /**
21
+ * Expose `Landing`.
22
+ */
23
+
24
+ exports = module.exports = Landing;
25
+
26
+ /**
27
+ * Airplane color.
28
+ */
29
+
30
+ Base.colors.plane = 0;
31
+
32
+ /**
33
+ * Airplane crash color.
34
+ */
35
+
36
+ Base.colors['plane crash'] = 31;
37
+
38
+ /**
39
+ * Runway color.
40
+ */
41
+
42
+ Base.colors.runway = 90;
43
+
44
+ /**
45
+ * Constructs a new `Landing` reporter instance.
46
+ *
47
+ * @public
48
+ * @class
49
+ * @memberof Mocha.reporters
50
+ * @extends Mocha.reporters.Base
51
+ * @param {Runner} runner - Instance triggers reporter actions.
52
+ * @param {Object} [options] - runner options
53
+ */
54
+ function Landing(runner, options) {
55
+ Base.call(this, runner, options);
56
+
57
+ var self = this;
58
+ var width = (Base.window.width * 0.75) | 0;
59
+ var stream = process.stdout;
60
+
61
+ var plane = color('plane', '✈');
62
+ var crashed = -1;
63
+ var n = 0;
64
+ var total = 0;
65
+
66
+ function runway() {
67
+ var buf = Array(width).join('-');
68
+ return ' ' + color('runway', buf);
69
+ }
70
+
71
+ runner.on(EVENT_RUN_BEGIN, function() {
72
+ stream.write('\n\n\n ');
73
+ cursor.hide();
74
+ });
75
+
76
+ runner.on(EVENT_TEST_END, function(test) {
77
+ // check if the plane crashed
78
+ var col = crashed === -1 ? ((width * ++n) / ++total) | 0 : crashed;
79
+ // show the crash
80
+ if (test.state === STATE_FAILED) {
81
+ plane = color('plane crash', '✈');
82
+ crashed = col;
83
+ }
84
+
85
+ // render landing strip
86
+ stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
87
+ stream.write(runway());
88
+ stream.write('\n ');
89
+ stream.write(color('runway', Array(col).join('⋅')));
90
+ stream.write(plane);
91
+ stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
92
+ stream.write(runway());
93
+ stream.write('\u001b[0m');
94
+ });
95
+
96
+ runner.once(EVENT_RUN_END, function() {
97
+ cursor.show();
98
+ process.stdout.write('\n');
99
+ self.epilogue();
100
+ });
101
+
102
+ // if cursor is hidden when we ctrl-C, then it will remain hidden unless...
103
+ process.once('SIGINT', function() {
104
+ cursor.show();
105
+ process.nextTick(function() {
106
+ process.kill(process.pid, 'SIGINT');
107
+ });
108
+ });
109
+ }
110
+
111
+ /**
112
+ * Inherit from `Base.prototype`.
113
+ */
114
+ inherits(Landing, Base);
115
+
116
+ Landing.description = 'Unicode landing strip';
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+ /**
3
+ * @module List
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var inherits = require('../utils').inherits;
11
+ var constants = require('../runner').constants;
12
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
13
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
14
+ var EVENT_TEST_BEGIN = constants.EVENT_TEST_BEGIN;
15
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
16
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
17
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
18
+ var color = Base.color;
19
+ var cursor = Base.cursor;
20
+
21
+ /**
22
+ * Expose `List`.
23
+ */
24
+
25
+ exports = module.exports = List;
26
+
27
+ /**
28
+ * Constructs a new `List` 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 List(runner, options) {
38
+ Base.call(this, runner, options);
39
+
40
+ var self = this;
41
+ var n = 0;
42
+
43
+ runner.on(EVENT_RUN_BEGIN, function() {
44
+ Base.consoleLog();
45
+ });
46
+
47
+ runner.on(EVENT_TEST_BEGIN, function(test) {
48
+ process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
49
+ });
50
+
51
+ runner.on(EVENT_TEST_PENDING, function(test) {
52
+ var fmt = color('checkmark', ' -') + color('pending', ' %s');
53
+ Base.consoleLog(fmt, test.fullTitle());
54
+ });
55
+
56
+ runner.on(EVENT_TEST_PASS, function(test) {
57
+ var fmt =
58
+ color('checkmark', ' ' + Base.symbols.ok) +
59
+ color('pass', ' %s: ') +
60
+ color(test.speed, '%dms');
61
+ cursor.CR();
62
+ Base.consoleLog(fmt, test.fullTitle(), test.duration);
63
+ });
64
+
65
+ runner.on(EVENT_TEST_FAIL, function(test) {
66
+ cursor.CR();
67
+ Base.consoleLog(color('fail', ' %d) %s'), ++n, test.fullTitle());
68
+ });
69
+
70
+ runner.once(EVENT_RUN_END, self.epilogue.bind(self));
71
+ }
72
+
73
+ /**
74
+ * Inherit from `Base.prototype`.
75
+ */
76
+ inherits(List, Base);
77
+
78
+ List.description = 'like "spec" reporter but flat';
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+ /**
3
+ * @module Markdown
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var utils = require('../utils');
11
+ var constants = require('../runner').constants;
12
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
13
+ var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
14
+ var EVENT_SUITE_END = constants.EVENT_SUITE_END;
15
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
16
+
17
+ /**
18
+ * Constants
19
+ */
20
+
21
+ var SUITE_PREFIX = '$';
22
+
23
+ /**
24
+ * Expose `Markdown`.
25
+ */
26
+
27
+ exports = module.exports = Markdown;
28
+
29
+ /**
30
+ * Constructs a new `Markdown` reporter instance.
31
+ *
32
+ * @public
33
+ * @class
34
+ * @memberof Mocha.reporters
35
+ * @extends Mocha.reporters.Base
36
+ * @param {Runner} runner - Instance triggers reporter actions.
37
+ * @param {Object} [options] - runner options
38
+ */
39
+ function Markdown(runner, options) {
40
+ Base.call(this, runner, options);
41
+
42
+ var level = 0;
43
+ var buf = '';
44
+
45
+ function title(str) {
46
+ return Array(level).join('#') + ' ' + str;
47
+ }
48
+
49
+ function mapTOC(suite, obj) {
50
+ var ret = obj;
51
+ var key = SUITE_PREFIX + suite.title;
52
+
53
+ obj = obj[key] = obj[key] || {suite: suite};
54
+ suite.suites.forEach(function(suite) {
55
+ mapTOC(suite, obj);
56
+ });
57
+
58
+ return ret;
59
+ }
60
+
61
+ function stringifyTOC(obj, level) {
62
+ ++level;
63
+ var buf = '';
64
+ var link;
65
+ for (var key in obj) {
66
+ if (key === 'suite') {
67
+ continue;
68
+ }
69
+ if (key !== SUITE_PREFIX) {
70
+ link = ' - [' + key.substring(1) + ']';
71
+ link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
72
+ buf += Array(level).join(' ') + link;
73
+ }
74
+ buf += stringifyTOC(obj[key], level);
75
+ }
76
+ return buf;
77
+ }
78
+
79
+ function generateTOC(suite) {
80
+ var obj = mapTOC(suite, {});
81
+ return stringifyTOC(obj, 0);
82
+ }
83
+
84
+ generateTOC(runner.suite);
85
+
86
+ runner.on(EVENT_SUITE_BEGIN, function(suite) {
87
+ ++level;
88
+ var slug = utils.slug(suite.fullTitle());
89
+ buf += '<a name="' + slug + '"></a>' + '\n';
90
+ buf += title(suite.title) + '\n';
91
+ });
92
+
93
+ runner.on(EVENT_SUITE_END, function() {
94
+ --level;
95
+ });
96
+
97
+ runner.on(EVENT_TEST_PASS, function(test) {
98
+ var code = utils.clean(test.body);
99
+ buf += test.title + '.\n';
100
+ buf += '\n```js\n';
101
+ buf += code + '\n';
102
+ buf += '```\n\n';
103
+ });
104
+
105
+ runner.once(EVENT_RUN_END, function() {
106
+ process.stdout.write('# TOC\n');
107
+ process.stdout.write(generateTOC(runner.suite));
108
+ process.stdout.write(buf);
109
+ });
110
+ }
111
+
112
+ Markdown.description = 'GitHub Flavored Markdown';
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+ /**
3
+ * @module Min
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var inherits = require('../utils').inherits;
11
+ var constants = require('../runner').constants;
12
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
13
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
14
+
15
+ /**
16
+ * Expose `Min`.
17
+ */
18
+
19
+ exports = module.exports = Min;
20
+
21
+ /**
22
+ * Constructs a new `Min` reporter instance.
23
+ *
24
+ * @description
25
+ * This minimal test reporter is best used with '--watch'.
26
+ *
27
+ * @public
28
+ * @class
29
+ * @memberof Mocha.reporters
30
+ * @extends Mocha.reporters.Base
31
+ * @param {Runner} runner - Instance triggers reporter actions.
32
+ * @param {Object} [options] - runner options
33
+ */
34
+ function Min(runner, options) {
35
+ Base.call(this, runner, options);
36
+
37
+ runner.on(EVENT_RUN_BEGIN, function() {
38
+ // clear screen
39
+ process.stdout.write('\u001b[2J');
40
+ // set cursor position
41
+ process.stdout.write('\u001b[1;3H');
42
+ });
43
+
44
+ runner.once(EVENT_RUN_END, this.epilogue.bind(this));
45
+ }
46
+
47
+ /**
48
+ * Inherit from `Base.prototype`.
49
+ */
50
+ inherits(Min, Base);
51
+
52
+ Min.description = 'essentially just a summary';
@@ -0,0 +1,276 @@
1
+ 'use strict';
2
+ /**
3
+ * @module Nyan
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var constants = require('../runner').constants;
11
+ var inherits = require('../utils').inherits;
12
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
13
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
14
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
15
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
16
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
17
+
18
+ /**
19
+ * Expose `Dot`.
20
+ */
21
+
22
+ exports = module.exports = NyanCat;
23
+
24
+ /**
25
+ * Constructs a new `Nyan` reporter instance.
26
+ *
27
+ * @public
28
+ * @class Nyan
29
+ * @memberof Mocha.reporters
30
+ * @extends Mocha.reporters.Base
31
+ * @param {Runner} runner - Instance triggers reporter actions.
32
+ * @param {Object} [options] - runner options
33
+ */
34
+ function NyanCat(runner, options) {
35
+ Base.call(this, runner, options);
36
+
37
+ var self = this;
38
+ var width = (Base.window.width * 0.75) | 0;
39
+ var nyanCatWidth = (this.nyanCatWidth = 11);
40
+
41
+ this.colorIndex = 0;
42
+ this.numberOfLines = 4;
43
+ this.rainbowColors = self.generateColors();
44
+ this.scoreboardWidth = 5;
45
+ this.tick = 0;
46
+ this.trajectories = [[], [], [], []];
47
+ this.trajectoryWidthMax = width - nyanCatWidth;
48
+
49
+ runner.on(EVENT_RUN_BEGIN, function() {
50
+ Base.cursor.hide();
51
+ self.draw();
52
+ });
53
+
54
+ runner.on(EVENT_TEST_PENDING, function() {
55
+ self.draw();
56
+ });
57
+
58
+ runner.on(EVENT_TEST_PASS, function() {
59
+ self.draw();
60
+ });
61
+
62
+ runner.on(EVENT_TEST_FAIL, function() {
63
+ self.draw();
64
+ });
65
+
66
+ runner.once(EVENT_RUN_END, function() {
67
+ Base.cursor.show();
68
+ for (var i = 0; i < self.numberOfLines; i++) {
69
+ write('\n');
70
+ }
71
+ self.epilogue();
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Inherit from `Base.prototype`.
77
+ */
78
+ inherits(NyanCat, Base);
79
+
80
+ /**
81
+ * Draw the nyan cat
82
+ *
83
+ * @private
84
+ */
85
+
86
+ NyanCat.prototype.draw = function() {
87
+ this.appendRainbow();
88
+ this.drawScoreboard();
89
+ this.drawRainbow();
90
+ this.drawNyanCat();
91
+ this.tick = !this.tick;
92
+ };
93
+
94
+ /**
95
+ * Draw the "scoreboard" showing the number
96
+ * of passes, failures and pending tests.
97
+ *
98
+ * @private
99
+ */
100
+
101
+ NyanCat.prototype.drawScoreboard = function() {
102
+ var stats = this.stats;
103
+
104
+ function draw(type, n) {
105
+ write(' ');
106
+ write(Base.color(type, n));
107
+ write('\n');
108
+ }
109
+
110
+ draw('green', stats.passes);
111
+ draw('fail', stats.failures);
112
+ draw('pending', stats.pending);
113
+ write('\n');
114
+
115
+ this.cursorUp(this.numberOfLines);
116
+ };
117
+
118
+ /**
119
+ * Append the rainbow.
120
+ *
121
+ * @private
122
+ */
123
+
124
+ NyanCat.prototype.appendRainbow = function() {
125
+ var segment = this.tick ? '_' : '-';
126
+ var rainbowified = this.rainbowify(segment);
127
+
128
+ for (var index = 0; index < this.numberOfLines; index++) {
129
+ var trajectory = this.trajectories[index];
130
+ if (trajectory.length >= this.trajectoryWidthMax) {
131
+ trajectory.shift();
132
+ }
133
+ trajectory.push(rainbowified);
134
+ }
135
+ };
136
+
137
+ /**
138
+ * Draw the rainbow.
139
+ *
140
+ * @private
141
+ */
142
+
143
+ NyanCat.prototype.drawRainbow = function() {
144
+ var self = this;
145
+
146
+ this.trajectories.forEach(function(line) {
147
+ write('\u001b[' + self.scoreboardWidth + 'C');
148
+ write(line.join(''));
149
+ write('\n');
150
+ });
151
+
152
+ this.cursorUp(this.numberOfLines);
153
+ };
154
+
155
+ /**
156
+ * Draw the nyan cat
157
+ *
158
+ * @private
159
+ */
160
+ NyanCat.prototype.drawNyanCat = function() {
161
+ var self = this;
162
+ var startWidth = this.scoreboardWidth + this.trajectories[0].length;
163
+ var dist = '\u001b[' + startWidth + 'C';
164
+ var padding = '';
165
+
166
+ write(dist);
167
+ write('_,------,');
168
+ write('\n');
169
+
170
+ write(dist);
171
+ padding = self.tick ? ' ' : ' ';
172
+ write('_|' + padding + '/\\_/\\ ');
173
+ write('\n');
174
+
175
+ write(dist);
176
+ padding = self.tick ? '_' : '__';
177
+ var tail = self.tick ? '~' : '^';
178
+ write(tail + '|' + padding + this.face() + ' ');
179
+ write('\n');
180
+
181
+ write(dist);
182
+ padding = self.tick ? ' ' : ' ';
183
+ write(padding + '"" "" ');
184
+ write('\n');
185
+
186
+ this.cursorUp(this.numberOfLines);
187
+ };
188
+
189
+ /**
190
+ * Draw nyan cat face.
191
+ *
192
+ * @private
193
+ * @return {string}
194
+ */
195
+
196
+ NyanCat.prototype.face = function() {
197
+ var stats = this.stats;
198
+ if (stats.failures) {
199
+ return '( x .x)';
200
+ } else if (stats.pending) {
201
+ return '( o .o)';
202
+ } else if (stats.passes) {
203
+ return '( ^ .^)';
204
+ }
205
+ return '( - .-)';
206
+ };
207
+
208
+ /**
209
+ * Move cursor up `n`.
210
+ *
211
+ * @private
212
+ * @param {number} n
213
+ */
214
+
215
+ NyanCat.prototype.cursorUp = function(n) {
216
+ write('\u001b[' + n + 'A');
217
+ };
218
+
219
+ /**
220
+ * Move cursor down `n`.
221
+ *
222
+ * @private
223
+ * @param {number} n
224
+ */
225
+
226
+ NyanCat.prototype.cursorDown = function(n) {
227
+ write('\u001b[' + n + 'B');
228
+ };
229
+
230
+ /**
231
+ * Generate rainbow colors.
232
+ *
233
+ * @private
234
+ * @return {Array}
235
+ */
236
+ NyanCat.prototype.generateColors = function() {
237
+ var colors = [];
238
+
239
+ for (var i = 0; i < 6 * 7; i++) {
240
+ var pi3 = Math.floor(Math.PI / 3);
241
+ var n = i * (1.0 / 6);
242
+ var r = Math.floor(3 * Math.sin(n) + 3);
243
+ var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
244
+ var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
245
+ colors.push(36 * r + 6 * g + b + 16);
246
+ }
247
+
248
+ return colors;
249
+ };
250
+
251
+ /**
252
+ * Apply rainbow to the given `str`.
253
+ *
254
+ * @private
255
+ * @param {string} str
256
+ * @return {string}
257
+ */
258
+ NyanCat.prototype.rainbowify = function(str) {
259
+ if (!Base.useColors) {
260
+ return str;
261
+ }
262
+ var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
263
+ this.colorIndex += 1;
264
+ return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
265
+ };
266
+
267
+ /**
268
+ * Stdout helper.
269
+ *
270
+ * @param {string} string A message to write to stdout.
271
+ */
272
+ function write(string) {
273
+ process.stdout.write(string);
274
+ }
275
+
276
+ NyanCat.description = '"nyan cat"';