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

[Bug]: modulePathIgnorePatterns should not cause "no tests found" #15214

Closed
chriswilty opened this issue Jul 26, 2024 · 4 comments
Closed

[Bug]: modulePathIgnorePatterns should not cause "no tests found" #15214

chriswilty opened this issue Jul 26, 2024 · 4 comments

Comments

@chriswilty
Copy link

chriswilty commented Jul 26, 2024

Version

29.7

Steps to reproduce

https://github.com/chriswilty/jest-bug-module-ignores

Repo contains a single test, and a simple Jest config with modulePathIgnorePatterns matching the test file.

npm ci
npm test

Expected behavior

Test is found and is run.

Actual behavior

Test is not even found (0 matches):

> jest

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\dev\mine\jest-bug-module-ignores
  3 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 0 matches
  testPathIgnorePatterns: \\node_modules\\ - 3 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches

Additional context

The docs for modulePathIgnorePatterns state:

An array of regexp pattern strings that are matched against all module paths  
before those paths are to be considered 'visible' to the module loader. If a  
given module's path matches any of the patterns, it will not be require()-able  
in the test environment.

From the above statements, I would expect that all tests are found, and any test without imports/requires would run whereas those with imports/requires of modules matching an ignore pattern would error with a "module not found" message.

Compare to using testPathIgnorePatterns, where we see my test is found but subsequently filtered out:

> jest

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\dev\mine\jest-bug-module-ignores
  4 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 1 match
  testPathIgnorePatterns: C:\\dev\\mine\\jest-bug-module-ignores\\notthese\\ - 3 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches

I would guess this is not a bug at all, just ambiguity in the docs. Can we tighten those up a little, to indicate this behaviour is intentional, that test files are considered modules for the Jest runner? It would also be nice to clarify the difference in behaviour between testPathIgnorePatterns and modulePathIgnorePatterns.

However, in both cases I am confused as to why Jest is reporting THREE matches to the ignore pattern, not one.

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 20.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 3.3.0 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.8.1 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Copy link

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

@github-actions github-actions bot added the Stale label Aug 25, 2024
Copy link

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

1 similar comment
Copy link

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

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
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 Oct 25, 2024
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

1 participant