Skip to content
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

Jest interprets testMatch strings containing <rootDir> incorrectly if rootDir contains parentheses #4838

Closed
rimunroe opened this issue Nov 3, 2017 · 3 comments

Comments

@rimunroe
Copy link
Contributor

rimunroe commented Nov 3, 2017

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.

  1. Clone my example repo: git clone git@github.com:rimunroe/jest-parentheses-in-rootDir.git
  2. Switch to the repo's directory
  3. Switch to the directory containing parens in its name: cd with-\(parens\)/
  4. yarn install
  5. 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.

@rimunroe rimunroe changed the title Jest interprets testMatch containing <rootDir> incorrectly if rootDir contains parentheses Jest interprets testMatch strings containing <rootDir> incorrectly if rootDir contains parentheses Nov 3, 2017
@SimenB
Copy link
Member

SimenB commented Dec 25, 2017

@rimunroe would you be able to send a PR with your fix? We have a bunch of tests and integration tests, so I think any potential regression would be picked up there

@rimunroe
Copy link
Contributor Author

rimunroe commented Jan 8, 2018

Resolved by #5224

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants