-
-
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
Escape glob characters in rootDir before interpolating into testMatch #5224
Escape glob characters in rootDir before interpolating into testMatch #5224
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5224 +/- ##
==========================================
+ Coverage 60.91% 60.93% +0.02%
==========================================
Files 202 202
Lines 6731 6733 +2
Branches 4 3 -1
==========================================
+ Hits 4100 4103 +3
+ Misses 2630 2629 -1
Partials 1 1
Continue to review full report at Codecov.
|
Interesting. I think we didn't intend glob patterns to use |
The documentation makes it seem like it's at least somewhat expected. For example, there's an explicit example of using
Also, the version of that section currently up on the Jest website has another bit showing using
I guess I'm kind of fuzzy on what rootDir should be for in the first place. My question is: if |
Yeah, you are right about this being confusing. Originally the idea was that any regex pattern in the config would support rootDir (legacy Jest basically) but that globs don't need it. Right now we are in this confusing state where we support both globs and regex for different config options. I think it's best to merge your PR to make this less confusing for users even if technically we don't really need rootDir to be included in glob patterns, it still works. |
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. |
Summary
This is an attempt to address #4838 and facebook/create-react-app#3404. Currently, some tests aren't found when the user is running Jest in a project where the path contains parentheses and they have the
<rootDir>
token in one of thetestMatch
strings. This seems to be becausetestMatch
is treated as an array of Globs, but rootDir is dropped into those Globs unaltered.For an example, given this configuration:
Jest will end up with
/(parens)/**/*.test.js
as atestMatch
pattern. This will match the file at/parens/src/index.test.js
, rather than file/(parens)/src/index.test.js
, since micromatch will treat the parens as a designating a regex group containing a single pattern.It looks like this is also a problem in every other place in the configuration where
<rootDir>
would be used in a glob pattern. I tried addressing the issue in those places too, but this ended up causing some new test failures, so I'm just pushing up my attempt at fixing the immediate problem. It would be nice if there were a way to address the other cases here too. Is there a use-case for having a rootDir glob pattern instead of just a single path?Test plan
I added an additional failing test before beginning, though I had trouble finding a place for it that seemed suitable and ended up just putting it near some tests that seemed to be checking for similar things inside jest-cli.
This is how I checked to see if the changes addressed #4838:
yarn link
inside packages/jest-cli../with-(parens)
.yarn
to install the un-linked Jest.yarn test
and note that no tests were found.yarn link jest-cli
to use the new build of Jest instead.yarn test
again, which should result in a test being found.