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.
- package/lib/cli/commands.js +5 -4
- package/lib/cli/run-helpers.js +29 -9
- package/lib/cli/run-option-metadata.js +1 -0
- package/lib/cli/run.js +6 -1
- package/lib/mocha.js +16 -0
- package/lib/nodejs/serializer.js +1 -1
- package/mocha.js +18 -2
- package/mocha.js.map +1 -1
- package/package.json +51 -15
package/lib/cli/commands.js
CHANGED
package/lib/cli/run-helpers.js
CHANGED
|
@@ -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}
|
|
24
|
+
* @param {number} clampedCode - Exit code; typically # of failures
|
|
25
25
|
* @ignore
|
|
26
26
|
* @private
|
|
27
27
|
*/
|
|
28
|
-
const exitMochaLater =
|
|
28
|
+
const exitMochaLater = clampedCode => {
|
|
29
29
|
process.on('exit', () => {
|
|
30
|
-
process.exitCode =
|
|
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}
|
|
37
|
+
* @param {number} clampedCode - Exit code; typically # of failures
|
|
38
38
|
* @ignore
|
|
39
39
|
* @private
|
|
40
40
|
*/
|
|
41
|
-
const exitMocha =
|
|
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 (
|
|
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(
|
|
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(
|
|
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
|
+
};
|
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
|
*
|
package/lib/nodejs/serializer.js
CHANGED
package/mocha.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// mocha@10.
|
|
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.
|
|
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
|
*
|