diff --git a/lib/cli/run.js b/lib/cli/run.js index e6c14f67ad..1d8a26d872 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -9,8 +9,10 @@ const Mocha = require('../mocha'); const ansi = require('ansi-colors'); -const errors = require('../errors'); -const createInvalidArgumentValueError = errors.createInvalidArgumentValueError; +const { + createInvalidArgumentValueError, + createMissingArgumentError +} = require('../errors'); const { list, @@ -258,13 +260,15 @@ exports.builder = yargs => // yargs.implies() isn't flexible enough to handle this if (argv.invert && !('fgrep' in argv || 'grep' in argv)) { - throw new Error( - '"--invert" requires one of "--fgrep " or "--grep "' + throw createMissingArgumentError( + '"--invert" requires one of "--fgrep " or "--grep "', + '--fgrep|--grep', + 'string|regexp' ); } if (argv.compilers) { - throw new Error( + throw createInvalidArgumentValueError( `--compilers is DEPRECATED and no longer supported. See ${ansi.cyan('https://git.io/vdcSr')} for migration information.` ); diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 81eac5786a..6854528566 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -346,6 +346,26 @@ describe('options', function() { done(); }); }); + + it('should throw an error when `--invert` used in isolation', function(done) { + args = ['--invert']; + runMocha( + 'options/grep.fixture.js', + args, + function(err, res) { + if (err) { + done(err); + return; + } + expect(res, 'to satisfy', { + code: 1, + output: /--invert.*--grep / + }); + done(); + }, + {stdio: 'pipe'} + ); + }); }); });