-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
Do you want to request a feature or report a bug?
I think this is a bug
What is the current behavior?
If a project is created under a path /I/contain/(parentheses)
, and Jest is configured like so:
{
"jest": {
"testMatch": [
"<rootDir>/**/*.test.js"
]
}
}
it will fail to find a test located at /I/contain/(parentheses)/index.test.js
. If the parentheses are removed from the enclosing path, the test will be found correctly.
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
- Clone my example repo:
git clone [email protected]:rimunroe/jest-parentheses-in-rootDir.git
- Switch to the repo's directory
- Switch to the directory containing parens in its name:
cd with-\(parens\)/
yarn install
yarn test
What is the expected behavior?
A the test at with-(parens)/index.test.js
should be found and run. If instead you switch to the without-parens
directory (and install) and run tests, the test will be found correctly.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
macOS 10.12.6
node 6.10.3
npm 3.10.10
jest 20.0.4 & 21.2.1
Some more info
A teammate ran into this first with a new app using create-react-app (1.4.3). They found that our Jenkins workers were unable to find any tests. It's similar enough in effect to a problem I ran into last year (#1315) that it feels like a regression.
I'm not familiar with the current layout of Jest, but I tried investigating a bit. It seems to me like the issue is caused by rootDir
being interpolated into the glob strings contained by testMatch
. Since these are passed to micromatch as globs, unescaped parens (and I suppose any other globbing characters) will cause unexpected behavior. I looked around for a place to fix this issue, but couldn't tell what exactly the right thing to do would be. It looks like possibly escaping rootDir
's glob characters at https://github.com/facebook/jest/blob/165efcd55b7dce6da348e9f4a661185e02b66c71/packages/jest-config/src/normalize.js#L447 fixes the problem, but I don't know if that's the right place. It seems like the _replaceRootDirTags
function is maybe a better candidate, but I don't know what the implications of that would be for the rest of the code.
Ideally, the type system would be able to catch this kind of problem by distinguishing between Glob and Path types (while still remembering that they're both subtypes of strings), but I don't know if that distinction is possible with Flow.