Skip to content
Permalink
Browse files

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

☝️ 

### Possible Drawbacks

None that I can see

### Applicable issues

#3656, #3125. semver-patch
  • Loading branch information...
vkarpov15 authored and boneskull committed Jan 17, 2019
1 parent 635ecd1 commit 414bc1e184358cac886a3649fa2a610b7cb35cd8
Showing with 29 additions and 5 deletions.
  1. +9 −5 lib/cli/run.js
  2. +20 −0 test/integration/options.spec.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 <str>" or "--grep <regexp>"'
throw createMissingArgumentError(
'"--invert" requires one of "--fgrep <str>" or "--grep <regexp>"',
'--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.`
);
@@ -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 <regexp>/
});
done();
},
{stdio: 'pipe'}
);
});
});
});

0 comments on commit 414bc1e

Please sign in to comment.
You can’t perform that action at this time.