mocha-compat 3.6.4 → 10.8.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 (92) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +61 -110
  3. package/bin/_mocha +10 -0
  4. package/bin/mocha.js +142 -0
  5. package/browser-entry.js +61 -22
  6. package/lib/browser/highlight-tags.js +39 -0
  7. package/lib/browser/parse-query.js +24 -0
  8. package/lib/{template.html → browser/template.html} +7 -5
  9. package/lib/cli/cli.js +89 -0
  10. package/lib/cli/collect-files.js +137 -0
  11. package/lib/cli/commands.js +14 -0
  12. package/lib/cli/config.js +100 -0
  13. package/lib/cli/index.js +3 -0
  14. package/lib/cli/init.js +36 -0
  15. package/lib/cli/lookup-files.js +150 -0
  16. package/lib/cli/node-flags.js +85 -0
  17. package/lib/cli/one-and-dones.js +69 -0
  18. package/lib/cli/options.js +284 -0
  19. package/lib/cli/run-helpers.js +304 -0
  20. package/lib/cli/run-option-metadata.js +116 -0
  21. package/lib/cli/run.js +380 -0
  22. package/lib/cli/watch-run.js +377 -0
  23. package/lib/context.js +16 -42
  24. package/lib/errors.js +563 -0
  25. package/lib/hook.js +50 -9
  26. package/lib/interfaces/bdd.js +28 -29
  27. package/lib/interfaces/common.js +56 -21
  28. package/lib/interfaces/exports.js +4 -7
  29. package/lib/interfaces/qunit.js +10 -11
  30. package/lib/interfaces/tdd.js +15 -15
  31. package/lib/mocha.js +1073 -292
  32. package/lib/mocharc.json +10 -0
  33. package/lib/nodejs/buffered-worker-pool.js +188 -0
  34. package/lib/nodejs/esm-utils.js +106 -0
  35. package/lib/nodejs/file-unloader.js +15 -0
  36. package/lib/nodejs/parallel-buffered-runner.js +433 -0
  37. package/lib/nodejs/reporters/parallel-buffered.js +165 -0
  38. package/lib/nodejs/serializer.js +414 -0
  39. package/lib/nodejs/worker.js +151 -0
  40. package/lib/pending.js +3 -3
  41. package/lib/plugin-loader.js +286 -0
  42. package/lib/reporters/base.js +305 -205
  43. package/lib/reporters/doc.js +52 -21
  44. package/lib/reporters/dot.js +31 -18
  45. package/lib/reporters/html.js +153 -81
  46. package/lib/reporters/json-stream.js +53 -24
  47. package/lib/reporters/json.js +88 -18
  48. package/lib/reporters/landing.js +38 -16
  49. package/lib/reporters/list.js +34 -19
  50. package/lib/reporters/markdown.js +28 -15
  51. package/lib/reporters/min.js +22 -8
  52. package/lib/reporters/nyan.js +62 -58
  53. package/lib/reporters/progress.js +32 -19
  54. package/lib/reporters/spec.js +41 -23
  55. package/lib/reporters/tap.js +255 -32
  56. package/lib/reporters/xunit.js +89 -39
  57. package/lib/runnable.js +233 -148
  58. package/lib/runner.js +679 -380
  59. package/lib/stats-collector.js +83 -0
  60. package/lib/suite.js +376 -112
  61. package/lib/test.js +82 -21
  62. package/lib/utils.js +364 -477
  63. package/mocha.css +183 -54
  64. package/mocha.js +19840 -15846
  65. package/mocha.js.map +1 -0
  66. package/package.json +163 -336
  67. package/{lib/to-iso-string → vendor/serialize-javascript}/LICENSE +8 -6
  68. package/vendor/serialize-javascript/README.md +10 -0
  69. package/vendor/serialize-javascript/index.js +349 -0
  70. package/bin/_mocha-compat +0 -572
  71. package/bin/mocha-compat +0 -87
  72. package/bin/options.js +0 -41
  73. package/bower.json +0 -38
  74. package/images/error.png +0 -0
  75. package/images/ok.png +0 -0
  76. package/lib/browser/.eslintrc.yaml +0 -4
  77. package/lib/browser/debug.js +0 -7
  78. package/lib/browser/events.js +0 -195
  79. package/lib/browser/progress.js +0 -119
  80. package/lib/browser/tty.js +0 -13
  81. package/lib/ms.js +0 -130
  82. package/lib/to-iso-string/index.js +0 -37
  83. package/vendor/glob/LICENSE +0 -15
  84. package/vendor/glob/README.md +0 -399
  85. package/vendor/glob/common.js +0 -244
  86. package/vendor/glob/glob.js +0 -788
  87. package/vendor/glob/package.json +0 -55
  88. package/vendor/glob/sync.js +0 -486
  89. package/vendor/inflight/LICENSE +0 -15
  90. package/vendor/inflight/README.md +0 -37
  91. package/vendor/inflight/inflight.js +0 -54
  92. package/vendor/inflight/package.json +0 -29
@@ -1,11 +1,19 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Nyan
4
+ */
3
5
  /**
4
6
  * Module dependencies.
5
7
  */
6
8
 
7
9
  var Base = require('./base');
10
+ var constants = require('../runner').constants;
8
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;
9
17
 
10
18
  /**
11
19
  * Expose `Dot`.
@@ -14,18 +22,21 @@ var inherits = require('../utils').inherits;
14
22
  exports = module.exports = NyanCat;
15
23
 
16
24
  /**
17
- * Initialize a new `Dot` matrix test reporter.
25
+ * Constructs a new `Nyan` reporter instance.
18
26
  *
19
- * @param {Runner} runner
20
- * @api public
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
21
33
  */
22
-
23
- function NyanCat (runner) {
24
- Base.call(this, runner);
34
+ function NyanCat(runner, options) {
35
+ Base.call(this, runner, options);
25
36
 
26
37
  var self = this;
27
- var width = Base.window.width * 0.75 | 0;
28
- var nyanCatWidth = this.nyanCatWidth = 11;
38
+ var width = (Base.window.width * 0.75) | 0;
39
+ var nyanCatWidth = (this.nyanCatWidth = 11);
29
40
 
30
41
  this.colorIndex = 0;
31
42
  this.numberOfLines = 4;
@@ -33,29 +44,29 @@ function NyanCat (runner) {
33
44
  this.scoreboardWidth = 5;
34
45
  this.tick = 0;
35
46
  this.trajectories = [[], [], [], []];
36
- this.trajectoryWidthMax = (width - nyanCatWidth);
47
+ this.trajectoryWidthMax = width - nyanCatWidth;
37
48
 
38
- runner.on('start', function () {
49
+ runner.on(EVENT_RUN_BEGIN, function () {
39
50
  Base.cursor.hide();
40
51
  self.draw();
41
52
  });
42
53
 
43
- runner.on('pending', function () {
54
+ runner.on(EVENT_TEST_PENDING, function () {
44
55
  self.draw();
45
56
  });
46
57
 
47
- runner.on('pass', function () {
58
+ runner.on(EVENT_TEST_PASS, function () {
48
59
  self.draw();
49
60
  });
50
61
 
51
- runner.on('fail', function () {
62
+ runner.on(EVENT_TEST_FAIL, function () {
52
63
  self.draw();
53
64
  });
54
65
 
55
- runner.on('end', function () {
66
+ runner.once(EVENT_RUN_END, function () {
56
67
  Base.cursor.show();
57
68
  for (var i = 0; i < self.numberOfLines; i++) {
58
- write('\n');
69
+ process.stdout.write('\n');
59
70
  }
60
71
  self.epilogue();
61
72
  });
@@ -69,7 +80,7 @@ inherits(NyanCat, Base);
69
80
  /**
70
81
  * Draw the nyan cat
71
82
  *
72
- * @api private
83
+ * @private
73
84
  */
74
85
 
75
86
  NyanCat.prototype.draw = function () {
@@ -84,22 +95,22 @@ NyanCat.prototype.draw = function () {
84
95
  * Draw the "scoreboard" showing the number
85
96
  * of passes, failures and pending tests.
86
97
  *
87
- * @api private
98
+ * @private
88
99
  */
89
100
 
90
101
  NyanCat.prototype.drawScoreboard = function () {
91
102
  var stats = this.stats;
92
103
 
93
- function draw (type, n) {
94
- write(' ');
95
- write(Base.color(type, n));
96
- write('\n');
104
+ function draw(type, n) {
105
+ process.stdout.write(' ');
106
+ process.stdout.write(Base.color(type, n));
107
+ process.stdout.write('\n');
97
108
  }
98
109
 
99
110
  draw('green', stats.passes);
100
111
  draw('fail', stats.failures);
101
112
  draw('pending', stats.pending);
102
- write('\n');
113
+ process.stdout.write('\n');
103
114
 
104
115
  this.cursorUp(this.numberOfLines);
105
116
  };
@@ -107,7 +118,7 @@ NyanCat.prototype.drawScoreboard = function () {
107
118
  /**
108
119
  * Append the rainbow.
109
120
  *
110
- * @api private
121
+ * @private
111
122
  */
112
123
 
113
124
  NyanCat.prototype.appendRainbow = function () {
@@ -126,16 +137,16 @@ NyanCat.prototype.appendRainbow = function () {
126
137
  /**
127
138
  * Draw the rainbow.
128
139
  *
129
- * @api private
140
+ * @private
130
141
  */
131
142
 
132
143
  NyanCat.prototype.drawRainbow = function () {
133
144
  var self = this;
134
145
 
135
146
  this.trajectories.forEach(function (line) {
136
- write('\u001b[' + self.scoreboardWidth + 'C');
137
- write(line.join(''));
138
- write('\n');
147
+ process.stdout.write('\u001b[' + self.scoreboardWidth + 'C');
148
+ process.stdout.write(line.join(''));
149
+ process.stdout.write('\n');
139
150
  });
140
151
 
141
152
  this.cursorUp(this.numberOfLines);
@@ -144,7 +155,7 @@ NyanCat.prototype.drawRainbow = function () {
144
155
  /**
145
156
  * Draw the nyan cat
146
157
  *
147
- * @api private
158
+ * @private
148
159
  */
149
160
  NyanCat.prototype.drawNyanCat = function () {
150
161
  var self = this;
@@ -152,25 +163,25 @@ NyanCat.prototype.drawNyanCat = function () {
152
163
  var dist = '\u001b[' + startWidth + 'C';
153
164
  var padding = '';
154
165
 
155
- write(dist);
156
- write('_,------,');
157
- write('\n');
166
+ process.stdout.write(dist);
167
+ process.stdout.write('_,------,');
168
+ process.stdout.write('\n');
158
169
 
159
- write(dist);
170
+ process.stdout.write(dist);
160
171
  padding = self.tick ? ' ' : ' ';
161
- write('_|' + padding + '/\\_/\\ ');
162
- write('\n');
172
+ process.stdout.write('_|' + padding + '/\\_/\\ ');
173
+ process.stdout.write('\n');
163
174
 
164
- write(dist);
175
+ process.stdout.write(dist);
165
176
  padding = self.tick ? '_' : '__';
166
177
  var tail = self.tick ? '~' : '^';
167
- write(tail + '|' + padding + this.face() + ' ');
168
- write('\n');
178
+ process.stdout.write(tail + '|' + padding + this.face() + ' ');
179
+ process.stdout.write('\n');
169
180
 
170
- write(dist);
181
+ process.stdout.write(dist);
171
182
  padding = self.tick ? ' ' : ' ';
172
- write(padding + '"" "" ');
173
- write('\n');
183
+ process.stdout.write(padding + '"" "" ');
184
+ process.stdout.write('\n');
174
185
 
175
186
  this.cursorUp(this.numberOfLines);
176
187
  };
@@ -178,7 +189,7 @@ NyanCat.prototype.drawNyanCat = function () {
178
189
  /**
179
190
  * Draw nyan cat face.
180
191
  *
181
- * @api private
192
+ * @private
182
193
  * @return {string}
183
194
  */
184
195
 
@@ -197,37 +208,37 @@ NyanCat.prototype.face = function () {
197
208
  /**
198
209
  * Move cursor up `n`.
199
210
  *
200
- * @api private
211
+ * @private
201
212
  * @param {number} n
202
213
  */
203
214
 
204
215
  NyanCat.prototype.cursorUp = function (n) {
205
- write('\u001b[' + n + 'A');
216
+ process.stdout.write('\u001b[' + n + 'A');
206
217
  };
207
218
 
208
219
  /**
209
220
  * Move cursor down `n`.
210
221
  *
211
- * @api private
222
+ * @private
212
223
  * @param {number} n
213
224
  */
214
225
 
215
226
  NyanCat.prototype.cursorDown = function (n) {
216
- write('\u001b[' + n + 'B');
227
+ process.stdout.write('\u001b[' + n + 'B');
217
228
  };
218
229
 
219
230
  /**
220
231
  * Generate rainbow colors.
221
232
  *
222
- * @api private
233
+ * @private
223
234
  * @return {Array}
224
235
  */
225
236
  NyanCat.prototype.generateColors = function () {
226
237
  var colors = [];
227
238
 
228
- for (var i = 0; i < (6 * 7); i++) {
239
+ for (var i = 0; i < 6 * 7; i++) {
229
240
  var pi3 = Math.floor(Math.PI / 3);
230
- var n = (i * (1.0 / 6));
241
+ var n = i * (1.0 / 6);
231
242
  var r = Math.floor(3 * Math.sin(n) + 3);
232
243
  var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
233
244
  var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
@@ -240,7 +251,7 @@ NyanCat.prototype.generateColors = function () {
240
251
  /**
241
252
  * Apply rainbow to the given `str`.
242
253
  *
243
- * @api private
254
+ * @private
244
255
  * @param {string} str
245
256
  * @return {string}
246
257
  */
@@ -253,11 +264,4 @@ NyanCat.prototype.rainbowify = function (str) {
253
264
  return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
254
265
  };
255
266
 
256
- /**
257
- * Stdout helper.
258
- *
259
- * @param {string} string A message to write to stdout.
260
- */
261
- function write (string) {
262
- process.stdout.write(string);
263
- }
267
+ NyanCat.description = '"nyan cat"';
@@ -1,10 +1,16 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Progress
4
+ */
3
5
  /**
4
6
  * Module dependencies.
5
7
  */
6
8
 
7
9
  var Base = require('./base');
10
+ var constants = require('../runner').constants;
11
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
12
+ var EVENT_TEST_END = constants.EVENT_TEST_END;
13
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
8
14
  var inherits = require('../utils').inherits;
9
15
  var color = Base.color;
10
16
  var cursor = Base.cursor;
@@ -22,41 +28,46 @@ exports = module.exports = Progress;
22
28
  Base.colors.progress = 90;
23
29
 
24
30
  /**
25
- * Initialize a new `Progress` bar test reporter.
31
+ * Constructs a new `Progress` reporter instance.
26
32
  *
27
- * @api public
28
- * @param {Runner} runner
29
- * @param {Object} options
33
+ * @public
34
+ * @class
35
+ * @memberof Mocha.reporters
36
+ * @extends Mocha.reporters.Base
37
+ * @param {Runner} runner - Instance triggers reporter actions.
38
+ * @param {Object} [options] - runner options
30
39
  */
31
- function Progress (runner, options) {
32
- Base.call(this, runner);
40
+ function Progress(runner, options) {
41
+ Base.call(this, runner, options);
33
42
 
34
43
  var self = this;
35
- var width = Base.window.width * 0.50 | 0;
44
+ var width = (Base.window.width * 0.5) | 0;
36
45
  var total = runner.total;
37
46
  var complete = 0;
38
47
  var lastN = -1;
39
48
 
40
49
  // default chars
41
50
  options = options || {};
42
- options.open = options.open || '[';
43
- options.complete = options.complete || '▬';
44
- options.incomplete = options.incomplete || Base.symbols.dot;
45
- options.close = options.close || ']';
46
- options.verbose = false;
51
+ var reporterOptions = options.reporterOptions || {};
52
+
53
+ options.open = reporterOptions.open || '[';
54
+ options.complete = reporterOptions.complete || '▬';
55
+ options.incomplete = reporterOptions.incomplete || Base.symbols.dot;
56
+ options.close = reporterOptions.close || ']';
57
+ options.verbose = reporterOptions.verbose || false;
47
58
 
48
59
  // tests started
49
- runner.on('start', function () {
50
- console.log();
60
+ runner.on(EVENT_RUN_BEGIN, function () {
61
+ process.stdout.write('\n');
51
62
  cursor.hide();
52
63
  });
53
64
 
54
65
  // tests complete
55
- runner.on('test end', function () {
66
+ runner.on(EVENT_TEST_END, function () {
56
67
  complete++;
57
68
 
58
69
  var percent = complete / total;
59
- var n = width * percent | 0;
70
+ var n = (width * percent) | 0;
60
71
  var i = width - n;
61
72
 
62
73
  if (n === lastN && !options.verbose) {
@@ -78,9 +89,9 @@ function Progress (runner, options) {
78
89
 
79
90
  // tests are complete, output some stats
80
91
  // and the failures if any
81
- runner.on('end', function () {
92
+ runner.once(EVENT_RUN_END, function () {
82
93
  cursor.show();
83
- console.log();
94
+ process.stdout.write('\n');
84
95
  self.epilogue();
85
96
  });
86
97
  }
@@ -89,3 +100,5 @@ function Progress (runner, options) {
89
100
  * Inherit from `Base.prototype`.
90
101
  */
91
102
  inherits(Progress, Base);
103
+
104
+ Progress.description = 'a progress bar';
@@ -1,10 +1,20 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Spec
4
+ */
3
5
  /**
4
6
  * Module dependencies.
5
7
  */
6
8
 
7
9
  var Base = require('./base');
10
+ var constants = require('../runner').constants;
11
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
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_FAIL = constants.EVENT_TEST_FAIL;
16
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
17
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
8
18
  var inherits = require('../utils').inherits;
9
19
  var color = Base.color;
10
20
 
@@ -15,67 +25,75 @@ var color = Base.color;
15
25
  exports = module.exports = Spec;
16
26
 
17
27
  /**
18
- * Initialize a new `Spec` test reporter.
28
+ * Constructs a new `Spec` reporter instance.
19
29
  *
20
- * @api public
21
- * @param {Runner} runner
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
22
36
  */
23
- function Spec (runner) {
24
- Base.call(this, runner);
37
+ function Spec(runner, options) {
38
+ Base.call(this, runner, options);
25
39
 
26
40
  var self = this;
27
41
  var indents = 0;
28
42
  var n = 0;
29
43
 
30
- function indent () {
44
+ function indent() {
31
45
  return Array(indents).join(' ');
32
46
  }
33
47
 
34
- runner.on('start', function () {
35
- console.log();
48
+ runner.on(EVENT_RUN_BEGIN, function () {
49
+ Base.consoleLog();
36
50
  });
37
51
 
38
- runner.on('suite', function (suite) {
52
+ runner.on(EVENT_SUITE_BEGIN, function (suite) {
39
53
  ++indents;
40
- console.log(color('suite', '%s%s'), indent(), suite.title);
54
+ Base.consoleLog(color('suite', '%s%s'), indent(), suite.title);
41
55
  });
42
56
 
43
- runner.on('suite end', function () {
57
+ runner.on(EVENT_SUITE_END, function () {
44
58
  --indents;
45
59
  if (indents === 1) {
46
- console.log();
60
+ Base.consoleLog();
47
61
  }
48
62
  });
49
63
 
50
- runner.on('pending', function (test) {
64
+ runner.on(EVENT_TEST_PENDING, function (test) {
51
65
  var fmt = indent() + color('pending', ' - %s');
52
- console.log(fmt, test.title);
66
+ Base.consoleLog(fmt, test.title);
53
67
  });
54
68
 
55
- runner.on('pass', function (test) {
69
+ runner.on(EVENT_TEST_PASS, function (test) {
56
70
  var fmt;
57
71
  if (test.speed === 'fast') {
58
- fmt = indent() +
72
+ fmt =
73
+ indent() +
59
74
  color('checkmark', ' ' + Base.symbols.ok) +
60
75
  color('pass', ' %s');
61
- console.log(fmt, test.title);
76
+ Base.consoleLog(fmt, test.title);
62
77
  } else {
63
- fmt = indent() +
78
+ fmt =
79
+ indent() +
64
80
  color('checkmark', ' ' + Base.symbols.ok) +
65
81
  color('pass', ' %s') +
66
82
  color(test.speed, ' (%dms)');
67
- console.log(fmt, test.title, test.duration);
83
+ Base.consoleLog(fmt, test.title, test.duration);
68
84
  }
69
85
  });
70
86
 
71
- runner.on('fail', function (test) {
72
- console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
87
+ runner.on(EVENT_TEST_FAIL, function (test) {
88
+ Base.consoleLog(indent() + color('fail', ' %d) %s'), ++n, test.title);
73
89
  });
74
90
 
75
- runner.on('end', self.epilogue.bind(self));
91
+ runner.once(EVENT_RUN_END, self.epilogue.bind(self));
76
92
  }
77
93
 
78
94
  /**
79
95
  * Inherit from `Base.prototype`.
80
96
  */
81
97
  inherits(Spec, Base);
98
+
99
+ Spec.description = 'hierarchical & verbose [default]';