Skip to content

Commit

Permalink
rename "exclude" to "ignore" and create alias; closes #3871
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Apr 12, 2019
1 parent f1fe632 commit 2439e4d
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 26 deletions.
12 changes: 6 additions & 6 deletions docs/index.md
Expand Up @@ -817,7 +817,7 @@ Mocha supports the `err.expected` and `err.actual` properties of any thrown `Ass

<!-- AUTO-GENERATED-CONTENT:START (usage:executable=bin/mocha) -->

```plain
```text
mocha [spec..]
Expand Down Expand Up @@ -864,7 +864,7 @@ Configuration
--package Path to package.json for config [string]
File Handling
--exclude Ignore file(s) or glob pattern(s)
--ignore, --exclude Ignore file(s) or glob pattern(s)
[array] [default: (none)]
--extension, --watch-extensions File extension(s) to load and/or watch
[array] [default: js]
Expand All @@ -883,7 +883,7 @@ Test Filters
Positional Arguments
spec One or more files, directories, or globs to test
[array] [default: ["test/"]]
[array] [default: ["test"]]
Other Options
--help, -h Show usage information & exit [boolean]
Expand Down Expand Up @@ -1075,9 +1075,9 @@ Specify an explicit path to a [`package.json` file](#configuring-mocha-node-js)

By default, Mocha looks for a `package.json` in the current working directory or nearest ancestor, and will use the first file found (regardless of whether it contains a `mocha` property); to suppress `package.json` lookup, use `--no-package`.

### `--exclude <file/directory/glob>`
### `--ignore <file|directory|glob>`

Explicitly exclude one or more files, directories or "globs" that would otherwise be loaded.
Explicitly ignore (exclude) one or more test files, directories or globs (e.g., `some/**/files*`) that would otherwise be loaded.

Files specified using `--file` _are not affected_ by this option.

Expand All @@ -1093,7 +1093,7 @@ Affects `--watch` behavior.

Specifying `--extension` will _remove_ `.js` as a test file extension; use `--extension js` to re-add it. For example, to load `.mjs` and `.js` test files, you must supply `--extension mjs --extension js`.

### `--file <file/directory/glob>`
### `--file <file|directory|glob>`

Explicitly _include_ a test file to be loaded before other test files files. Multiple uses of `--file` are allowed, and will be loaded in order given.

Expand Down
4 changes: 2 additions & 2 deletions example/config/.mocharc.yml
Expand Up @@ -6,8 +6,8 @@ check-leaks: false
color: true
delay: false
diff: true
exclude:
- /path/to/some/excluded/file
ignore:
- /path/to/some/ignored/file
exit: false # could be expressed as "no-exit: true"
extension:
- js
Expand Down
6 changes: 3 additions & 3 deletions lib/cli/run-helpers.js
Expand Up @@ -123,14 +123,14 @@ exports.handleRequires = (requires = []) => {
* @param {Object} [opts] - Options
* @param {string[]} [opts.extension] - File extensions to use
* @param {string[]} [opts.spec] - Files, dirs, globs to run
* @param {string[]} [opts.exclude] - Files, dirs, globs to exclude
* @param {string[]} [opts.ignore] - Files, dirs, globs to ignore
* @param {boolean} [opts.recursive=false] - Find files recursively
* @param {boolean} [opts.sort=false] - Sort test files
* @returns {string[]} List of files to test
* @private
*/
exports.handleFiles = ({
exclude = [],
ignore = [],
extension = [],
file = [],
recursive = false,
Expand All @@ -157,7 +157,7 @@ exports.handleFiles = ({
newFiles = [newFiles];
}
newFiles = newFiles.filter(fileName =>
exclude.every(pattern => !minimatch(fileName, pattern))
ignore.every(pattern => !minimatch(fileName, pattern))
);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/cli/run-option-metadata.js
Expand Up @@ -14,7 +14,7 @@
*/
exports.types = {
array: [
'exclude',
'ignore',
'extension',
'file',
'global',
Expand Down Expand Up @@ -63,6 +63,7 @@ exports.aliases = {
global: ['globals'],
grep: ['g'],
growl: ['G'],
ignore: ['exclude'],
invert: ['i'],
'no-colors': ['C'],
reporter: ['R'],
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/run.js
Expand Up @@ -82,7 +82,7 @@ exports.builder = yargs =>
description: 'Show diff on failure',
group: GROUPS.OUTPUT
},
exclude: {
ignore: {
defaultDescription: '(none)',
description: 'Ignore file(s) or glob pattern(s)',
group: GROUPS.FILES,
Expand Down
Expand Up @@ -5,7 +5,7 @@ var helpers = require('../helpers');
var runMochaJSON = helpers.runMochaJSON;
var resolvePath = helpers.resolveFixturePath;

describe('--exclude', function() {
describe('--ignore', function() {
/*
* Runs mocha in {path} with the given args.
* Calls handleResult with the result.
Expand All @@ -26,11 +26,11 @@ describe('--exclude', function() {
});
}

it('should exclude specific files', function(done) {
var fixtures = path.join('options', 'exclude', '*');
it('should ignore specific files', function(done) {
var fixtures = path.join('options', 'ignore', '*');
runMochaTest(
fixtures,
['--exclude', resolvePath(path.join('options', 'exclude', 'fail'))],
['--ignore', resolvePath(path.join('options', 'ignore', 'fail'))],
function(res) {
expect(res, 'to have passed')
.and('to have run test', 'should find this test')
Expand All @@ -40,11 +40,11 @@ describe('--exclude', function() {
);
});

it('should exclude globbed files', function(done) {
var fixtures = path.join('options', 'exclude', '**', '*');
it('should ignore globbed files', function(done) {
var fixtures = path.join('options', 'ignore', '**', '*');
runMochaTest(
fixtures,
['--exclude', '**/fail.fixture.js'],
['--ignore', '**/fail.fixture.js'],
function(res) {
expect(res, 'to have passed')
.and('not to have pending tests')
Expand All @@ -54,15 +54,15 @@ describe('--exclude', function() {
);
});

it('should exclude multiple patterns', function(done) {
var fixtures = path.join('options', 'exclude', '**', '*');
it('should ignore multiple patterns', function(done) {
var fixtures = path.join('options', 'ignore', '**', '*');
runMochaTest(
fixtures,
[
'--exclude',
resolvePath(path.join('options', 'exclude', 'fail')),
'--exclude',
resolvePath(path.join('options', 'exclude', 'nested', 'fail'))
'--ignore',
resolvePath(path.join('options', 'ignore', 'fail')),
'--ignore',
resolvePath(path.join('options', 'ignore', 'nested', 'fail'))
],
function(res) {
expect(res, 'to have passed')
Expand Down

0 comments on commit 2439e4d

Please sign in to comment.