Comparing version 10.6.1 to 10.7.0
@@ -24,9 +24,9 @@ 'use strict'; | ||
* Exits Mocha when tests + code under test has finished execution (default) | ||
* @param {number} code - Exit code; typically # of failures | ||
* @param {number} clampedCode - Exit code; typically # of failures | ||
* @ignore | ||
* @private | ||
*/ | ||
const exitMochaLater = code => { | ||
const exitMochaLater = clampedCode => { | ||
process.on('exit', () => { | ||
process.exitCode = Math.min(code, 255); | ||
process.exitCode = clampedCode; | ||
}); | ||
@@ -38,8 +38,7 @@ }; | ||
* what the tests or code under test is doing. | ||
* @param {number} code - Exit code; typically # of failures | ||
* @param {number} clampedCode - Exit code; typically # of failures | ||
* @ignore | ||
* @private | ||
*/ | ||
const exitMocha = code => { | ||
const clampedCode = Math.min(code, 255); | ||
const exitMocha = clampedCode => { | ||
let draining = 0; | ||
@@ -144,2 +143,3 @@ | ||
* @param {boolean} [opts.exit] - Whether or not to force-exit after tests are complete | ||
* @param {boolean} [opts.passOnFailingTestSuite] - Whether or not to fail test run if tests were failed | ||
* @param {Object} fileCollectParams - Parameters that control test | ||
@@ -150,3 +150,7 @@ * file collection. See `lib/cli/collect-files.js`. | ||
*/ | ||
const singleRun = async (mocha, {exit}, fileCollectParams) => { | ||
const singleRun = async ( | ||
mocha, | ||
{exit, passOnFailingTestSuite}, | ||
fileCollectParams | ||
) => { | ||
const fileCollectionObj = collectFiles(fileCollectParams); | ||
@@ -163,3 +167,5 @@ | ||
await mocha.loadFilesAsync(); | ||
return mocha.run(exit ? exitMocha : exitMochaLater); | ||
return mocha.run( | ||
createExitHandler({exit, passOnFailingTestSuite}) | ||
); | ||
}; | ||
@@ -194,3 +200,5 @@ | ||
// note that we DO NOT load any files here; this is handled by the worker | ||
return mocha.run(options.exit ? exitMocha : exitMochaLater); | ||
return mocha.run( | ||
createExitHandler(options) | ||
); | ||
}; | ||
@@ -291,1 +299,13 @@ | ||
}; | ||
const createExitHandler = ({ exit, passOnFailingTestSuite }) => { | ||
return code => { | ||
const clampedCode = passOnFailingTestSuite | ||
? 0 | ||
: Math.min(code, 255); | ||
return exit | ||
? exitMocha(clampedCode) | ||
: exitMochaLater(clampedCode); | ||
}; | ||
}; |
@@ -38,2 +38,3 @@ 'use strict'; | ||
'exit', | ||
'pass-on-failing-test-suite', | ||
'fail-zero', | ||
@@ -40,0 +41,0 @@ 'forbid-only', |
@@ -101,2 +101,7 @@ 'use strict'; | ||
}, | ||
'pass-on-failing-test-suite': { | ||
default: false, | ||
description: 'Not fail test run if tests were failed', | ||
group: GROUPS.RULES | ||
}, | ||
'fail-zero': { | ||
@@ -103,0 +108,0 @@ description: 'Fail test run if no test(s) encountered', |
@@ -160,2 +160,3 @@ 'use strict'; | ||
* @param {boolean} [options.dryRun] - Report tests without running them? | ||
* @param {boolean} [options.passOnFailingTestSuite] - Fail test run if tests were failed? | ||
* @param {boolean} [options.failZero] - Fail test run if zero tests? | ||
@@ -220,2 +221,3 @@ * @param {string} [options.fgrep] - Test filter given string. | ||
'dryRun', | ||
'passOnFailingTestSuite', | ||
'failZero', | ||
@@ -876,2 +878,16 @@ 'forbidOnly', | ||
/** | ||
* Fail test run if tests were failed. | ||
* | ||
* @public | ||
* @see [CLI option](../#-pass-on-failing-test-suite) | ||
* @param {boolean} [passOnFailingTestSuite=false] - Whether to fail test run. | ||
* @return {Mocha} this | ||
* @chainable | ||
*/ | ||
Mocha.prototype.passOnFailingTestSuite = function(passOnFailingTestSuite) { | ||
this.options.passOnFailingTestSuite = passOnFailingTestSuite === true; | ||
return this; | ||
}; | ||
/** | ||
* Causes tests marked `only` to fail the suite. | ||
@@ -878,0 +894,0 @@ * |
{ | ||
"name": "mocha", | ||
"version": "10.6.1", | ||
"version": "10.7.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "description": "simple, flexible, fun test framework", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2119572
30518
1