From 414bc1e184358cac886a3649fa2a610b7cb35cd8 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 17 Jan 2019 16:43:52 -0500 Subject: [PATCH] Fix couple errors missing codes (#3666) ### Requirements * Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion. * All new code requires tests to ensure against regressions. ### Description of the Change #3656 added a couple utils for setting `code` on errors. I fixed a couple here and wanted to make sure I was on the right track before making more changes. ### Alternate Designs N/A ### Why should this be in core? Codes help identify errors as mocha errors at a glance without using custom error types, and better DX is always good. ### Benefits :point_up: ### Possible Drawbacks None that I can see ### Applicable issues #3656, #3125. semver-patch --- lib/cli/run.js | 14 +++++++++----- test/integration/options.spec.js | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) 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'} + ); + }); }); });