From 4e7f923ca3d29ec731669f7236b1a7e6e59a0e6c Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 8 Jan 2019 18:08:36 -0500 Subject: [PATCH] Fix couple errors missing codes --- lib/cli/run.js | 13 +++++++++---- test/integration/options.spec.js | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index e6c14f67ad..35498f5c39 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -11,6 +11,7 @@ const Mocha = require('../mocha'); const ansi = require('ansi-colors'); const errors = require('../errors'); const createInvalidArgumentValueError = errors.createInvalidArgumentValueError; +const createMissingArgumentError = errors.createMissingArgumentError; const { list, @@ -258,15 +259,19 @@ 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 "', + '--invert', + argv.invert ); } 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.` + See ${ansi.cyan('https://git.io/vdcSr')} for migration information.`, + '--compilers', + argv.compilers ); } diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 81eac5786a..3b39fc6c89 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -346,6 +346,26 @@ describe('options', function() { done(); }); }); + + it('fails if no --grep', 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: /fgrep/ + }); + done(); + }, + {stdio: 'pipe'} + ); + }); }); });