-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Test glob support #2359
Test glob support #2359
Conversation
Codecov Report@@ Coverage Diff @@
## master #2359 +/- ##
=========================================
+ Coverage 67.9% 68% +0.09%
=========================================
Files 140 140
Lines 5057 5072 +15
=========================================
+ Hits 3434 3449 +15
Misses 1623 1623
Continue to review full report at Codecov.
|
// micromatch doesn't support '..' through the globstar ('**') to avoid | ||
// infinite recursion. | ||
|
||
it('supports ../ paths and unix separators via textRegex', () => { |
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.
testRegex
is not used in this test at all?
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.
Good catch, this used to rely on the default, so I've changed it to explicitly set a regex.
Is it going to be merged? |
The CI job is failing and I don't understand why - anyone have any suggestions? |
There is some issue with eslint on travis, I'll figure it out. @pugnascotia thanks for working on this, it'll take me a bit longer to get to this PR as there are currently 20+ open requests and I'm still catching up with work at FB after my vacation. |
No worries, just pleased to help out. |
Any luck figuring out what was up with CI? Do you want me to merge up to |
Do you mind rebasing this? |
af14c3d
to
f02cc5b
Compare
I've rebased and squashed, and |
Are you sure you rebased against Jest's master branch? It doesn't seem like it. |
f02cc5b
to
e0d73bb
Compare
What...I'm sure I fetched before rebasing. Weird. OK, should be there now. |
@pugnascotia maybe you fetched from your fork's master, happens to me sometimes 😄 |
5891d3e
to
1b88af0
Compare
Generated by 🚫 dangerJS |
I've rebased (again) onto master, and this time I've actually fixed the problems that arose. In particular, in commit b4f65e1 I altered the order in which config keys are validated, so that keys that are still in force but are deprecated will trigger warnings. Re: the |
packages/jest-util/src/messages.js
Outdated
import type {AssertionResult, TestResult} from 'types/TestResult'; | ||
|
||
const chalk = require('chalk'); | ||
const mm = require('micromatch'); |
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.
can we call this variable micromatch everywhere please?
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.
Yep.
@@ -23,6 +23,11 @@ const shouldInstrument = (filename: Path, config: Config): boolean => { | |||
return false; | |||
} | |||
|
|||
if (config.testGlob && config.testGlob.length | |||
&& micromatch.any(filename, config.testGlob)) { |
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.
the code style in Jest is:
if (
config.testGlob &&
config.testGlob.length &&
micromatch.any(filename, config.testGlob)
) {
@@ -116,7 +114,6 @@ class Runtime { | |||
this._mocksPattern = | |||
config.mocksPattern ? new RegExp(config.mocksPattern) : null; | |||
this._shouldAutoMock = config.automock; | |||
this._testRegex = new RegExp(replacePathSepForRegex(config.testRegex)); |
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.
Nice, this seems to have been dead code.
testGlob: [ | ||
'**/__tests__/**/*.js?(x)', | ||
'**/?(*.)(spec|test).js?(x)', | ||
], | ||
testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', |
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.
Why do we need both?
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.
Um...we probably don't :-)
if (config.testRegex && (!config.testGlob || config.testGlob.length === 0)) { | ||
// Prevent default glob conflicting with any explicit `testRegex` value | ||
newConfig.testGlob = []; | ||
} |
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.
Seems like we should warn if both are given?
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.
Wait, I don't really understand this. Why are you setting testGlob to an empty array if testGlob is empty?
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.
Sorry, that's little messy, I'll tidy that up.
.gitignore
Outdated
@@ -2,6 +2,8 @@ | |||
.eslintcache | |||
*.swp | |||
*~ | |||
.idea | |||
*.iml |
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.
do you mind removing these here and instead moving these into a global gitignore config for your computer?
|
||
case 'testRegex': | ||
value = config[key]; | ||
break; |
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.
why did you add this as a separate option in this switch case?
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.
Gah, that's a leftover from an earlier implementation, when the deprecation warnings were generated here. Good catch.
Finally had some time to look at this. Am I understanding this correctly – it'll support both testGlob and testRegex and have the following behaviors:
? |
That was my thinking, yes. Since we can't (AFAIK) turn an arbitrary regex into a glob, I felt it was best to allow |
1cb273a
to
1b0f158
Compare
That's the branch rebased onto |
I feel like we shouldn't show the deprecation warning for testRegex yet. Instead, I'd recommend this:
Are there any better names than "testGlob"? Any way we can drop the "glob" from it? I don't like it, especially as we'll be ending up with a singular option in the future :) |
maybe edit: |
90b0f57
to
9abfc68
Compare
Rebased again and updated as per your comments. I liked
|
The existing validation in jest-validate did not allow for fields that will be replaced but still have an effect, owing to the order in which the validation is carried out. Swap the order so that the deprecation check comes first.
9abfc68
to
0dddf39
Compare
Rebased onto master again - any more feedback on this? |
Thank you for working on this and for being so thorough. Sorry for the delay in reviews. This will be in Jest 19. |
* Validate for deprecated fields first The existing validation in jest-validate did not allow for fields that will be replaced but still have an effect, owing to the order in which the validation is carried out. Swap the order so that the deprecation check comes first. * Implement testGlob option * Fixes from code review * Rename testGlob to testMatch, and remove testMatch deprecation * Forbid testMatch and testRegex being used together * Update SearchSource.js * Update messages.js
* Validate for deprecated fields first The existing validation in jest-validate did not allow for fields that will be replaced but still have an effect, owing to the order in which the validation is carried out. Swap the order so that the deprecation check comes first. * Implement testGlob option * Fixes from code review * Rename testGlob to testMatch, and remove testMatch deprecation * Forbid testMatch and testRegex being used together * Update SearchSource.js * Update messages.js
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Implement a new
testGlob
configuration option. This allows test files to be matched using extended glob patterns instead of regular expressions, as implemented by micromatch.Per #926, globs are a frequently-used tool for matching files, and can be easier to use for filename matching. Other popular tools also use globs instead of regexs.
testRegex
is still supported in this PR, buttestGlob
becomes the favoured option.Existing tests have been modified where necessary to make them pass. New test cases have been added to
SearchSource-test.js
to check that glob matching works in addition to regex matching. A test has also been added tonormalize-test.js
to check that a deprecation warning is printed to the console.