Skip to content

Commit

Permalink
add new option 'fail-zero'
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Aug 12, 2021
1 parent 09ffc30 commit 110ffcc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/cli/run-option-metadata.js
Expand Up @@ -35,6 +35,7 @@ const TYPES = (exports.types = {
'diff',
'dry-run',
'exit',
'fail-zero',
'forbid-only',
'forbid-pending',
'full-trace',
Expand Down
4 changes: 4 additions & 0 deletions lib/cli/run.js
Expand Up @@ -98,6 +98,10 @@ exports.builder = yargs =>
requiresArg: true,
coerce: list
},
'fail-zero': {
description: 'Fail if no test(s) encountered',
group: GROUPS.RULES
},
fgrep: {
conflicts: 'grep',
description: 'Only run tests containing this string',
Expand Down
1 change: 1 addition & 0 deletions lib/mocha.js
Expand Up @@ -1025,6 +1025,7 @@ Mocha.prototype.run = function(fn) {
const runner = new this._runnerClass(suite, {
delay: options.delay,
dryRun: options.dryRun,
failZero: options.failZero,
cleanReferencesAfterRun: this._cleanReferencesAfterRun
});
createStatsCollector(runner);
Expand Down
2 changes: 2 additions & 0 deletions lib/runner.js
Expand Up @@ -1044,6 +1044,8 @@ Runner.prototype.run = function(fn, opts = {}) {
fn = fn || function() {};

const end = () => {
if (!this.total && options.failZero) this.failures = 1;

debug('run(): root suite completed; emitting %s', constants.EVENT_RUN_END);
this.emit(constants.EVENT_RUN_END);
};
Expand Down

0 comments on commit 110ffcc

Please sign in to comment.