Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure invalid arguments are not ignored when using bin/mocha; closes #3687 #3692

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {loadConfig, findConfig} = require('./config');
const findup = require('findup-sync');
const {deprecate} = require('../utils');
const debug = require('debug')('mocha:cli:options');
const {createMissingArgumentError} = require('../errors');

/**
* The `yargs-parser` namespace
Expand Down Expand Up @@ -73,8 +74,8 @@ const nargOpts = types.array
* @private
* @ignore
*/
const parse = (args = [], ...configObjects) =>
yargsParser(
const parse = (args = [], ...configObjects) => {
const result = yargsParser.detailed(
args,
Object.assign(
{
Expand All @@ -87,6 +88,11 @@ const parse = (args = [], ...configObjects) =>
types
)
);
if (result.error) {
throw createMissingArgumentError(result.error.message);
}
return result.argv;
};

/**
* - Replaces comments with empty strings
Expand Down
20 changes: 20 additions & 0 deletions test/integration/invalid-arguments.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var invokeMocha = require('./helpers').invokeMocha;

describe('invalid arguments', function() {
it('should exit with failure if arguments are invalid', function(done) {
invokeMocha(
['--ui'],
function(err, result) {
if (err) {
return done(err);
}
expect(result, 'to have failed');
expect(result.output, 'to match', /not enough arguments/i);
done();
},
{stdio: 'pipe'}
);
});
});