From 4e7f923ca3d29ec731669f7236b1a7e6e59a0e6c Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 8 Jan 2019 18:08:36 -0500 Subject: [PATCH 1/2] 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'} + ); + }); }); }); From 49d9d778932e4ad7c00088d2231878a8838a8ab6 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 14 Jan 2019 21:28:32 -0500 Subject: [PATCH 2/2] Fix code review comments --- lib/cli/run.js | 15 +++++++-------- test/integration/options.spec.js | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index 35498f5c39..1d8a26d872 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -9,9 +9,10 @@ const Mocha = require('../mocha'); const ansi = require('ansi-colors'); -const errors = require('../errors'); -const createInvalidArgumentValueError = errors.createInvalidArgumentValueError; -const createMissingArgumentError = errors.createMissingArgumentError; +const { + createInvalidArgumentValueError, + createMissingArgumentError +} = require('../errors'); const { list, @@ -261,17 +262,15 @@ exports.builder = yargs => if (argv.invert && !('fgrep' in argv || 'grep' in argv)) { throw createMissingArgumentError( '"--invert" requires one of "--fgrep " or "--grep "', - '--invert', - argv.invert + '--fgrep|--grep', + 'string|regexp' ); } if (argv.compilers) { throw createInvalidArgumentValueError( `--compilers is DEPRECATED and no longer supported. - See ${ansi.cyan('https://git.io/vdcSr')} for migration information.`, - '--compilers', - argv.compilers + 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 3b39fc6c89..6854528566 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -347,7 +347,7 @@ describe('options', function() { }); }); - it('fails if no --grep', function(done) { + it('should throw an error when `--invert` used in isolation', function(done) { args = ['--invert']; runMocha( 'options/grep.fixture.js', @@ -359,7 +359,7 @@ describe('options', function() { } expect(res, 'to satisfy', { code: 1, - output: /fgrep/ + output: /--invert.*--grep / }); done(); },