question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

find tests when path includes folder starting with a period

See original GitHub issue

šŸ› 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 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
JohnAlbincommented, 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.

1reaction
thymikeecommented, Oct 25, 2018

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Given full path, check if path is subdirectory of some other ...
dir1. contains(dir2); but that also returns true, if directories have similar names, for example - c:\abc and c:\abc1 are not sub-directories, bet returns...
Read more >
What does the period (.) mean at the start of a filename in ...
For example in a path ( ./file ) it describes the current directory you are in, while ../file refers to file in the...
Read more >
File path formats on Windows systems
A relative path to a file in a directory starting from the current directory. C:\Projects\apilibrary\apilibrary.sln, An absolute path to a fileĀ ...
Read more >
40 Best Examples of Find command in Linux
The Linux find command is a powerful tool that enables system administrators to locate and manage files and directories based on a wide...
Read more >
Simplify the directory path (Unix like)
Note that absolute path always begin with '/' ( root directory ), a dot in path represent current directory and double dot represents...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found