Confusing "No tests found" message when using testPathIgnorePatterns
See original GitHub issue🐛 Bug Report
As noted in issue #1047, Jest ignores all tests if testPathIgnorePatterns matches the path to the repo. This seems like a bug but the Jest devs seem to treat this behavior as intentional, so I am just here to complain that there seems to be a bug in the way Jest reports what it is doing to users. In particular, it tells users that testPathIgnorePatterns
has 0 matches
.
To Reproduce
-
Make a project whose test file will be “accidentally” ignored:
mkdir ignored cd ignored npm init -f echo test(‘’,function(){}) > my.test.js
-
In package.json, add an ignore pattern matching a parent folder:
"jest": { "testPathIgnorePatterns": ["ignore.*"] }
-
Run
jest
and observe unhelpful error message:No tests found In C:\Dev\ignored 2 files checked. testMatch: **/__tests__/**/*.js?(x),**/?(*.)+(spec|test).js?(x) - 1 match testPathIgnorePatterns: ignore.* - 0 matches Pattern: - 0 matches
jest --version
: 23.4.0
Expected behavior
The message should be clear that testPathIgnorePatterns
is causing files to be ignored. Also I suggest mentioning either that testPathIgnorePatterns can match the parent folder and/or that <rootDir>
can avoid that problem. Also, why does Jest print Pattern: - 0 matches
? That’s not meaningful.
Suggested output:
No tests found
In C:\Dev\ignored
2 files checked.
testMatch: **/__tests__/**/*.js?(x),**/?(*.)+(spec|test).js?(x) - 1 match
testPathIgnorePatterns: ignore.* - 1 ignored
Caution: testPathIgnorePatterns does not begin with <rootDir> so
it is potentially matched against the name of a parent directory.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:6
also would be nice to know how to use this option from CLI, because there any kind of value basically just makes everything to be ignored all the time…
@qwertie, @ashnur, @Kamilius
I’ve managed to get
testPathIgnorePatterns
on the CLI.The docs are not clear on how to use
testPathIgnorePatterns
in the CLI however the following will work:For example, if I used a
.unit.spec.js
and.integration.spec.js
suffix on my tests to differentiate between integration and unit tests I could run the following:And if you want to add this to your
package.json
then it would look like:Or you could use:
In short,
jest --testPathIgnorePatterns=\".pattern\"
works for the Jest CLI.Note that I am using Jest 23.6.0 that does not document
testPathIgnorePatterns
but it is present.