Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Fix couple errors missing codes (mochajs#3666)
Browse files Browse the repository at this point in the history
### 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

mochajs#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

mochajs#3656, mochajs#3125. semver-patch
  • Loading branch information
vkarpov15 authored and boneskull committed Jan 17, 2019
1 parent ef40b75 commit 6179b6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.`
);
Expand Down
20 changes: 20 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
);
});
});
});

Expand Down

0 comments on commit 6179b6b

Please sign in to comment.