mocha 10.6.0 → 10.7.0
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/README.md +0 -1
- package/lib/cli/run-helpers.js +29 -9
- package/lib/cli/run-option-metadata.js +1 -0
- package/lib/cli/run.js +5 -0
- package/lib/mocha.js +16 -0
- package/lib/runnable.js +4 -6
- package/lib/utils.js +9 -2
- package/mocha.js +31 -10
- package/mocha.js.map +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://github.com/mochajs/mocha/actions?query=workflow%3ATests+branch%3Amain"><img src="https://github.com/mochajs/mocha/workflows/Tests/badge.svg?branch=main" alt="GitHub Actions Build Status"></a>
|
|
9
9
|
<a href="https://coveralls.io/github/mochajs/mocha"><img src="https://coveralls.io/repos/github/mochajs/mocha/badge.svg" alt="Coverage Status"></a>
|
|
10
|
-
<a href="https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_shield"><img src="https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha.svg?type=shield" alt="FOSSA Status"></a>
|
|
11
10
|
<a href="https://discord.gg/KeDn2uXhER"><img alt="Chat - Discord" src="https://img.shields.io/badge/chat-Discord-5765F2.svg" /></a>
|
|
12
11
|
<a href="https://github.com/mochajs/mocha#sponsors"><img src="https://opencollective.com/mochajs/tiers/sponsors/badge.svg" alt="OpenCollective Sponsors"></a>
|
|
13
12
|
<a href="https://github.com/mochajs/mocha#backers"><img src="https://opencollective.com/mochajs/tiers/backers/badge.svg" alt="OpenCollective Backers"></a>
|
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
|
@@ -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/runnable.js
CHANGED
|
@@ -20,6 +20,8 @@ var setTimeout = global.setTimeout;
|
|
|
20
20
|
var clearTimeout = global.clearTimeout;
|
|
21
21
|
var toString = Object.prototype.toString;
|
|
22
22
|
|
|
23
|
+
var MAX_TIMEOUT = Math.pow(2, 31) - 1;
|
|
24
|
+
|
|
23
25
|
module.exports = Runnable;
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -95,8 +97,7 @@ Runnable.prototype.timeout = function (ms) {
|
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
// Clamp to range
|
|
98
|
-
var
|
|
99
|
-
var range = [0, INT_MAX];
|
|
100
|
+
var range = [0, MAX_TIMEOUT];
|
|
100
101
|
ms = utils.clamp(ms, range);
|
|
101
102
|
|
|
102
103
|
// see #1652 for reasoning
|
|
@@ -233,11 +234,8 @@ Runnable.prototype.clearTimeout = function () {
|
|
|
233
234
|
*/
|
|
234
235
|
Runnable.prototype.resetTimeout = function () {
|
|
235
236
|
var self = this;
|
|
236
|
-
var ms = this.timeout();
|
|
237
|
+
var ms = this.timeout() || MAX_TIMEOUT;
|
|
237
238
|
|
|
238
|
-
if (ms === 0) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
239
|
this.clearTimeout();
|
|
242
240
|
this.timer = setTimeout(function () {
|
|
243
241
|
if (self.timeout() === 0) {
|
package/lib/utils.js
CHANGED
|
@@ -138,7 +138,7 @@ function emptyRepresentation(value, typeHint) {
|
|
|
138
138
|
* canonicalType(global) // 'global'
|
|
139
139
|
* canonicalType(new String('foo') // 'object'
|
|
140
140
|
* canonicalType(async function() {}) // 'asyncfunction'
|
|
141
|
-
* canonicalType(
|
|
141
|
+
* canonicalType(Object.create(null)) // 'null-prototype'
|
|
142
142
|
*/
|
|
143
143
|
var canonicalType = (exports.canonicalType = function canonicalType(value) {
|
|
144
144
|
if (value === undefined) {
|
|
@@ -147,7 +147,10 @@ var canonicalType = (exports.canonicalType = function canonicalType(value) {
|
|
|
147
147
|
return 'null';
|
|
148
148
|
} else if (Buffer.isBuffer(value)) {
|
|
149
149
|
return 'buffer';
|
|
150
|
+
} else if (Object.getPrototypeOf(value) === null) {
|
|
151
|
+
return 'null-prototype';
|
|
150
152
|
}
|
|
153
|
+
|
|
151
154
|
return Object.prototype.toString
|
|
152
155
|
.call(value)
|
|
153
156
|
.replace(/^\[.+\s(.+?)]$/, '$1')
|
|
@@ -213,7 +216,7 @@ exports.type = function type(value) {
|
|
|
213
216
|
exports.stringify = function (value) {
|
|
214
217
|
var typeHint = canonicalType(value);
|
|
215
218
|
|
|
216
|
-
if (!~['object', 'array', 'function'].indexOf(typeHint)) {
|
|
219
|
+
if (!~['object', 'array', 'function', 'null-prototype'].indexOf(typeHint)) {
|
|
217
220
|
if (typeHint === 'buffer') {
|
|
218
221
|
var json = Buffer.prototype.toJSON.call(value);
|
|
219
222
|
// Based on the toJSON result
|
|
@@ -399,8 +402,12 @@ exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
|
|
399
402
|
break;
|
|
400
403
|
}
|
|
401
404
|
/* falls through */
|
|
405
|
+
case 'null-prototype':
|
|
402
406
|
case 'object':
|
|
403
407
|
canonicalizedObj = canonicalizedObj || {};
|
|
408
|
+
if (typeHint === 'null-prototype' && Symbol.toStringTag in value) {
|
|
409
|
+
canonicalizedObj['[Symbol.toStringTag]'] = value[Symbol.toStringTag];
|
|
410
|
+
}
|
|
404
411
|
withStack(value, function () {
|
|
405
412
|
Object.keys(value)
|
|
406
413
|
.sort()
|
package/mocha.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// mocha@10.
|
|
1
|
+
// mocha@10.7.0 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) :
|
|
@@ -11101,7 +11101,7 @@
|
|
|
11101
11101
|
* canonicalType(global) // 'global'
|
|
11102
11102
|
* canonicalType(new String('foo') // 'object'
|
|
11103
11103
|
* canonicalType(async function() {}) // 'asyncfunction'
|
|
11104
|
-
* canonicalType(
|
|
11104
|
+
* canonicalType(Object.create(null)) // 'null-prototype'
|
|
11105
11105
|
*/
|
|
11106
11106
|
var canonicalType = (exports.canonicalType = function canonicalType(value) {
|
|
11107
11107
|
if (value === undefined) {
|
|
@@ -11110,7 +11110,10 @@
|
|
|
11110
11110
|
return 'null';
|
|
11111
11111
|
} else if (isBuffer(value)) {
|
|
11112
11112
|
return 'buffer';
|
|
11113
|
+
} else if (Object.getPrototypeOf(value) === null) {
|
|
11114
|
+
return 'null-prototype';
|
|
11113
11115
|
}
|
|
11116
|
+
|
|
11114
11117
|
return Object.prototype.toString
|
|
11115
11118
|
.call(value)
|
|
11116
11119
|
.replace(/^\[.+\s(.+?)]$/, '$1')
|
|
@@ -11176,7 +11179,7 @@
|
|
|
11176
11179
|
exports.stringify = function (value) {
|
|
11177
11180
|
var typeHint = canonicalType(value);
|
|
11178
11181
|
|
|
11179
|
-
if (!~['object', 'array', 'function'].indexOf(typeHint)) {
|
|
11182
|
+
if (!~['object', 'array', 'function', 'null-prototype'].indexOf(typeHint)) {
|
|
11180
11183
|
if (typeHint === 'buffer') {
|
|
11181
11184
|
var json = Buffer.prototype.toJSON.call(value);
|
|
11182
11185
|
// Based on the toJSON result
|
|
@@ -11362,8 +11365,12 @@
|
|
|
11362
11365
|
break;
|
|
11363
11366
|
}
|
|
11364
11367
|
/* falls through */
|
|
11368
|
+
case 'null-prototype':
|
|
11365
11369
|
case 'object':
|
|
11366
11370
|
canonicalizedObj = canonicalizedObj || {};
|
|
11371
|
+
if (typeHint === 'null-prototype' && Symbol.toStringTag in value) {
|
|
11372
|
+
canonicalizedObj['[Symbol.toStringTag]'] = value[Symbol.toStringTag];
|
|
11373
|
+
}
|
|
11367
11374
|
withStack(value, function () {
|
|
11368
11375
|
Object.keys(value)
|
|
11369
11376
|
.sort()
|
|
@@ -12960,6 +12967,8 @@
|
|
|
12960
12967
|
var clearTimeout$1 = commonjsGlobal.clearTimeout;
|
|
12961
12968
|
var toString = Object.prototype.toString;
|
|
12962
12969
|
|
|
12970
|
+
var MAX_TIMEOUT = Math.pow(2, 31) - 1;
|
|
12971
|
+
|
|
12963
12972
|
var runnable = Runnable$3;
|
|
12964
12973
|
|
|
12965
12974
|
/**
|
|
@@ -13035,8 +13044,7 @@
|
|
|
13035
13044
|
}
|
|
13036
13045
|
|
|
13037
13046
|
// Clamp to range
|
|
13038
|
-
var
|
|
13039
|
-
var range = [0, INT_MAX];
|
|
13047
|
+
var range = [0, MAX_TIMEOUT];
|
|
13040
13048
|
ms = utils$2.clamp(ms, range);
|
|
13041
13049
|
|
|
13042
13050
|
// see #1652 for reasoning
|
|
@@ -13173,11 +13181,8 @@
|
|
|
13173
13181
|
*/
|
|
13174
13182
|
Runnable$3.prototype.resetTimeout = function () {
|
|
13175
13183
|
var self = this;
|
|
13176
|
-
var ms = this.timeout();
|
|
13184
|
+
var ms = this.timeout() || MAX_TIMEOUT;
|
|
13177
13185
|
|
|
13178
|
-
if (ms === 0) {
|
|
13179
|
-
return;
|
|
13180
|
-
}
|
|
13181
13186
|
this.clearTimeout();
|
|
13182
13187
|
this.timer = setTimeout$2(function () {
|
|
13183
13188
|
if (self.timeout() === 0) {
|
|
@@ -19169,7 +19174,7 @@
|
|
|
19169
19174
|
};
|
|
19170
19175
|
|
|
19171
19176
|
var name = "mocha";
|
|
19172
|
-
var version = "10.
|
|
19177
|
+
var version = "10.7.0";
|
|
19173
19178
|
var homepage = "https://mochajs.org/";
|
|
19174
19179
|
var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
|
|
19175
19180
|
var require$$17 = {
|
|
@@ -19338,6 +19343,7 @@
|
|
|
19338
19343
|
* @param {boolean} [options.delay] - Delay root suite execution?
|
|
19339
19344
|
* @param {boolean} [options.diff] - Show diff on failure?
|
|
19340
19345
|
* @param {boolean} [options.dryRun] - Report tests without running them?
|
|
19346
|
+
* @param {boolean} [options.passOnFailingTestSuite] - Fail test run if tests were failed?
|
|
19341
19347
|
* @param {boolean} [options.failZero] - Fail test run if zero tests?
|
|
19342
19348
|
* @param {string} [options.fgrep] - Test filter given string.
|
|
19343
19349
|
* @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
|
|
@@ -19397,6 +19403,7 @@
|
|
|
19397
19403
|
'delay',
|
|
19398
19404
|
'diff',
|
|
19399
19405
|
'dryRun',
|
|
19406
|
+
'passOnFailingTestSuite',
|
|
19400
19407
|
'failZero',
|
|
19401
19408
|
'forbidOnly',
|
|
19402
19409
|
'forbidPending',
|
|
@@ -20051,6 +20058,20 @@
|
|
|
20051
20058
|
return this;
|
|
20052
20059
|
};
|
|
20053
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
|
+
|
|
20054
20075
|
/**
|
|
20055
20076
|
* Causes tests marked `only` to fail the suite.
|
|
20056
20077
|
*
|