-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1577 Add "--exclude" Option #3210
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
95aad4f
Add --exclude as option.
alexbainter 4dbc972
Add tests for --exclude option.
alexbainter 0790b1c
Implement --exclude.
alexbainter 0316b2d
Update --exclude description.
alexbainter 64684b8
Remove old exclude fixture.
alexbainter 9d0aa7f
Add new exclude fixture.
alexbainter 87b8ef3
Fix tests for --exclude option.
alexbainter 5c9547b
Add name to package.contributors.
alexbainter db0d1fd
Filter new files before they're added.
alexbainter 88a98ad
Allow multiple --exclude flags rather than using a comma-delimited list.
alexbainter aa307f8
Use .fixture extension for exclude fixtures.
alexbainter d17863b
Use runMochaJSON (run) instead of of directInvoke.
alexbainter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
const program = require('commander'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const minimatch = require('minimatch'); | ||
const resolve = path.resolve; | ||
const exists = fs.existsSync; | ||
const Mocha = require('../'); | ||
|
@@ -205,7 +206,8 @@ program | |
.option('--allow-uncaught', 'enable uncaught errors to propagate') | ||
.option('--forbid-only', 'causes test marked with only to fail the suite') | ||
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite') | ||
.option('--file <file>', 'include a file to be ran during the suite', collect, []); | ||
.option('--file <file>', 'include a file to be ran during the suite', collect, []) | ||
.option('--exclude <file>', 'a file or glob pattern to ignore', collect, []); | ||
|
||
program._name = 'mocha'; | ||
|
||
|
@@ -494,6 +496,13 @@ args.forEach(arg => { | |
throw err; | ||
} | ||
|
||
if (typeof newFiles !== 'undefined') { | ||
if (typeof newFiles === 'string') { | ||
newFiles = [newFiles]; | ||
} | ||
newFiles = newFiles.filter(fileName => program.exclude.every(pattern => !minimatch(fileName, pattern))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may be able to just chain this ( |
||
} | ||
|
||
files = files.concat(newFiles); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
"Adrian Ludwig (https://github.com/adrian-ludwig)", | ||
"Ainthe Kitchen <[email protected]> (https://github.com/ainthek)", | ||
"ajaykodali (https://github.com/ajaykodali)", | ||
"Alex Bainter <[email protected]> (https://github.com/metalex9)", | ||
"Alex Early (https://github.com/aearly)", | ||
"Alex Pham <[email protected]> (https://github.com/thedark1337)", | ||
"amsul (https://github.com/amsul)", | ||
|
@@ -314,6 +315,7 @@ | |
"glob": "7.1.2", | ||
"growl": "1.10.3", | ||
"he": "1.1.1", | ||
"minimatch": "^3.0.4", | ||
"mkdirp": "0.5.1", | ||
"supports-color": "4.4.0" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
describe('exclude test fail', function () { | ||
it('should not run this test', function () { | ||
throw new Error('should not run'); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/integration/fixtures/options/exclude/nested/fail.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
describe('exclude test nested fail', function () { | ||
it('should not run this test', function () { | ||
throw new Error('should not run'); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
test/integration/fixtures/options/exclude/nested/pass.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
describe('exclude test nested pass', function () { | ||
it('should find this test', function () {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
describe('exclude test pass', function () { | ||
it('should find this test', function () {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
newFiles
will be anything other than anArray
ofstring
s, will it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newFiles
is the result ofutils.lookupFiles
which can return an array of strings, a string, orundefined
.