Answer: it had nothing to do with the regex but with the position of the jest.config.js file, changing rootDirin the config fixed the issue
I have a working regex in regex101.com but I can make it work in Jest
__tests__\/.*test.[jt]sx?$
result given (regex101):
__tests__/__config/jest.config.js -> no
__tests__/app.test.js -> yes
__tests__/app.test.ts -> yes
__tests__/app.test.tsx -> yes
__tests__/api/app.test.js -> yes
__tests__/api/app.test.not -> no
__tests__/api/api2/api3/app.test.js -> yes
toto.test.js -> no
which is exactly what I want, but when I update the jest.config.js
Jest config:
module.exports = {
testRegex: ["__tests__/.*test.[jt]sx?$"],
};
it doesn't find anything.
What I'm looking to do: I want to store everything related to unit testing inside the __tests__ folder, including the jest.config.js and other stuff that does not has to be run by Jest.
In package.json run the config inside the __tests__ folder
...
"test": "jest --config ./__tests__/__config/jest.config.js"
...
So it gives me something like:
__tests__/
__config/
jest.config.js -> do not run
dabatase.js -> do not run
user/
user.test.js -> run this
user.mock.js -> do not run
So basically only the things that end in .test.js/ts that are inside the __tests__ folder
Here is a small repo with the current (non functional) config: Github Repo
Thanks