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,10 +1,8 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
3
  var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE =
5
+ require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
8
6
 
9
7
  /**
10
8
  * BDD-style interface:
@@ -23,10 +21,10 @@ var Test = require('../test');
23
21
  *
24
22
  * @param {Suite} suite Root suite.
25
23
  */
26
- module.exports = function (suite) {
24
+ module.exports = function bddInterface(suite) {
27
25
  var suites = [suite];
28
26
 
29
- suite.on('pre-require', function (context, file, mocha) {
27
+ suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
30
28
  var common = require('./common')(suites, context, mocha);
31
29
 
32
30
  context.before = common.before;
@@ -42,9 +40,9 @@ module.exports = function (suite) {
42
40
 
43
41
  context.describe = context.context = function (title, fn) {
44
42
  return common.suite.create({
45
- title: title,
46
- file: file,
47
- fn: fn
43
+ title,
44
+ file,
45
+ fn
48
46
  });
49
47
  };
50
48
 
@@ -52,13 +50,16 @@ module.exports = function (suite) {
52
50
  * Pending describe.
53
51
  */
54
52
 
55
- context.xdescribe = context.xcontext = context.describe.skip = function (title, fn) {
56
- return common.suite.skip({
57
- title: title,
58
- file: file,
59
- fn: fn
60
- });
61
- };
53
+ context.xdescribe =
54
+ context.xcontext =
55
+ context.describe.skip =
56
+ function (title, fn) {
57
+ return common.suite.skip({
58
+ title,
59
+ file,
60
+ fn
61
+ });
62
+ };
62
63
 
63
64
  /**
64
65
  * Exclusive suite.
@@ -66,9 +67,9 @@ module.exports = function (suite) {
66
67
 
67
68
  context.describe.only = function (title, fn) {
68
69
  return common.suite.only({
69
- title: title,
70
- file: file,
71
- fn: fn
70
+ title,
71
+ file,
72
+ fn
72
73
  });
73
74
  };
74
75
 
@@ -101,15 +102,13 @@ module.exports = function (suite) {
101
102
  * Pending test case.
102
103
  */
103
104
 
104
- context.xit = context.xspecify = context.it.skip = function (title) {
105
- context.it(title);
106
- };
107
-
108
- /**
109
- * Number of attempts to retry.
110
- */
111
- context.it.retries = function (n) {
112
- context.retries(n);
113
- };
105
+ context.xit =
106
+ context.xspecify =
107
+ context.it.skip =
108
+ function (title) {
109
+ return context.it(title);
110
+ };
114
111
  });
115
112
  };
113
+
114
+ module.exports.description = 'BDD or RSpec style [default]';
@@ -1,16 +1,41 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ @module interfaces/common
5
+ */
6
+
3
7
  var Suite = require('../suite');
8
+ var errors = require('../errors');
9
+ var createMissingArgumentError = errors.createMissingArgumentError;
10
+ var createUnsupportedError = errors.createUnsupportedError;
11
+ var createForbiddenExclusivityError = errors.createForbiddenExclusivityError;
4
12
 
5
13
  /**
6
14
  * Functions common to more than one interface.
7
15
  *
16
+ * @private
8
17
  * @param {Suite[]} suites
9
18
  * @param {Context} context
10
19
  * @param {Mocha} mocha
11
20
  * @return {Object} An object containing common functions.
12
21
  */
13
22
  module.exports = function (suites, context, mocha) {
23
+ /**
24
+ * Check if the suite should be tested.
25
+ *
26
+ * @private
27
+ * @param {Suite} suite - suite to check
28
+ * @returns {boolean}
29
+ */
30
+ function shouldBeTested(suite) {
31
+ return (
32
+ !mocha.options.grep ||
33
+ (mocha.options.grep &&
34
+ mocha.options.grep.test(suite.fullTitle()) &&
35
+ !mocha.options.invert)
36
+ );
37
+ }
38
+
14
39
  return {
15
40
  /**
16
41
  * This is only present if flag --delay is passed into Mocha. It triggers
@@ -19,8 +44,8 @@ module.exports = function (suites, context, mocha) {
19
44
  * @param {Suite} suite The root suite.
20
45
  * @return {Function} A function which runs the root suite
21
46
  */
22
- runWithSuite: function runWithSuite (suite) {
23
- return function run () {
47
+ runWithSuite: function runWithSuite(suite) {
48
+ return function run() {
24
49
  suite.run();
25
50
  };
26
51
  },
@@ -73,8 +98,10 @@ module.exports = function (suites, context, mocha) {
73
98
  * @param {Object} opts
74
99
  * @returns {Suite}
75
100
  */
76
- only: function only (opts) {
77
- mocha.options.hasOnly = true;
101
+ only: function only(opts) {
102
+ if (mocha.options.forbidOnly) {
103
+ throw createForbiddenExclusivityError(mocha);
104
+ }
78
105
  opts.isOnly = true;
79
106
  return this.create(opts);
80
107
  },
@@ -86,13 +113,14 @@ module.exports = function (suites, context, mocha) {
86
113
  * @param {Object} opts
87
114
  * @returns {Suite}
88
115
  */
89
- skip: function skip (opts) {
116
+ skip: function skip(opts) {
90
117
  opts.pending = true;
91
118
  return this.create(opts);
92
119
  },
93
120
 
94
121
  /**
95
122
  * Creates a suite.
123
+ *
96
124
  * @param {Object} opts Options
97
125
  * @param {string} opts.title Title of Suite
98
126
  * @param {Function} [opts.fn] Suite Function (not always applicable)
@@ -101,20 +129,35 @@ module.exports = function (suites, context, mocha) {
101
129
  * @param {boolean} [opts.isOnly] Is Suite exclusive?
102
130
  * @returns {Suite}
103
131
  */
104
- create: function create (opts) {
132
+ create: function create(opts) {
105
133
  var suite = Suite.create(suites[0], opts.title);
106
134
  suite.pending = Boolean(opts.pending);
107
135
  suite.file = opts.file;
108
136
  suites.unshift(suite);
109
137
  if (opts.isOnly) {
110
- suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
111
- mocha.options.hasOnly = true;
138
+ suite.markOnly();
139
+ }
140
+ if (
141
+ suite.pending &&
142
+ mocha.options.forbidPending &&
143
+ shouldBeTested(suite)
144
+ ) {
145
+ throw createUnsupportedError('Pending test forbidden');
112
146
  }
113
147
  if (typeof opts.fn === 'function') {
114
148
  opts.fn.call(suite);
115
149
  suites.shift();
116
150
  } else if (typeof opts.fn === 'undefined' && !suite.pending) {
117
- throw new Error('Suite "' + suite.fullTitle() + '" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.');
151
+ throw createMissingArgumentError(
152
+ 'Suite "' +
153
+ suite.fullTitle() +
154
+ '" was defined but no callback was supplied. ' +
155
+ 'Supply a callback or explicitly skip the suite.',
156
+ 'callback',
157
+ 'function'
158
+ );
159
+ } else if (!opts.fn && suite.pending) {
160
+ suites.shift();
118
161
  }
119
162
 
120
163
  return suite;
@@ -122,7 +165,6 @@ module.exports = function (suites, context, mocha) {
122
165
  },
123
166
 
124
167
  test: {
125
-
126
168
  /**
127
169
  * Exclusive test-case.
128
170
  *
@@ -131,8 +173,10 @@ module.exports = function (suites, context, mocha) {
131
173
  * @returns {*}
132
174
  */
133
175
  only: function (mocha, test) {
134
- test.parent._onlyTests = test.parent._onlyTests.concat(test);
135
- mocha.options.hasOnly = true;
176
+ if (mocha.options.forbidOnly) {
177
+ throw createForbiddenExclusivityError(mocha);
178
+ }
179
+ test.markOnly();
136
180
  return test;
137
181
  },
138
182
 
@@ -143,15 +187,6 @@ module.exports = function (suites, context, mocha) {
143
187
  */
144
188
  skip: function (title) {
145
189
  context.test(title);
146
- },
147
-
148
- /**
149
- * Number of retry attempts
150
- *
151
- * @param {number} n
152
- */
153
- retries: function (n) {
154
- context.retries(n);
155
190
  }
156
191
  }
157
192
  };
@@ -1,9 +1,4 @@
1
1
  'use strict';
2
-
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
2
  var Suite = require('../suite');
8
3
  var Test = require('../test');
9
4
 
@@ -27,9 +22,9 @@ var Test = require('../test');
27
22
  module.exports = function (suite) {
28
23
  var suites = [suite];
29
24
 
30
- suite.on('require', visit);
25
+ suite.on(Suite.constants.EVENT_FILE_REQUIRE, visit);
31
26
 
32
- function visit (obj, file) {
27
+ function visit(obj, file) {
33
28
  var suite;
34
29
  for (var key in obj) {
35
30
  if (typeof obj[key] === 'function') {
@@ -61,3 +56,5 @@ module.exports = function (suite) {
61
56
  }
62
57
  }
63
58
  };
59
+
60
+ module.exports.description = 'Node.js module ("exports") style';
@@ -1,10 +1,8 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
3
  var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE =
5
+ require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
8
6
 
9
7
  /**
10
8
  * QUnit-style interface:
@@ -31,10 +29,10 @@ var Test = require('../test');
31
29
  *
32
30
  * @param {Suite} suite Root suite.
33
31
  */
34
- module.exports = function (suite) {
32
+ module.exports = function qUnitInterface(suite) {
35
33
  var suites = [suite];
36
34
 
37
- suite.on('pre-require', function (context, file, mocha) {
35
+ suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
38
36
  var common = require('./common')(suites, context, mocha);
39
37
 
40
38
  context.before = common.before;
@@ -51,8 +49,8 @@ module.exports = function (suite) {
51
49
  suites.shift();
52
50
  }
53
51
  return common.suite.create({
54
- title: title,
55
- file: file,
52
+ title,
53
+ file,
56
54
  fn: false
57
55
  });
58
56
  };
@@ -66,8 +64,8 @@ module.exports = function (suite) {
66
64
  suites.shift();
67
65
  }
68
66
  return common.suite.only({
69
- title: title,
70
- file: file,
67
+ title,
68
+ file,
71
69
  fn: false
72
70
  });
73
71
  };
@@ -94,6 +92,7 @@ module.exports = function (suite) {
94
92
  };
95
93
 
96
94
  context.test.skip = common.test.skip;
97
- context.test.retries = common.test.retries;
98
95
  });
99
96
  };
97
+
98
+ module.exports.description = 'QUnit style';
@@ -1,10 +1,8 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Module dependencies.
5
- */
6
-
7
3
  var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE =
5
+ require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
8
6
 
9
7
  /**
10
8
  * TDD-style interface:
@@ -34,7 +32,7 @@ var Test = require('../test');
34
32
  module.exports = function (suite) {
35
33
  var suites = [suite];
36
34
 
37
- suite.on('pre-require', function (context, file, mocha) {
35
+ suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
38
36
  var common = require('./common')(suites, context, mocha);
39
37
 
40
38
  context.setup = common.beforeEach;
@@ -49,9 +47,9 @@ module.exports = function (suite) {
49
47
  */
50
48
  context.suite = function (title, fn) {
51
49
  return common.suite.create({
52
- title: title,
53
- file: file,
54
- fn: fn
50
+ title,
51
+ file,
52
+ fn
55
53
  });
56
54
  };
57
55
 
@@ -60,9 +58,9 @@ module.exports = function (suite) {
60
58
  */
61
59
  context.suite.skip = function (title, fn) {
62
60
  return common.suite.skip({
63
- title: title,
64
- file: file,
65
- fn: fn
61
+ title,
62
+ file,
63
+ fn
66
64
  });
67
65
  };
68
66
 
@@ -71,9 +69,9 @@ module.exports = function (suite) {
71
69
  */
72
70
  context.suite.only = function (title, fn) {
73
71
  return common.suite.only({
74
- title: title,
75
- file: file,
76
- fn: fn
72
+ title,
73
+ file,
74
+ fn
77
75
  });
78
76
  };
79
77
 
@@ -101,6 +99,8 @@ module.exports = function (suite) {
101
99
  };
102
100
 
103
101
  context.test.skip = common.test.skip;
104
- context.test.retries = common.test.retries;
105
102
  });
106
103
  };
104
+
105
+ module.exports.description =
106
+ 'traditional "suite"/"test" instead of BDD\'s "describe"/"it"';