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

find tests when path includes folder starting with a period #7267

Closed
JohnAlbin opened this issue Oct 25, 2018 · 14 comments
Closed

find tests when path includes folder starting with a period #7267

JohnAlbin opened this issue Oct 25, 2018 · 14 comments
Labels

Comments

@JohnAlbin
Copy link

🐛 Bug Report

This is a regression of the bug reported in #3111 that was fixed in #3006 and broke again sometime in the v23 branch.

When a test is inside a folder that has a name starting with period, ., they are ignored by testMatch and by testRegex. It's even more obscure if the entire project is checked out below a dot-folder, in which case all tests are ignored.

To Reproduce

Given the following directory listing:

~/projects/jestbug/.app/__tests__/atest.js
~/projects/jestbug/.app/atest.test.js
~/projects/jestbug/app/atest.test.js
~/projects/jestbug/app/.subfolder/__tests__/atest.js
~/projects/jestbug/app/.subfolder/atest.test.js
~/projects/jestbug/app/__tests__/atest.js
~/projects/jestbug/atest.test.js

Using the following package.json:

{
  "name": "jestbug",
  "devDependencies": {
    "jest": "^23.6.0"
  }
}

None of the tests in a folder staring with . are found:

$ rm -rf node_modules
$ npm install
$ npx jest --listTests --no-cache
~/projects/jestbug/atest.test.js
~/projects/jestbug/app/atest.test.js
~/projects/jestbug/app/__tests__/atest.js

Using the following package.json:

{
  "name": "jestbug",
  "devDependencies": {
    "jest": "^23.6.0"
  },
  "jest": {
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$"
  }
}

None of the tests in a folder staring with . are found:

$ rm -rf node_modules
$ npm install
$ npx jest --listTests --no-cache
~/projects/jestbug/atest.test.js
~/projects/jestbug/app/atest.test.js
~/projects/jestbug/app/__tests__/atest.js

Expected behavior

Using the following package.json:

{
  "name": "jestbug",
  "devDependencies": {
    "jest": "^22.4.4"
  }
}
$ rm -rf node_modules
$ npm install
$ npx jest --listTests --no-cache
~/projects/jestbug/app/atest.test.js
~/projects/jestbug/.app/atest.test.js
~/projects/jestbug/app/.subfolder/atest.test.js
~/projects/jestbug/atest.test.js
~/projects/jestbug/app/.subfolder/__tests__/atest.js
~/projects/jestbug/app/__tests__/atest.js
~/projects/jestbug/.app/__tests__/atest.js

Using the following package.json:

{
  "name": "jestbug",
  "devDependencies": {
    "jest": "^22.4.4"
  },
  "jest": {
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$"
  }
}
$ rm -rf node_modules
$ npm install
$ npx jest --listTests --no-cache
~/projects/jestbug/app/atest.test.js
~/projects/jestbug/.app/atest.test.js
~/projects/jestbug/app/.subfolder/atest.test.js
~/projects/jestbug/atest.test.js
~/projects/jestbug/app/.subfolder/__tests__/atest.js
~/projects/jestbug/app/__tests__/atest.js
~/projects/jestbug/.app/__tests__/atest.js

Link to repl or repo (highly encouraged)

Note that repl.it currently uses Jest v22 and I can't figure out how to make it run under v23.

But here's the demo link where the bug is NOT present because v22 is not broken. https://repl.it/@John_AlbinAlbin/CarpalSoulfulDirectories

Run npx envinfo --preset jest

  System:
    OS: macOS 10.14
    CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  Binaries:
    Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
    Yarn: 1.10.1 - ~/.yarn/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0 
@SimenB
Copy link
Member

SimenB commented Oct 25, 2018

Could you set up a quick repository we can pull down and see the error in? I copied out your repl to my local machine and can reproduce

The test I said was failing for me in #3111 was actually fixed by me restarting watchman locally...

@thymikee
Copy link
Collaborator

You can restart watchman by doing watchman watch-del $PWD or watchman watch-del-all (will remove all other projects crawl cache, if they use watchamn).

@SimenB
Copy link
Member

SimenB commented Oct 25, 2018

I can confirm that killing watchman seems to fix this.

Is it a bug in watchman?

@JohnAlbin
Copy link
Author

I've created https://github.com/JohnAlbin/jest-bug-7267 with the example repo.

I tried watchman watch-del-all and it had no effect on the failure of npx jest --no-cache --listTests to find all 7 tests; it only finds 3 tests.

@SimenB
Copy link
Member

SimenB commented Oct 25, 2018

With your repo:

image

@SimenB
Copy link
Member

SimenB commented Oct 25, 2018

What happens if you do jest --listTests --no-watchman?

@JohnAlbin
Copy link
Author

JohnAlbin commented Oct 25, 2018

npx jest --listTests --no-cache only finds 3 tests (as stated before)

But npx jest --listTests --no-watchman --no-cache finds all 7 tests!

FYI, Jest's cache was giving me inconsistent results; if I installed Jest v22, ran the tests, and then re-installed v23, the tests would all be found until I used the --no-cache option.

@ewolfe
Copy link

ewolfe commented Oct 25, 2018

I'm not sure if this is related, but I'm experiencing an issue when running jest via yarn.

Given:

"scripts": {
  "jest": "jest .storybook"
}

Then yarn jest fails, while npm run jest runs just fine.

No tests found
In /Users/ewolfe/Projects/<myProject>
  2020 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)+(spec|test).js?(x) - 245 matches
  testPathIgnorePatterns: /node_modules/ - 2020 matches
Pattern: .storybook - 0 matches

Update: this is probably just user error on my end, a co-worker is running my code and not having any issues.

@JohnAlbin
Copy link
Author

JohnAlbin commented Oct 26, 2018

this is probably just user error on my end

This bug made me question my sanity at first too.

a co-worker is running my code and not having any issues.

FYI, because of the Jest cache issues, that's exactly what was happening to my team. My co-worker saw the bug and I didn't. Then finally I did see the bug, but after a day it disappeared. Then reappeared. However, we always used Yarn (not npm). AND, the tests that were being skipped were ones that we put in our .storybook folder.

@joanasmramos
Copy link

Hello, me and two other students are trying to fix this issue for a course in college. However, it's our first time working with jest (and any open source project really) so we are not so sure how to work this. We've done an UML components diagram for the whole system but still don't understand the flow of the program and are having a hard time finding the files directly and indirectly involved in this issue. Another problem we are having is in replicating and possibly testing our solution. If you could please give us some guidelines we would be very grateful!

@rickhanlonii
Copy link
Member

@joanasmramos thats so cool! I'd love to see the UML diagram at some point :D

This video may be helpful for you for understanding how the jest architecture works

That being said, this may not be a good first issue to work on because it sounds like the issue may not be in Jest but in a tool we use called Watchman. You can search our issues with the Good First Issue label to find issues good for people intro'ing to the code base 👌

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 2, 2022

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 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants