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]: Jest forces path separators to forward slashes in testMatch #15516

Open
miss-programgamer opened this issue Feb 19, 2025 · 5 comments
Open

Comments

@miss-programgamer
Copy link

Version

29.7.0

Steps to reproduce

Using this jest.config.ts file, run jest to try and run all tests in a tests folder.

Image

Expected behavior

It finds my single test file.

Image

Actual behavior

It does not find my single test file.

Image

Additional context

I assume I'm doing something wrong because it seems inconceivable to me that converting backslashes to forward slashes on windows is the intended behavior, yet I can't fathom what it is I've misconfigured.

Environment

System:
    OS: Windows 11 10.0.26100
    CPU: I'm not sharing that.
  Binaries:
    Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@mrazauskas
Copy link
Contributor

mrazauskas commented Feb 20, 2025

testMatch is a list of glob patterns, these are not paths. Therefore only / is interpreted as a separator on all systems. Take a look at documentation: https://jestjs.io/docs/configuration#testmatch-arraystring

@miss-programgamer
Copy link
Author

@mrazauskas The explanation you gave isn't present on the page you linked, which I combed over several times before writing this post anyway. Considering the ignore pattern right below the test match in the console output uses OS-specific separators, it would be nice if there was mention of micromatch being separator agnostic to avoid the confusion I went through.

And besides, there's still the issue that my pattern matches zero test files, so what gives?

@mrazauskas
Copy link
Contributor

You can keep on complaining or try to understand how globs and this particular implementation works. All is provided in documentation link which has link to implementation documentation which has more links. Etc.

@miss-programgamer
Copy link
Author

I did read the docs my guy. I still don't understand why the glob I feed jest doesn't find my test file. I also don't think it's unreasonable to request that common pitfalls of the pattern matching library you use be documented on your end of things. Your motto about jest being "delightful" to use doesn't ring especially true right now.

@miss-programgamer
Copy link
Author

miss-programgamer commented Feb 20, 2025

Anyway, I figured out why it wasn't matching my tests: you need to append __dirname to the front of your match if you want it to only search specific folders. This seems to be because jest only checks matches against absolute paths, and not paths relative to the current directory. Which, I'll add, is not a problem with micromatch or my lack of understanding of how it works.

You can close this issue, I guess.

Edit:

Actually, your docs do mention this whole business with absolute paths, just not in the testMatch section, but in the transformIgnorePatterns section instead, which I found just now on a whim. I would request for testMatch to receive the same attention and have the absolute path explanation added there too for completeness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants