I want to execute 2 different test environments,
one for integration tests and the second is for unit tests.
The folders structure is something like this:
__tests__/ut/p/a/t/h/file.test.ts
__tests__/it/p/a/t/h/file.test.ts
I have come up with these regex:
(__tests__/ut/.*\.test)\.(tsx?|ts?)$
(__tests__/it/.*\.test)\.(tsx?|ts?)$
My scripts looks like this:
"test:ut": "jest \"(__tests__/ut/.*\\.test)\\.(tsx?|ts?)$\"",
"test:it": "jest \"(__tests__/it/.*\\.test)\\.(tsx?|ts?)$\"",
But when I run yarn test:ut I get:
yarn run v1.3.2
$ jest "(__tests__/ut/.*\.test)\.(tsx?|ts?)$"
No tests found
In /home/dev/sample
20 files checked.
testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 0 matches
testPathIgnorePatterns: /node_modules/ - 20 matches
Pattern: (__tests__/ut/.*\.test)\.(tsx?|ts?)$ - 0 matches
Done in 0.49s.
Though, if I use the same pattern in a json configuration file it works.
I guess it something with how I execute the jest.
How can I fix it?
EDIT
Executing this:
"test:ut": "jest -c jest.json \"(__tests__\\/ut\\/.*\\.test)\\.(tsx?|ts?)$\"",
result with the no tests found.
But if I put the regex inside the configuration file, it does work:
{
"testRegex": "(__tests__\\/ut\\/.*\\.test)\\.(tsx?|ts?)$",
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json",
"jsx"
]
}
Executing it as npm script I just comment out the testRegex from the config file.