mocha 10.6.1 → 10.7.3

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.
@@ -7,7 +7,8 @@
7
7
  * @module
8
8
  */
9
9
 
10
- exports.init = require('./init');
11
-
12
- // default command
13
- exports.run = require('./run');
10
+ module.exports = {
11
+ init: require('./init'),
12
+ // default command
13
+ run: require('./run'),
14
+ }
@@ -21,25 +21,24 @@ const {UnmatchedFile} = require('./collect-files');
21
21
 
22
22
  /**
23
23
  * Exits Mocha when tests + code under test has finished execution (default)
24
- * @param {number} code - Exit code; typically # of failures
24
+ * @param {number} clampedCode - Exit code; typically # of failures
25
25
  * @ignore
26
26
  * @private
27
27
  */
28
- const exitMochaLater = code => {
28
+ const exitMochaLater = clampedCode => {
29
29
  process.on('exit', () => {
30
- process.exitCode = Math.min(code, 255);
30
+ process.exitCode = clampedCode;
31
31
  });
32
32
  };
33
33
 
34
34
  /**
35
35
  * Exits Mocha when Mocha itself has finished execution, regardless of
36
36
  * what the tests or code under test is doing.
37
- * @param {number} code - Exit code; typically # of failures
37
+ * @param {number} clampedCode - Exit code; typically # of failures
38
38
  * @ignore
39
39
  * @private
40
40
  */
41
- const exitMocha = code => {
42
- const clampedCode = Math.min(code, 255);
41
+ const exitMocha = clampedCode => {
43
42
  let draining = 0;
44
43
 
45
44
  // Eagerly set the process's exit code in case stream.write doesn't
@@ -139,12 +138,17 @@ const handleUnmatchedFiles = (mocha, unmatchedFiles) => {
139
138
  * @param {Mocha} mocha - Mocha instance
140
139
  * @param {Options} [opts] - Command line options
141
140
  * @param {boolean} [opts.exit] - Whether or not to force-exit after tests are complete
141
+ * @param {boolean} [opts.passOnFailingTestSuite] - Whether or not to fail test run if tests were failed
142
142
  * @param {Object} fileCollectParams - Parameters that control test
143
143
  * file collection. See `lib/cli/collect-files.js`.
144
144
  * @returns {Promise<Runner>}
145
145
  * @private
146
146
  */
147
- const singleRun = async (mocha, {exit}, fileCollectParams) => {
147
+ const singleRun = async (
148
+ mocha,
149
+ {exit, passOnFailingTestSuite},
150
+ fileCollectParams
151
+ ) => {
148
152
  const fileCollectionObj = collectFiles(fileCollectParams);
149
153
 
150
154
  if (fileCollectionObj.unmatchedFiles.length > 0) {
@@ -156,7 +160,9 @@ const singleRun = async (mocha, {exit}, fileCollectParams) => {
156
160
 
157
161
  // handles ESM modules
158
162
  await mocha.loadFilesAsync();
159
- return mocha.run(exit ? exitMocha : exitMochaLater);
163
+ return mocha.run(
164
+ createExitHandler({exit, passOnFailingTestSuite})
165
+ );
160
166
  };
161
167
 
162
168
  /**
@@ -186,7 +192,9 @@ const parallelRun = async (mocha, options, fileCollectParams) => {
186
192
  mocha.files = fileCollectionObj.files;
187
193
 
188
194
  // note that we DO NOT load any files here; this is handled by the worker
189
- return mocha.run(options.exit ? exitMocha : exitMochaLater);
195
+ return mocha.run(
196
+ createExitHandler(options)
197
+ );
190
198
  };
191
199
 
192
200
  /**
@@ -282,3 +290,15 @@ exports.validateLegacyPlugin = (opts, pluginType, map = {}) => {
282
290
  }
283
291
  }
284
292
  };
293
+
294
+ const createExitHandler = ({ exit, passOnFailingTestSuite }) => {
295
+ return code => {
296
+ const clampedCode = passOnFailingTestSuite
297
+ ? 0
298
+ : Math.min(code, 255);
299
+
300
+ return exit
301
+ ? exitMocha(clampedCode)
302
+ : exitMochaLater(clampedCode);
303
+ };
304
+ };
@@ -35,6 +35,7 @@ const TYPES = (exports.types = {
35
35
  'diff',
36
36
  'dry-run',
37
37
  'exit',
38
+ 'pass-on-failing-test-suite',
38
39
  'fail-zero',
39
40
  'forbid-only',
40
41
  'forbid-pending',
package/lib/cli/run.js CHANGED
@@ -24,7 +24,7 @@ const {
24
24
  } = require('./run-helpers');
25
25
  const {ONE_AND_DONES, ONE_AND_DONE_ARGS} = require('./one-and-dones');
26
26
  const debug = require('debug')('mocha:cli:run');
27
- const defaults = require('../mocharc');
27
+ const defaults = require('../mocharc.json');
28
28
  const {types, aliases} = require('./run-option-metadata');
29
29
 
30
30
  /**
@@ -98,6 +98,11 @@ exports.builder = yargs =>
98
98
  requiresArg: true,
99
99
  coerce: list
100
100
  },
101
+ 'pass-on-failing-test-suite': {
102
+ default: false,
103
+ description: 'Not fail test run if tests were failed',
104
+ group: GROUPS.RULES
105
+ },
101
106
  'fail-zero': {
102
107
  description: 'Fail test run if no test(s) encountered',
103
108
  group: GROUPS.RULES
package/lib/mocha.js CHANGED
@@ -157,6 +157,7 @@ exports.run = function (...args) {
157
157
  * @param {boolean} [options.delay] - Delay root suite execution?
158
158
  * @param {boolean} [options.diff] - Show diff on failure?
159
159
  * @param {boolean} [options.dryRun] - Report tests without running them?
160
+ * @param {boolean} [options.passOnFailingTestSuite] - Fail test run if tests were failed?
160
161
  * @param {boolean} [options.failZero] - Fail test run if zero tests?
161
162
  * @param {string} [options.fgrep] - Test filter given string.
162
163
  * @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
@@ -216,6 +217,7 @@ function Mocha(options = {}) {
216
217
  'delay',
217
218
  'diff',
218
219
  'dryRun',
220
+ 'passOnFailingTestSuite',
219
221
  'failZero',
220
222
  'forbidOnly',
221
223
  'forbidPending',
@@ -870,6 +872,20 @@ Mocha.prototype.failZero = function (failZero) {
870
872
  return this;
871
873
  };
872
874
 
875
+ /**
876
+ * Fail test run if tests were failed.
877
+ *
878
+ * @public
879
+ * @see [CLI option](../#-pass-on-failing-test-suite)
880
+ * @param {boolean} [passOnFailingTestSuite=false] - Whether to fail test run.
881
+ * @return {Mocha} this
882
+ * @chainable
883
+ */
884
+ Mocha.prototype.passOnFailingTestSuite = function(passOnFailingTestSuite) {
885
+ this.options.passOnFailingTestSuite = passOnFailingTestSuite === true;
886
+ return this;
887
+ };
888
+
873
889
  /**
874
890
  * Causes tests marked `only` to fail the suite.
875
891
  *
@@ -259,7 +259,7 @@ class SerializableEvent {
259
259
  });
260
260
 
261
261
  // mutates the object
262
- breakCircularDeps(result);
262
+ breakCircularDeps(result.error);
263
263
 
264
264
  const pairs = Object.keys(result).map(key => [result, key]);
265
265
 
package/mocha.js CHANGED
@@ -1,4 +1,4 @@
1
- // mocha@10.6.1 in javascript ES2018
1
+ // mocha@10.7.3 in javascript ES2018
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -19174,7 +19174,7 @@
19174
19174
  };
19175
19175
 
19176
19176
  var name = "mocha";
19177
- var version = "10.6.1";
19177
+ var version = "10.7.3";
19178
19178
  var homepage = "https://mochajs.org/";
19179
19179
  var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
19180
19180
  var require$$17 = {
@@ -19343,6 +19343,7 @@
19343
19343
  * @param {boolean} [options.delay] - Delay root suite execution?
19344
19344
  * @param {boolean} [options.diff] - Show diff on failure?
19345
19345
  * @param {boolean} [options.dryRun] - Report tests without running them?
19346
+ * @param {boolean} [options.passOnFailingTestSuite] - Fail test run if tests were failed?
19346
19347
  * @param {boolean} [options.failZero] - Fail test run if zero tests?
19347
19348
  * @param {string} [options.fgrep] - Test filter given string.
19348
19349
  * @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
@@ -19402,6 +19403,7 @@
19402
19403
  'delay',
19403
19404
  'diff',
19404
19405
  'dryRun',
19406
+ 'passOnFailingTestSuite',
19405
19407
  'failZero',
19406
19408
  'forbidOnly',
19407
19409
  'forbidPending',
@@ -20056,6 +20058,20 @@
20056
20058
  return this;
20057
20059
  };
20058
20060
 
20061
+ /**
20062
+ * Fail test run if tests were failed.
20063
+ *
20064
+ * @public
20065
+ * @see [CLI option](../#-pass-on-failing-test-suite)
20066
+ * @param {boolean} [passOnFailingTestSuite=false] - Whether to fail test run.
20067
+ * @return {Mocha} this
20068
+ * @chainable
20069
+ */
20070
+ Mocha.prototype.passOnFailingTestSuite = function(passOnFailingTestSuite) {
20071
+ this.options.passOnFailingTestSuite = passOnFailingTestSuite === true;
20072
+ return this;
20073
+ };
20074
+
20059
20075
  /**
20060
20076
  * Causes tests marked `only` to fail the suite.
20061
20077
  *