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

testMatch doesn't glob as expected #7108

Closed
worc opened this issue Oct 5, 2018 · 14 comments
Closed

testMatch doesn't glob as expected #7108

worc opened this issue Oct 5, 2018 · 14 comments

Comments

@worc
Copy link

worc commented Oct 5, 2018

i'm setting up jest's testMatch config, but it doesn't glob as expected. my sanity-check command looks into the test folder relative to the project, goes to any depth, and selects any file that ends in .js:

ls ./test/**/*.js | wc -l

running that returns 92. which makes sense, i have 92 files in that directory structure (some tests and some test utils). but when i run jest with the same glob it says there are no tests found:

yarn run v1.9.4
$ jest --config jest.config.json
No tests found
In /Users/<user>/<repo>
  460 files checked.
  testMatch: ./test/**/*.js - 0 matches
  testPathIgnorePatterns: /node_modules/ - 460 matches
Pattern:  - 0 matches
error Command failed with exit code 1.

is this an issue with jest? with micromatch?

@dandv
Copy link
Contributor

dandv commented Oct 10, 2018

Same issue here: --testMatch just doesn't work. Combined with #3793, this makes it impossible to even attempt testing .mjs files (let alone the plethora of issues with .mjs) using CLI arguments.

% node_modules/.bin/jest --testMatch '*.test.mjs'
No tests found
In /home/dandv/jesttest
  2 files checked.
  testMatch: *.test.mjs - 0 matches
  testPathIgnorePatterns: /node_modules/ - 2 matches
Pattern:  - 0 matches

% ls *.test.mjs
index.test.mjs

% node_modules/.bin/jest --version
23.6.0

@43081j
Copy link

43081j commented Oct 10, 2018

Same behaviour here with src/**/*.test.ts. its a pretty simple glob to be honest..

@rickhanlonii
Copy link
Member

Can you try this with **/test/**/*.js or **/src/**/*.test.ts?

My guess is that it's the relative pathing

@43081j
Copy link

43081j commented Oct 10, 2018

This indeed works, but what if you don't want to match potentially deeper src children?

It is still unexpected behaviour that such a simple glob wouldn't work, the workaround isn't really equivalent unfortunately (over-matching).

@rickhanlonii
Copy link
Member

Thanks!

We can look into why those globs don't work - just wanted to verify that it's the relative pathing

@jeffrey-l-turner
Copy link

We're also seeing a similar issue. However, the globbing file expansion is inconsistent between different machines.

@worc
Copy link
Author

worc commented Mar 27, 2019

looking back, this bug would've been in jest 23.6.0. today, trying jest again, and the same bug shows up for v24.5.0. the bug seems largely the same, but jest is now at least showing which files are being picked up by which matchers. though it still is reporting that zero tests are found.

at first it looked like there was progress here, those tests were originally written for mocha, so jest is technically correct, there are no jest tests in those files. i converted them over, and reran the command, but still ended up with files matching, but no tests found.

$ yarn run jest --testMatch ./src/components/search/*.test.js
yarn run v1.15.2
$ /Users/user/repos/repo/node_modules/.bin/jest --testMatch ./src/components/search/jest.test.js ./src/components/search/levenshtein-distance.test.js ./src/components/search/search.test.js
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/user/repos/repo
  1235 files checked.
  testMatch: ./src/components/search/jest.test.js, ./src/components/search/levenshtein-distance.test.js, ./src/components/search/search.test.js - 0 matches
  testPathIgnorePatterns: /node_modules/ - 1235 matches
  testRegex:  - 1235 matches
Pattern:  - 0 matches
error Command failed with exit code 1.

@mbrowne
Copy link

mbrowne commented May 30, 2019

Jest is using an older version of micromatch; perhaps that could be part of the issue here. See also #8510

@lkmill
Copy link

lkmill commented Mar 27, 2020

I too have problems with the testMatch globbing.

Changing the built in:

testMatch: [
  "**/__tests__/**/*.[jt]s?(x)",
  "**/?(*.)+(spec|test).[tj]s?(x)"
],

to

testMatch: [
  "src/**/__tests__/**/*.[jt]s?(x)",
  "src/**/?(*.)+(spec|test).[tj]s?(x)"
],

will cause no files to be matches. To resolve this i have to:

testMatch: [
  path.join(__dirname, 'src/**/__tests__/**/*.[jt]s?(x)'),
  path.join(__dirname, 'src/**/?(*.)+(spec|test).[tj]s?(x)'),
],

@lkmill
Copy link

lkmill commented Mar 27, 2020

I also have to:

    "test:e2e": "jest --testMatch \"$(pwd)/tests/**/*\"",

instead of

    "test:e2e": "jest --testMatch \"tests/**/*\"",

in my package.json scripts

@mbrowne
Copy link

mbrowne commented Aug 20, 2020

If Jest upgrades to the latest version of micromatch, it might fix this issue completely.

@ndrewtl
Copy link

ndrewtl commented Sep 3, 2021

It's been over a year since the last activity on this issue. I am still seeing it in Jest 27.1.0. @rickhanlonii could you please upgrade the version of micromatch?

@rickhanlonii
Copy link
Member

@ndrewtl we are on the latest version of micromatch, and we've moved to picomatch in some cases.

I'm going to close this as it's pretty old and we've changed the dependencies.

If you're still having issues, please create a PR with a test.

@github-actions
Copy link

github-actions bot commented Oct 9, 2021

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 Oct 9, 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

8 participants