jest: --findRelatedTests don't find test file if path include special characters and file extension
π Bug Report
Hi guys,
Implementing Stryker on my repository was a really difficult task and after searching why jest give me a lot of additional work, iβm openning this issue.
I think the code responsibly to parse and find test paths with the --findRelatedTests
contains (maybe, iβm not sure) a bug.
Every things is explained in this other issue but to summarize, in my context i have an angular project which is running with jest.
Architecture folders are like this :
βββ src (application codebase)
β βββ app
β β βββ @core (local libraries)
β β βββ @shared (shared modules)
β β βββ app
β β βββ ** (main views / containers)
if i run npx jest --findRelatedTests src/app/app.module.ts
everything is ok. Jest found 2 spec files. (except 240 seconds is needed to pass them β¦ for just 2 assertions - codebase = 29K pure ligne of code)
if i run npx jest --findRelatedTests src/app/@core/store/store.ts
jest stdout this :
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\Users\xxxxxx\Projects\xxxxxxxxxxxxxxxxxxxxx
977 files checked.
testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 333 matches
testPathIgnorePatterns: \\node_modules\\ - 977 matches
testRegex: - 0 matches
Pattern: src\\app\\@core\\store\\store.ts - 0 matches
To Reproduce
git clone https://github.com/blephy/jest-path-bug.git
cd jest-path-bug
npm i
npm run test:every
# look at the package.json to see paths
Expected behavior
Jest should understand paths with special characters and with or without file extensions
envinfo
βββ @stryker-mutator/core@5.0.1
βββ @stryker-mutator/jest-runner@5.0.1
βββ @stryker-mutator/typescript-checker@5.0.1
βββ jest@26.6.3
βββ @angular/cli@11.2.11
βββ @angular-builders/jest@11.2.0
βββ jest-preset-angular@8.4.0
βββ ts-jest@26.5.5
βββ typescript@4.1.5
βββ ts-node@8.3.0
Regards !
and many thanks about maintaining jest π
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 19 (8 by maintainers)
Iβve found the issues. It has to do with the way file patterns are handled on windows. Iβve implemented a fix in #11548 (which also fixes #9728). This merely fixes the bug, it doesnβt add support for targeting directories.
@nicojs you rock π₯°
Iβve noticed that this only seems to affect Windows.
On Linux (WSL):
Iβll try to debug to see whatβs going on here.
While weβre at it: #9728 is also a big hurdle for StrykerJS users π
@blephy Thanks for all your hard work on this issue π
StrykerJS uses
--findRelatedTests
to speed up jest test execution during mutation testing considerably (since StrykerJS knows exactly which file is mutated at a particular time, it specifies that file with--findRelatedTests
), but you can turn this behavior off using{ "jest": { "enableFindRelatedTests": false } }
, so that is the current workaround for projects that have issues. See https://stryker-mutator.io/docs/stryker-js/jest-runner#configuration.@blephyβs suggestion would work for us. We mostly need a βbugfreeβ version of
--findRelatedTests
. We only use the βfull file pathβ (incl extension), so that would work.However, from Jestβs point of view, it would be technically impossible to know the difference between path that includes a file extension vs one that doesnβt without performing disk IO. For example, βfoo.barβ might refer to a file with name βfooβ with extension β.barβ, or it could refer to a directory βfoo.barβ which contains files. I would suggest the following:
"testMatch"
rules, see https://jestjs.io/docs/configuration#testmatch-arraystring)I like the suggestion.
cc @SimenB